#include <xmltooling/util/XMLHelper.h>
#ifndef WIN32
-# ifdef HAVE_SYS_TYPES_H && HAVE_DIRENT_H
-# include <sys/types.h>
+# if defined(HAVE_SYS_TYPES_H) && defined(HAVE_DIRENT_H)
# include <dirent.h>
+# include <sys/types.h>
+# include <sys/stat.h>
# else
-# #error Unsupported directory library headers.
+# error Unsupported directory library headers.
# endif
#endif
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);
if (e->hasAttributeNS(nullptr, precedence))
root->setAttributeNS(nullptr, precedence, e->getAttributeNS(nullptr, precedence));
- Category& log = Category::getInstance(SAML_LOGCAT".Metadata.Folder");
+ Category& log = Category::getInstance(SAML_LOGCAT ".Metadata.Folder");
log.info("loading metadata files from folder (%s)", loc.c_str());
#ifdef WIN32
}
do {
if (f.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
- log.warn("nested folders not supported, skipping (%s)", f.cFileName);
+ if (strcmp(f.cFileName, ".") && strcmp(f.cFileName, ".."))
+ log.warn("nested folders not supported, skipping (%s)", f.cFileName);
continue;
}
fullname = loc + '/' + f.cFileName;
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
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) {