summaryrefslogtreecommitdiff
path: root/lib/radsec.c
diff options
context:
space:
mode:
authorlinus <linus@nordu.net>2011-01-21 13:09:00 +0100
committerlinus <linus@nordu.net>2011-01-21 13:09:00 +0100
commita29c3f1a7a00684804b032970ed347fa05ca9cce (patch)
treed17f8a509ec2c216898e925ec2979e9434d06ae4 /lib/radsec.c
parent2bd25761177373972eb38a0700426787f1fb2d24 (diff)
Fix bug where one or two stanzas in a config file would be but not more.
Also restructure error handling in rs_context_create().
Diffstat (limited to 'lib/radsec.c')
-rw-r--r--lib/radsec.c92
1 files changed, 55 insertions, 37 deletions
diff --git a/lib/radsec.c b/lib/radsec.c
index 40d14fc..bc06894 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -26,55 +26,73 @@
int
rs_context_create(struct rs_context **ctx, const char *dict)
{
+ int err = RSE_OK;
struct rs_context *h;
+ char *buf1 = NULL, *buf2 = NULL;
+ char *dir, *fn;
+
+ assert (dict);
if (ctx)
*ctx = NULL;
h = (struct rs_context *) malloc (sizeof(struct rs_context));
- if (h)
+ if (!h)
+ return RSE_NOMEM;
+
+ /* Initialize freeradius dictionary. */
+ buf1 = malloc (strlen (dict) + 1);
+ buf2 = malloc (strlen (dict) + 1);
+ if (!buf1 || !buf2)
+ {
+ err = RSE_NOMEM;
+ goto err_out;
+ }
+ strcpy (buf1, dict);
+ dir = dirname (buf1);
+ strcpy (buf2, dict);
+ fn = basename (buf2);
+ if (dict_init (dir, fn) < 0)
{
- char *buf1 = NULL, *buf2 = NULL;
- char *dir, *fn;
-
- buf1 = malloc (strlen (dict) + 1);
- buf2 = malloc (strlen (dict) + 1);
- if (!buf1 || !buf2)
- {
- free (h);
- if (buf1)
- free (buf1);
- if (buf2)
- free (buf2);
- return RSE_NOMEM;
- }
- strcpy (buf1, dict);
- dir = dirname (buf1);
- strcpy (buf2, dict);
- fn = basename (buf2);
- if (dict_init (dir, fn) < 0)
- {
- free (h);
- return RSE_SOME_ERROR;
- }
- free (buf1);
- free (buf2);
+ err = RSE_SOME_ERROR;
+ goto err_out;
+ }
+ free (buf1);
+ free (buf2);
+
#if defined RS_ENABLE_TLS
- ssl_init ();
+ ssl_init ();
#endif
#if defined (DEBUG)
- fr_log_fp = stderr;
- fr_debug_flag = 1;
+ fr_log_fp = stderr;
+ fr_debug_flag = 1;
#endif
- debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
-
- memset (h, 0, sizeof(struct rs_context));
- fr_randinit (&h->fr_randctx, 0);
- fr_rand_seed (NULL, 0);
+ debug_init ("libradsec"); /* radsecproxy compat, FIXME: remove */
- if (ctx)
- *ctx = h;
+ memset (h, 0, sizeof(struct rs_context));
+ h->realms = malloc (sizeof (struct rs_realm));
+ if (!h->realms)
+ {
+ err = RSE_NOMEM;
+ goto err_out;
}
- return h ? RSE_OK : RSE_NOMEM;
+ memset (h->realms, 0, sizeof (struct rs_realm));
+ h->realms->next = h->realms;
+ fr_randinit (&h->fr_randctx, 0);
+ fr_rand_seed (NULL, 0);
+
+ if (ctx)
+ *ctx = h;
+
+ return RSE_OK;
+
+ err_out:
+ if (buf1)
+ free (buf1);
+ if (buf2)
+ free (buf2);
+ if (h)
+ free (h);
+ return err;
}
void rs_context_destroy(struct rs_context *ctx)