diff options
| author | Günther Deschner <gdeschner@redhat.com> | 2012-06-18 13:44:28 +0200 |
|---|---|---|
| committer | Simo Sorce <simo@redhat.com> | 2012-06-25 16:49:20 -0400 |
| commit | 9b8e141b8e5286e4323df16557763e2a0be71c9e (patch) | |
| tree | fa88769fd13122987d8cc06e9642fca715cd9c85 /proxy/src | |
| parent | 06748b94c376ca680e6a7c80708618dc136f1fe1 (diff) | |
| download | gss-proxy-9b8e141b8e5286e4323df16557763e2a0be71c9e.tar.gz gss-proxy-9b8e141b8e5286e4323df16557763e2a0be71c9e.tar.xz gss-proxy-9b8e141b8e5286e4323df16557763e2a0be71c9e.zip | |
Add gp_init_ring_buffer/gp_free_ring_buffer.
Guenther
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'proxy/src')
| -rw-r--r-- | proxy/src/gp_export.c | 107 | ||||
| -rw-r--r-- | proxy/src/gp_ring_buffer.h | 37 |
2 files changed, 143 insertions, 1 deletions
diff --git a/proxy/src/gp_export.c b/proxy/src/gp_export.c index c0dfebe..57caf39 100644 --- a/proxy/src/gp_export.c +++ b/proxy/src/gp_export.c @@ -1,8 +1,9 @@ /* GSS-PROXY - Copyright (C) 2011 Red Hat, Inc. + Copyright (C) 2011-2012 Red Hat, Inc. Copyright (C) 2011 Simo Sorce <simo.sorce@redhat.com> + Copyright (C) 2012 Guenther Deschner <guenther.deschner@redhat.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), @@ -33,6 +34,7 @@ #include <gssapi/gssapi_krb5.h> #include <pwd.h> #include <grp.h> +#include <pthread.h> /* FIXME: F I X M E * @@ -55,6 +57,109 @@ * *MUST* BE FIXED BEFORE ANY OFFICIAL RELEASE. */ +struct gp_ring_buffer_cred { + uint64_t count; + gss_cred_id_t cred; +}; + +struct gp_ring_buffer { + char *name; + uint32_t end; + uint64_t count; + pthread_mutex_t lock; + struct gp_ring_buffer_cred **creds; + uint32_t num_creds; +}; + +static void gp_free_ring_buffer_cred(struct gp_ring_buffer_cred *cred) +{ + uint32_t ret_min; + + if (!cred) { + return; + } + + gss_release_cred(&ret_min, &cred->cred); + + free(cred); +} + +void gp_free_ring_buffer(struct gp_ring_buffer *buffer) +{ + uint32_t i; + + if (!buffer) { + return; + } + + free(buffer->name); + + for (i=0; i < buffer->num_creds; i++) { + gp_free_ring_buffer_cred(buffer->creds[i]); + } + + free(buffer->creds); + + pthread_mutex_destroy(&buffer->lock); + + free(buffer); +} + +uint32_t gp_init_ring_buffer(uint32_t *min, + const char *name, + uint32_t ring_size, + struct gp_ring_buffer **buffer_out) +{ + struct gp_ring_buffer *buffer; + uint32_t ret_maj = 0; + uint32_t ret_min = 0; + int ret; + + GPDEBUG("gp_init_ring_buffer %s (size: %d)\n", name, ring_size); + + buffer = calloc(1, sizeof(struct gp_ring_buffer)); + if (!buffer) { + ret_min = ENOMEM; + ret_maj = GSS_S_FAILURE; + goto done; + } + + buffer->name = strdup(name); + if (!buffer->name) { + ret_min = ENOMEM; + ret_maj = GSS_S_FAILURE; + goto done; + } + + buffer->num_creds = ring_size; + + buffer->creds = calloc(sizeof(struct gp_ring_buffer_cred *), buffer->num_creds); + if (!buffer->creds) { + ret_min = ENOMEM; + ret_maj = GSS_S_FAILURE; + goto done; + } + + ret = pthread_mutex_init(&buffer->lock, NULL); + if (ret) { + ret_min = ret; + ret_maj = GSS_S_FAILURE; + goto done; + } + + ret_maj = GSS_S_COMPLETE; + ret_min = 0; + +done: + *min = ret_min; + if (ret_maj) { + gp_free_ring_buffer(buffer); + } + *buffer_out = buffer; + + return ret_maj; +} + uint32_t gp_export_gssx_cred(uint32_t *min, gss_cred_id_t *in, gssx_cred *out) { diff --git a/proxy/src/gp_ring_buffer.h b/proxy/src/gp_ring_buffer.h new file mode 100644 index 0000000..ea95f59 --- /dev/null +++ b/proxy/src/gp_ring_buffer.h @@ -0,0 +1,37 @@ +/* + GSS-PROXY + + Copyright (C) 2012 Red Hat, Inc. + Copyright (C) 2012 Guenther Deschner <guenther.deschner@redhat.com> + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#ifndef _GP_RING_BUFFER_H_ +#define _GP_RING_BUFFER_H_ + +#include <gssapi/gssapi.h> + +uint32_t gp_init_ring_buffer(uint32_t *min, + const char *name, + uint32_t ring_size, + struct gp_ring_buffer **buffer_out); +void gp_free_ring_buffer(struct gp_ring_buffer *buffer); + +#endif /* _GP_RING_BUFFER_H_ */ |
