static krb5_error_code parse_section(char *p, krb5_config_section **s,
krb5_config_section **res,
- const char **error_message);
+ const char **err_message);
static krb5_error_code parse_binding(struct fileptr *f, unsigned *lineno, char *p,
krb5_config_binding **b,
krb5_config_binding **parent,
- const char **error_message);
+ const char **err_message);
static krb5_error_code parse_list(struct fileptr *f, unsigned *lineno,
krb5_config_binding **parent,
- const char **error_message);
+ const char **err_message);
static krb5_config_section *
get_entry(krb5_config_section **parent, const char *name, int type)
*
* starting at the line in `p', storing the resulting structure in
* `s' and hooking it into `parent'.
- * Store the error message in `error_message'.
+ * Store the error message in `err_message'.
*/
static krb5_error_code
parse_section(char *p, krb5_config_section **s, krb5_config_section **parent,
- const char **error_message)
+ const char **err_message)
{
char *p1;
krb5_config_section *tmp;
p1 = strchr (p + 1, ']');
if (p1 == NULL) {
- *error_message = "missing ]";
+ *err_message = "missing ]";
return KRB5_CONFIG_BADFORMAT;
}
*p1 = '\0';
tmp = get_entry(parent, p + 1, krb5_config_list);
if(tmp == NULL) {
- *error_message = "out of memory";
+ *err_message = "out of memory";
return KRB5_CONFIG_BADFORMAT;
}
*s = tmp;
/*
* Parse a brace-enclosed list from `f', hooking in the structure at
* `parent'.
- * Store the error message in `error_message'.
+ * Store the error message in `err_message'.
*/
static krb5_error_code
parse_list(struct fileptr *f, unsigned *lineno, krb5_config_binding **parent,
- const char **error_message)
+ const char **err_message)
{
char buf[BUFSIZ];
krb5_error_code ret;
return 0;
if (*p == '\0')
continue;
- ret = parse_binding (f, lineno, p, &b, parent, error_message);
+ ret = parse_binding (f, lineno, p, &b, parent, err_message);
if (ret)
return ret;
}
*lineno = beg_lineno;
- *error_message = "unclosed {";
+ *err_message = "unclosed {";
return KRB5_CONFIG_BADFORMAT;
}
static krb5_error_code
parse_binding(struct fileptr *f, unsigned *lineno, char *p,
krb5_config_binding **b, krb5_config_binding **parent,
- const char **error_message)
+ const char **err_message)
{
krb5_config_binding *tmp;
char *p1, *p2;
while (*p && *p != '=' && !isspace((unsigned char)*p))
++p;
if (*p == '\0') {
- *error_message = "missing =";
+ *err_message = "missing =";
return KRB5_CONFIG_BADFORMAT;
}
p2 = p;
while (isspace((unsigned char)*p))
++p;
if (*p != '=') {
- *error_message = "missing =";
+ *err_message = "missing =";
return KRB5_CONFIG_BADFORMAT;
}
++p;
if (*p == '{') {
tmp = get_entry(parent, p1, krb5_config_list);
if (tmp == NULL) {
- *error_message = "out of memory";
+ *err_message = "out of memory";
return KRB5_CONFIG_BADFORMAT;
}
- ret = parse_list (f, lineno, &tmp->u.list, error_message);
+ ret = parse_list (f, lineno, &tmp->u.list, err_message);
} else {
tmp = get_entry(parent, p1, krb5_config_string);
if (tmp == NULL) {
- *error_message = "out of memory";
+ *err_message = "out of memory";
return KRB5_CONFIG_BADFORMAT;
}
p1 = p;
/*
* Parse the config file `fname', generating the structures into `res'
- * returning error messages in `error_message'
+ * returning error messages in `err_message'
*/
static krb5_error_code
krb5_config_parse_debug (struct fileptr *f,
krb5_config_section **res,
unsigned *lineno,
- const char **error_message)
+ const char **err_message)
{
krb5_config_section *s = NULL;
krb5_config_binding *b = NULL;
if (*p == '#' || *p == ';')
continue;
if (*p == '[') {
- ret = parse_section(p, &s, res, error_message);
+ ret = parse_section(p, &s, res, err_message);
if (ret)
return ret;
b = NULL;
} else if (*p == '}') {
- *error_message = "unmatched }";
+ *err_message = "unmatched }";
return EINVAL; /* XXX */
} else if(*p != '\0') {
if (s == NULL) {
- *error_message = "binding before section";
+ *err_message = "binding before section";
return EINVAL;
}
- ret = parse_binding(f, lineno, p, &b, &s->u.list, error_message);
+ ret = parse_binding(f, lineno, p, &b, &s->u.list, err_message);
if (ret)
return ret;
}
--- /dev/null
+/*
+ * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <config.h>
+
+#ifndef HAVE_VSYSLOG
+
+#include <stdio.h>
+#include <syslog.h>
+#include <stdarg.h>
+
+#include "roken.h"
+
+/*
+ * the theory behind this is that we might be trying to call vsyslog
+ * when there's no memory left, and we should try to be as useful as
+ * possible. And the format string should say something about what's
+ * failing.
+ */
+
+static void
+simple_vsyslog(int pri, const char *fmt, va_list ap)
+{
+ syslog (pri, "%s", fmt);
+}
+
+/*
+ * do like syslog but with a `va_list'
+ */
+
+ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
+vsyslog(int pri, const char *fmt, va_list ap)
+{
+ char *fmt2;
+ const char *p;
+ char *p2;
+ int ret;
+ int saved_errno = errno;
+ int fmt_len = strlen (fmt);
+ int fmt2_len = fmt_len;
+ char *buf;
+
+ fmt2 = malloc (fmt_len + 1);
+ if (fmt2 == NULL) {
+ simple_vsyslog (pri, fmt, ap);
+ return;
+ }
+
+ for (p = fmt, p2 = fmt2; *p != '\0'; ++p) {
+ if (p[0] == '%' && p[1] == 'm') {
+ const char *e = strerror (saved_errno);
+ int e_len = strlen (e);
+ char *tmp;
+ int pos;
+
+ pos = p2 - fmt2;
+ fmt2_len += e_len - 2;
+ tmp = realloc (fmt2, fmt2_len + 1);
+ if (tmp == NULL) {
+ free (fmt2);
+ simple_vsyslog (pri, fmt, ap);
+ return;
+ }
+ fmt2 = tmp;
+ p2 = fmt2 + pos;
+ memmove (p2, e, e_len);
+ p2 += e_len;
+ ++p;
+ } else
+ *p2++ = *p;
+ }
+ *p2 = '\0';
+
+ ret = vasprintf (&buf, fmt2, ap);
+ free (fmt2);
+ if (ret < 0 || buf == NULL) {
+ simple_vsyslog (pri, fmt, ap);
+ return;
+ }
+ syslog (pri, "%s", buf);
+ free (buf);
+}
+#endif