Skip to content

Commit

Permalink
Fix handling of CURLOPT_CAINFO and CURLOPT_CAPATH
Browse files Browse the repository at this point in the history
re: Issue Unidata/netcdf4-python#1246

This provides a **partial** solution to the above PR.
The underlying problem is with libcurl, but at least a
workaround should be possible by creating a "~/.ncrc" file
containing the line "HTTP.SSL_CAINFO=\<path to the cert (.crt) file\>".
This was not working for obscure reasons. This PR should fix it.

## Misc. Other Changes

* Update/fix configure.ac to properly test for libcurl version >= 7.66.0
* Update include/netcdf_json.h
* Remove use of strlcat from plugins.
* Fix applicability of .rc file entries
  • Loading branch information
DennisHeimbigner committed Apr 29, 2023
1 parent 2bed69a commit fc796b3
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 33 deletions.
8 changes: 4 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,19 @@ AC_MSG_RESULT([${havecurloption}])
if test $havecurloption = yes; then
AC_DEFINE([HAVE_CURLOPT_KEEPALIVE],[1],[Is CURLOPT_TCP_KEEPALIVE defined])
fi

# CURLOPT_VERIFYHOST semantics differ depending on version
AC_MSG_CHECKING([whether libcurl is version 7.66 or later?])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[#include "curl/curl.h"],
[[
#if LIBCURL_VERSION_NUM < 0x074200
#if !CURL_AT_LEAST_VERSION(7,66,0)
error "<7.66";
#endif
]])], [libcurl766=yes], [libcurl766=no])

AC_MSG_RESULT([$libcurl766])
if test x$libcurl66 = xno; then
AC_DEFINE([HAVE_LIBCURL_766],[1],[Is libcurl version 7.66 or later])
if test x$libcurl766 = xyes; then
AC_DEFINE([HAVE_LIBCURL_766],[1],[libcurl version is 7.66 or later])
fi

CFLAGS="$SAVECFLAGS"
Expand Down
15 changes: 7 additions & 8 deletions include/netcdf_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,13 @@ testdouble(const char* word)
double d;
int count = 0;
/* Check for Nan and Infinity */
if(strcasecmp("nan",word)==0) return NCJTHROW(NCJ_OK);
if(strcasecmp("infinity",word)==0) return NCJTHROW(NCJ_OK);
if(strcasecmp("-infinity",word)==0) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("nan",word)) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("infinity",word)) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("-infinity",word)) return NCJTHROW(NCJ_OK);
/* Allow the XXXf versions as well */
if(strcasecmp("nanf",word)==0) return NCJTHROW(NCJ_OK);
if(strcasecmp("infinityf",word)==0) return NCJTHROW(NCJ_OK);
if(strcasecmp("-infinityf",word)==0) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("nanf",word)) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("infinityf",word)) return NCJTHROW(NCJ_OK);
if(0==(int)strcasecmp("-infinityf",word)) return NCJTHROW(NCJ_OK);
/* Try to convert to number */
ncvt = sscanf(word,"%lg%n",&d,&count);
return NCJTHROW((ncvt == 1 && strlen(word)==count ? NCJ_OK : NCJ_ERR));
Expand Down Expand Up @@ -1226,8 +1226,7 @@ NCJtotext(const NCjson* json)
char* text = NULL;
if(json == NULL) {strcpy(outtext,"<null>"); goto done;}
(void)NCJunparse(json,0,&text);
outtext[0] = '\0';
strlcat(outtext,text,sizeof(outtext));
strncpy(outtext,text,sizeof(outtext));
nullfree(text);
done:
return outtext;
Expand Down
13 changes: 7 additions & 6 deletions libdispatch/drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,11 +567,12 @@ rcequal(NCRCentry* e1, NCRCentry* e2)
nulltest = 0;
if(e1->host == NULL) nulltest |= 1;
if(e2->host == NULL) nulltest |= 2;
/* Use host to decide if entry applies */
switch (nulltest) {
case 0: if(strcmp(e1->host,e2->host) != 0) {return 0;} break;
case 1: return 0;
case 2: return 0;
case 3: break;
case 1: break; /* .rc->host == NULL && candidate->host != NULL */
case 2: return 0; /* .rc->host != NULL && candidate->host == NULL */
case 3: break; /* .rc->host == NULL && candidate->host == NULL */
default: return 0;
}
/* test urlpath take NULL into account*/
Expand All @@ -580,9 +581,9 @@ rcequal(NCRCentry* e1, NCRCentry* e2)
if(e2->urlpath == NULL) nulltest |= 2;
switch (nulltest) {
case 0: if(strcmp(e1->urlpath,e2->urlpath) != 0) {return 0;} break;
case 1: return 0;
case 2: return 0;
case 3: break;
case 1: break; /* .rc->urlpath == NULL && candidate->urlpath != NULL */
case 2: return 0; /* .rc->urlpath != NULL && candidate->urlpath == NULL */
case 3: break; /* .rc->urlpath == NULL && candidate->urlpath == NULL */
default: return 0;
}
return 1;
Expand Down
3 changes: 1 addition & 2 deletions libdispatch/ncjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,7 @@ NCJtotext(const NCjson* json)
char* text = NULL;
if(json == NULL) {strcpy(outtext,"<null>"); goto done;}
(void)NCJunparse(json,0,&text);
outtext[0] = '\0';
strlcat(outtext,text,sizeof(outtext));
strncpy(outtext,text,sizeof(outtext));
nullfree(text);
done:
return outtext;
Expand Down
1 change: 1 addition & 0 deletions oc2/occurlfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ ocset_curlflag(OCstate* state, int flag)
case CURLOPT_USE_SSL:
case CURLOPT_SSLCERT: case CURLOPT_SSLKEY:
case CURLOPT_SSL_VERIFYPEER: case CURLOPT_SSL_VERIFYHOST:
case CURLOPT_CAINFO: case CURLOPT_CAPATH:
{
struct ssl* ssl = &state->auth->ssl;
/* VERIFYPEER == 0 => VERIFYHOST == 0 */
Expand Down
13 changes: 9 additions & 4 deletions plugins/H5Znoop.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,21 @@ NCZ_noop_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
int i,stat = NC_NOERR;
char json[8192];
char value[1024];
size_t jlen, count;

if(nparams != 0 && params == NULL)
{stat = NC_EINVAL; goto done;}

snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_noop_codec.codecid);

