diff options
author | olavmrk <olavmrk@a716ebb1-153a-0410-b759-cfb97c6a1b53> | 2008-11-10 18:33:55 +0000 |
---|---|---|
committer | olavmrk <olavmrk@a716ebb1-153a-0410-b759-cfb97c6a1b53> | 2008-11-10 18:33:55 +0000 |
commit | e8069a282501ffda569d1f84c669d285400b12b1 (patch) | |
tree | 053f9cf64f31e890e2f0be1f14b88f92c4253def /auth_mellon_util.c | |
parent | 18a8e091a690e942cdc9dc12fb22502052b00998 (diff) | |
download | mod_auth_mellon-e8069a282501ffda569d1f84c669d285400b12b1.tar.gz mod_auth_mellon-e8069a282501ffda569d1f84c669d285400b12b1.tar.xz mod_auth_mellon-e8069a282501ffda569d1f84c669d285400b12b1.zip |
Use lasso_server_new_from_buffer if available.
Recent versions of Lasso supports loading the SP metadata,
certificate and private key from memory. This patch changes mod_mellon
to use this function if it is available. This makes it possible to store
the SP private key readable only from root.
Thanks to Emmanuel Dreyfus for this patch.
git-svn-id: https://modmellon.googlecode.com/svn/trunk@35 a716ebb1-153a-0410-b759-cfb97c6a1b53
Diffstat (limited to 'auth_mellon_util.c')
-rw-r--r-- | auth_mellon_util.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/auth_mellon_util.c b/auth_mellon_util.c index 4f371cc..6b19fd9 100644 --- a/auth_mellon_util.c +++ b/auth_mellon_util.c @@ -516,3 +516,56 @@ char *am_generate_session_id(request_rec *r) return ret; } + +/* + * malloc a buffer and fill it with a given file + * + * Parameters: + * apr_pool_t *conf The configuration pool. Valid as long as this + * server_rec *s The server record for the current server. + * const char *file The file path + * + * Returns: + * char * The file content + */ +char *am_getfile(apr_pool_t *conf, server_rec *s, const char *file) +{ + apr_status_t rv; + char buffer[512]; + apr_finfo_t finfo; + char *data; + apr_file_t *fd; + apr_size_t nbytes; + + if (file == NULL) + return NULL; + + if ((rv = apr_file_open(&fd, file, APR_READ, 0, conf)) != 0) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, + "apr_file_open: Error opening \"%s\" [%d] \"%s\"", + file, rv, apr_strerror(rv, buffer, sizeof(buffer))); + return NULL; + } + + if ((rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, fd)) != 0) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, + "apr_file_info_get: Error opening \"%s\" [%d] \"%s\"", + file, rv, apr_strerror(rv, buffer, sizeof(buffer))); + (void)apr_file_close(fd); + return NULL; + } + + nbytes = finfo.size; + data = (char *)apr_palloc(conf, nbytes + 1); + + if ((rv = apr_file_read(fd, (void *)data, &nbytes)) != 0) { + ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, + "apr_file_read: Error reading \"%s\" [%d] \"%s\"", + file, rv, apr_strerror(rv, buffer, sizeof(buffer))); + } + data[finfo.size] = '\0'; + + (void)apr_file_close(fd); + + return data; +} |