$NetBSD: patch-ag,v 1.1 2011/04/04 08:46:42 manu Exp $

Add the MellonIdPMetadataGlob directive (pulled from upstream)

Index: auth_mellon_util.c
===================================================================
--- auth_mellon_util.c	(revision 116)
+++ auth_mellon_util.c	(working copy)
@@ -838,6 +838,31 @@
     return ret;
 }
 
+/* This returns the directroy part of a path, a la dirname(3)
+ *
+ * Parameters:
+ *  apr_pool_t p         Pool to allocate memory from
+ *  const char *path     Path to extract directory from
+ *
+ * Returns:
+ *  The directory part of path
+ */
+const char *am_filepath_dirname(apr_pool_t *p, const char *path) 
+{
+    char *cp;
+
+    /*
+     * Try Unix and then Windows style. Borrowed from
+     * apr_match_glob(), it seems it cannot be made more
+     * portable.
+     */
+    if (((cp = strrchr(path, (int)'/')) == NULL) &&
+        ((cp = strrchr(path, (int)'\\')) == NULL))
+            return ".";
+   
+    return apr_pstrndup(p, path, cp - path);
+}
+
 /*
  * malloc a buffer and fill it with a given file
  *
Index: auth_mellon.h
===================================================================
--- auth_mellon.h	(revision 116)
+++ auth_mellon.h	(working copy)
@@ -52,6 +52,7 @@
 #include "apr_file_io.h"
 #include "apr_xml.h"
 #include "apr_lib.h"
+#include "apr_fnmatch.h"
 
 #include "ap_config.h"
 #include "httpd.h"
@@ -296,6 +297,7 @@
 int am_postdir_cleanup(request_rec *s);
 char *am_htmlencode(request_rec *r, const char *str);
 int am_save_post(request_rec *r, const char **relay_state);
+const char *am_filepath_dirname(apr_pool_t *p, const char *path);
 const char *am_strip_cr(request_rec *r, const char *str);
 const char *am_add_cr(request_rec *r, const char *str);
 const char *am_xstrtok(request_rec *r, const char *str, 
Index: README
===================================================================
--- README	(revision 116)
+++ README	(working copy)
@@ -349,6 +349,11 @@
         # Default: None set.
 	MellonIdPMetadataFile /etc/apache2/mellon/idp-metadata.xml
 
+        # MellonIdPMetadataGlob is a glob(3) pattern enabled  alternative 
+        # to MellonIdPMetadataFile.
+        # Default: None set.
+	#MellonIdPMetadataGlob /etc/apache2/mellon/*-metadata.xml
+
         # MellonIdpPublicKeyFile is the full path of the public key of the
         # IdP. This parameter is optional if the public key is embedded
         # in the IdP's metadata file, or if a certificate authority is
Index: auth_mellon_config.c
===================================================================
--- auth_mellon_config.c	(revision 116)
+++ auth_mellon_config.c	(working copy)
@@ -222,6 +222,54 @@
     return NULL;
 }
 
+/* This function handles configuration directives which use
+ * a glob pattern
+ *
+ * Parameters:
+ *  cmd_parms *cmd       The command structure for this configuration
+ *                       directive.
+ *  void *struct_ptr     Pointer to the current directory configuration.
+ *                       NULL if we are not in a directory configuration.
+ *  const char *arg      The string argument following this configuration
+ *                       directive in the configuraion file.
+ *
+ * Returns:
+ *  NULL on success or an error string on failure.
+ */
+static const char *am_set_glob_fn(cmd_parms *cmd,
+                                  void *struct_ptr,
+                                  const char *arg)
+{
+    const char *(*take_argv)(cmd_parms *, void *, const char *);
+    apr_array_header_t *files;
+    const char *error;
+    const char *directory;
+    int i;
+
+    take_argv = cmd->info;
+    directory = am_filepath_dirname(cmd->pool, arg);
+
+    if (arg == NULL || *arg == '\0')
+        return apr_psprintf(cmd->pool, "%s takes one argument", cmd->cmd->name);
+
+    if (apr_match_glob(arg, &files, cmd->pool) != 0)
+        return take_argv(cmd, struct_ptr, arg);
+    
+    for (i = 0; i < files->nelts; i++) {
+        const char *path;
+
+        path = apr_pstrcat(cmd->pool, directory, "/", 
+                           ((const char **)(files->elts))[i], NULL); 
+                           
+        error = take_argv(cmd, struct_ptr, path);
+
+        if (error != NULL)
+            return error;
+    }
+   
+    return NULL;
+}
+
 /* This function handles configuration directives which set an 
  * idp related slot in the module configuration. 
  *
@@ -872,6 +920,13 @@
         "Full path to xml metadata file for the IdP."
         ),
     AP_INIT_TAKE1(
+        "MellonIdPMetadataGlob",
+        am_set_glob_fn,
+        am_set_idp_string_slot,
+        OR_AUTHCFG,
+        "Full path to xml metadata files for the IdP, with glob(3) patterns."
+        ),
+    AP_INIT_TAKE1(
         "MellonIdPPublicKeyFile",
         ap_set_string_slot,
         (void *)APR_OFFSETOF(am_dir_cfg_rec, idp_public_key_file),