jlen = sizeof(json);
count = snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_noop_codec.codecid);
for(i=0;i<nparams;i++) {
snprintf(value,sizeof(value),", \"p%d\": \"%u\"",i,params[i]);
strlcat(json,value,sizeof(json));
size_t len = snprintf(value,sizeof(value),", \"p%d\": \"%u\"",i,params[i]);
count += len; assert(jlen > count);
strcat(json,value);
}
strlcat(json,"}",sizeof(json));
count += 1; assert(jlen > count);
strcat(json,"}");
if(codecp) {
if((*codecp = strdup(json))==NULL) {stat = NC_ENOMEM; goto done;}
}
Expand Down
9 changes: 4 additions & 5 deletions plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ AM_LDFLAGS += $(plugin_version_info)
endif !ISCYGWIN
endif !ISMINGW

# Create an alternate directory if not installing or for noinst installs.
# Create an alternate directory if not installing.
ALTPLUGINDIR = ${abs_top_builddir}/plugins/plugindir

RPATH = -rpath $(abs_builddir)/.libs
Expand Down Expand Up @@ -80,11 +80,11 @@ endif # ENABLE_NCZARR_FILTERS

if ENABLE_PLUGINS

# The NCZarr codec libraries
# The NCZarr codec libraries (they need libnetcdf)
lib__nczstdfilters_la_SOURCES = NCZstdfilters.c
lib__nczstdfilters_la_LIBADD = $(LIBADD)
lib__nczstdfilters_la_LIBADD = $(LIBADD) $(top_builddir)/liblib/libnetcdf.la
lib__nczhdf5filters_la_SOURCES = NCZhdf5filters.c
lib__nczhdf5filters_la_LIBADD = $(LIBADD)
lib__nczhdf5filters_la_LIBADD = $(LIBADD) $(top_builddir)/liblib/libnetcdf.la

plugins_to_install += lib__nczhdf5filters.la
plugins_to_install += lib__nczstdfilters.la
Expand Down Expand Up @@ -119,7 +119,6 @@ lib__nch5unknown_la_SOURCES = H5Zunknown.c
lib__nch5unknown_la_LDFLAGS = $(AM_LDFLAGS) ${RPATH}

check_LTLIBRARIES += lib__nch5noop.la lib__nch5noop1.la lib__nch5unknown.la
# findplugin.sh needs these plugins, and I want to see if these get built properly
check_LTLIBRARIES += lib__nch5misc.la lib__nczmisc.la

# Bzip2 is used to test more complex filters
Expand Down
12 changes: 8 additions & 4 deletions plugins/NCZmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ NCZ_misc_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
int i,stat = NC_NOERR;
char json[4096];
char value[1024];
size_t count, jlen;

if(nparams == 0 || params == NULL)
{stat = NC_EINVAL; goto done;}
Expand All @@ -164,12 +165,15 @@ NCZ_misc_hdf5_to_codec(size_t nparams, const unsigned* params, char** codecp)
stat = NC_EINVAL;
goto done;
}
snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_misc_codec.codecid);
jlen = sizeof(json);
count = snprintf(json,sizeof(json),"{\"id\": \"%s\"",NCZ_misc_codec.codecid);
for(i=0;i<14;i++) {
snprintf(value,sizeof(value),", \"%s\": \"%u\"",fields[i],params[i]);
strlcat(json,value,sizeof(json));
size_t len = snprintf(value,sizeof(value),", \"%s\": \"%u\"",fields[i],params[i]);
count += len; assert(jlen > count);
strcat(json,value);
}
strlcat(json,"}",sizeof(json));
count += 1; assert(jlen > count);
strcat(json,"}");
if(codecp) {
if((*codecp = strdup(json))==NULL) {stat = NC_ENOMEM; goto done;}
}
Expand Down

0 comments on commit fc796b3

Please sign in to comment.