X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Fsaml2%2Fmetadata%2Fimpl%2FFolderMetadataProvider.cpp;h=a6b61e3e382374a89442a66a6cfb4b18004f588f;hb=90887d43405f3e4a1ebaa796a53b211ce5c64402;hp=1203d31df18d4087f9e02c1d40ef921d182e7816;hpb=8287218a8ebb9b3c858aeb2cbe6c9a13b9b58a63;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/saml2/metadata/impl/FolderMetadataProvider.cpp b/saml/saml2/metadata/impl/FolderMetadataProvider.cpp index 1203d31..a6b61e3 100644 --- a/saml/saml2/metadata/impl/FolderMetadataProvider.cpp +++ b/saml/saml2/metadata/impl/FolderMetadataProvider.cpp @@ -37,11 +37,12 @@ #include #ifndef WIN32 -# ifdef HAVE_SYS_TYPES_H && HAVE_DIRENT_H -# include +# if defined(HAVE_SYS_TYPES_H) && defined(HAVE_DIRENT_H) # include +# include +# include # else -# #error Unsupported directory library headers. +# error Unsupported directory library headers. # endif #endif @@ -58,6 +59,7 @@ namespace opensaml { static const XMLCh Chaining[] = UNICODE_LITERAL_8(C,h,a,i,n,i,n,g); static const XMLCh _MetadataProvider[] = UNICODE_LITERAL_16(M,e,t,a,d,a,t,a,P,r,o,v,i,d,e,r); static const XMLCh discoveryFeed[] = UNICODE_LITERAL_13(d,i,s,c,o,v,e,r,y,F,e,e,d); + static const XMLCh dropDOM[] = UNICODE_LITERAL_7(d,r,o,p,D,O,M); static const XMLCh legacyOrgNames[] = UNICODE_LITERAL_14(l,e,g,a,c,y,O,r,g,N,a,m,e,s); static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); static const XMLCh precedence[] = UNICODE_LITERAL_10(p,r,e,c,e,d,e,n,c,e); @@ -112,14 +114,22 @@ namespace opensaml { if (!d) { throw MetadataException("Folder MetadataProvider unable to open directory ($1)", params(1, loc.c_str())); } - struct dirent* ent; - while(readdir_r(d, ent, &ent) == 0 && ent) { - if (ent->d_type & DT_DIR) { - if (strcmp(ent->d_name, ".") && strcmp(ent->d_name, "..")) - log.warn("nested folders not supported, skipping (%s)", ent->d_name); + char dir_buf[sizeof(struct dirent) + PATH_MAX]; + struct dirent* ent = (struct dirent*)dir_buf; + struct dirent* entptr = nullptr; + while(readdir_r(d, ent, &entptr) == 0 && entptr) { + if (!strcmp(entptr->d_name, ".") || !strcmp(entptr->d_name, "..")) + continue; + fullname = loc + '/' + entptr->d_name; + struct stat stat_buf; + if (stat(fullname.c_str(), &stat_buf) != 0) { + log.warn("unable to access (%s)", entptr->d_name); + continue; + } + else if (S_ISDIR(stat_buf.st_mode)) { + log.warn("nested folders not supported, skipping (%s)", entptr->d_name); continue; } - fullname = loc + '/' + ent->d_name; log.info("will create metadata source from (%s)", fullname.c_str()); auto_ptr_XMLCh entry(fullname.c_str()); #endif @@ -134,6 +144,8 @@ namespace opensaml { child->setAttributeNS(nullptr, discoveryFeed, e->getAttributeNS(nullptr, discoveryFeed)); if (e->hasAttributeNS(nullptr, legacyOrgNames)) child->setAttributeNS(nullptr, legacyOrgNames, e->getAttributeNS(nullptr, legacyOrgNames)); + if (e->hasAttributeNS(nullptr, dropDOM)) + child->setAttributeNS(nullptr, dropDOM, e->getAttributeNS(nullptr, dropDOM)); DOMElement* filter = XMLHelper::getFirstChildElement(e); while (filter) {