diff options
author | Jean-Jacques Bernard-Gundol <jjbg@cvs.openbsd.org> | 2001-10-24 08:16:43 +0000 |
---|---|---|
committer | Jean-Jacques Bernard-Gundol <jjbg@cvs.openbsd.org> | 2001-10-24 08:16:43 +0000 |
commit | dab7fa54300ebdfe67399b7ae0db895888157c2a (patch) | |
tree | ca74c2edb5bbd260a106b689c3ae65a42c55bb12 /kerberosV | |
parent | d63faf6dea63e4725598059c282c6c69d1787061 (diff) |
syslog_r() implementation. deraadt@ ok.
Diffstat (limited to 'kerberosV')
-rw-r--r-- | kerberosV/src/lib/krb5/log.c | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/kerberosV/src/lib/krb5/log.c b/kerberosV/src/lib/krb5/log.c index 64c51a2d946..f179503ba38 100644 --- a/kerberosV/src/lib/krb5/log.c +++ b/kerberosV/src/lib/krb5/log.c @@ -33,7 +33,7 @@ #include "krb5_locl.h" -RCSID("$KTH: log.c,v 1.25 2000/09/17 21:46:07 assar Exp $"); +RCSID("$KTH: log.c,v 1.26 2001/05/14 06:14:49 assar Exp $"); struct facility { int min; @@ -120,11 +120,14 @@ krb5_initlog(krb5_context context, krb5_log_facility **fac) { krb5_log_facility *f = calloc(1, sizeof(*f)); - if(f == NULL) + if(f == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; + } f->program = strdup(program); if(f->program == NULL){ free(f); + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; } *fac = f; @@ -141,8 +144,10 @@ krb5_addlog_func(krb5_context context, void *data) { struct facility *fp = log_realloc(fac); - if(fp == NULL) + if(fp == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; + } fp->min = min; fp->max = max; fp->log = log; @@ -151,8 +156,9 @@ krb5_addlog_func(krb5_context context, return 0; } +/* Avoid conflict with syslog_data in syslog.h, rename to syslog_d */ -struct syslog_data{ +struct syslog_d{ int priority; }; @@ -162,7 +168,7 @@ log_syslog(const char *time, void *data) { - struct syslog_data *s = data; + struct syslog_d *s = data; syslog(s->priority, "%s", msg); } @@ -178,11 +184,13 @@ open_syslog(krb5_context context, krb5_log_facility *facility, int min, int max, const char *sev, const char *fac) { - struct syslog_data *sd = malloc(sizeof(*sd)); + struct syslog_d *sd = malloc(sizeof(*sd)); int i; - if(sd == NULL) + if(sd == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; + } i = find_value(sev, syslogvals); if(i == -1) i = LOG_ERR; @@ -232,8 +240,10 @@ open_file(krb5_context context, krb5_log_facility *fac, int min, int max, char *filename, char *mode, FILE *f, int keep_open) { struct file_data *fd = malloc(sizeof(*fd)); - if(fd == NULL) + if(fd == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; + } fd->filename = filename; fd->mode = mode; fd->fd = f; @@ -245,11 +255,13 @@ open_file(krb5_context context, krb5_log_facility *fac, int min, int max, krb5_error_code -krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p) +krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *orig) { krb5_error_code ret = 0; int min = 0, max = -1, n; char c; + const char *p = orig; + n = sscanf(p, "%d%c%d/", &min, &c, &max); if(n == 2){ if(c == '/') { @@ -263,7 +275,10 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p) } if(n){ p = strchr(p, '/'); - if(p == NULL) return HEIM_ERR_LOG_PARSE; + if(p == NULL) { + krb5_set_error_string (context, "failed to parse \"%s\"", orig); + return HEIM_ERR_LOG_PARSE; + } p++; } if(strcmp(p, "STDERR") == 0){ @@ -275,17 +290,26 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p) FILE *file = NULL; int keep_open = 0; fn = strdup(p + 5); - if(fn == NULL) + if(fn == NULL) { + krb5_set_error_string (context, "malloc: out of memory"); return ENOMEM; + } if(p[4] == '='){ int i = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_APPEND, 0666); - if(i < 0) - return errno; + if(i < 0) { + ret = errno; + krb5_set_error_string (context, "open(%s): %s", fn, + strerror(ret)); + return ret; + } file = fdopen(i, "a"); if(file == NULL){ + ret = errno; close(i); - return errno; + krb5_set_error_string (context, "fdopen(%s): %s", fn, + strerror(ret)); + return ret; } keep_open = 1; } @@ -303,6 +327,7 @@ krb5_addlog_dest(krb5_context context, krb5_log_facility *f, const char *p) facility = "AUTH"; ret = open_syslog(context, f, min, max, severity, facility); }else{ + krb5_set_error_string (context, "unknown log type: %s", p); ret = HEIM_ERR_LOG_PARSE; /* XXX */ } return ret; |