/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef struct logr_eventlog { const char *el_name; const char *el_path; } logr_eventlog_t; logr_eventlog_t logr_eventlog[] = { { "System", "/var/adm/messages" }, { "smbd", "/var/smb/smbd_log.txt" }, { "smbrdr", "/var/smb/smbrdr_log.txt" } }; typedef enum { LOGR_MONTH = 0, LOGR_DAY, LOGR_TIME, LOGR_HOST, LOGR_SOURCE, LOGR_IDTAG, LOGR_ID, LOGR_PRI_FAC, LOGR_NARG } logr_syslog_tokens_t; /* * Event code translation struct for use in processing config file */ typedef struct logr_priority { char *p_name; int p_value; } logr_priority_t; static logr_priority_t logr_pri_names[] = { "panic", LOG_EMERG, "emerg", LOG_EMERG, "alert", LOG_ALERT, "crit", LOG_CRIT, "err", LOG_ERR, "error", LOG_ERR, "warn", LOG_WARNING, "warning", LOG_WARNING, "notice", LOG_NOTICE, "info", LOG_INFO, "debug", LOG_DEBUG }; typedef struct logr_syslog_node { list_node_t ln_node; char ln_logline[LOGR_MAXENTRYLEN]; } logr_syslog_node_t; static void *logr_interposer_hdl = NULL; static struct { boolean_t (*logr_op_supported)(char *); int (*logr_op_snapshot)(logr_context_t *); } logr_interposer_ops; /* * Set the syslog timestamp. * * This is a private helper for logr_syslog_parse_entry(), which * must ensure that the appropriate argv entries are non-null. */ static void logr_syslog_set_timestamp(char **argv, logr_entry_t *le) { char *month = argv[LOGR_MONTH]; char *day = argv[LOGR_DAY]; char *time = argv[LOGR_TIME]; struct timeval now; struct tm tm, cur_tm; char buf[32]; bzero(&tm, sizeof (tm)); (void) snprintf(buf, 32, "%s %s %s", month, day, time); if (strptime(buf, "%b" "%d" "%H:%M:%S", &tm) == NULL) { le->le_timestamp.tv_sec = 0; return; } (void) gettimeofday(&now, NULL); (void) localtime_r(&now.tv_sec, &cur_tm); tm.tm_isdst = cur_tm.tm_isdst; tm.tm_year = cur_tm.tm_year; if (tm.tm_mon > cur_tm.tm_mon) tm.tm_year--; le->le_timestamp.tv_sec = mktime(&tm); } /* * Set the syslog priority. * * This is a private helper for logr_syslog_parse_entry(), which * must ensure that the appropriate argv entries are non-null. */ static void logr_syslog_set_priority(char **argv, logr_entry_t *le) { logr_priority_t *entry; char *token; int sz = sizeof (logr_pri_names) / sizeof (logr_pri_names[0]); int i; le->le_pri = LOG_INFO; if ((token = argv[LOGR_PRI_FAC]) == NULL) return; for (i = 0; i < sz; i++) { entry = &logr_pri_names[i]; if (strstr(token, entry->p_name) != NULL) { le->le_pri = entry->p_value; break; } } } /* * Parse a syslog entry into a log_entry_t structure. A typical syslog * entry has one of the following formats: * *