17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 23*293d1fc4Spd155743 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate * 267c478bd9Sstevel@tonic-gate * Copyright 1983,1984,1985,1986,1987,1988,1989 AT&T. 277c478bd9Sstevel@tonic-gate * All rights reserved. 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 307c478bd9Sstevel@tonic-gate * The Regents of the University of California 317c478bd9Sstevel@tonic-gate * All Rights Reserved 327c478bd9Sstevel@tonic-gate * 337c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 347c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 357c478bd9Sstevel@tonic-gate * contributors. 367c478bd9Sstevel@tonic-gate */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifndef _SYSLOGD_H 397c478bd9Sstevel@tonic-gate #define _SYSLOGD_H 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #ifdef __cplusplus 447c478bd9Sstevel@tonic-gate extern "C" { 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate struct utmpx dummy; /* for sizeof ut_user, ut_line */ 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * Various constants & tunable values for syslogd 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate #define DEBUGFILE "/var/adm/syslog.debug" 537c478bd9Sstevel@tonic-gate #define MAXLINE 1024 /* maximum line length */ 547c478bd9Sstevel@tonic-gate #define DEFUPRI (LOG_USER|LOG_INFO) 557c478bd9Sstevel@tonic-gate #define DEFSPRI (LOG_KERN|LOG_CRIT) 567c478bd9Sstevel@tonic-gate #define MARKCOUNT 3 /* ratio of minor to major marks */ 577c478bd9Sstevel@tonic-gate #define UNAMESZ (sizeof (dummy.ut_user)) /* length of a login name */ 587c478bd9Sstevel@tonic-gate #define UDEVSZ (sizeof (dummy.ut_line)) /* length of login dev name */ 597c478bd9Sstevel@tonic-gate #define MAXUNAMES 20 /* maximum number of user names */ 607c478bd9Sstevel@tonic-gate #define Q_HIGHWATER_MARK 10000 /* max outstanding msgs per file */ 617c478bd9Sstevel@tonic-gate #define NOPRI 0x10 /* the "no priority" priority */ 627c478bd9Sstevel@tonic-gate #define LOG_MARK (LOG_NFACILITIES << 3) /* mark "facility" */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate /* 657c478bd9Sstevel@tonic-gate * host_list_t structure contains a list of hostnames for a given address 667c478bd9Sstevel@tonic-gate */ 677c478bd9Sstevel@tonic-gate typedef struct host_list { 687c478bd9Sstevel@tonic-gate int hl_cnt; /* number of hl_hosts entries */ 697c478bd9Sstevel@tonic-gate char **hl_hosts; /* hostnames */ 707c478bd9Sstevel@tonic-gate pthread_mutex_t hl_mutex; /* protects this structs members */ 717c478bd9Sstevel@tonic-gate int hl_refcnt; /* reference count */ 727c478bd9Sstevel@tonic-gate } host_list_t; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * host_info_t structure contains address information for a host 767c478bd9Sstevel@tonic-gate * from which we received a message. 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate typedef struct host_info { 797c478bd9Sstevel@tonic-gate struct netconfig *ncp; 807c478bd9Sstevel@tonic-gate struct netbuf addr; 817c478bd9Sstevel@tonic-gate } host_info_t; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * statistics structure attached to each filed for debugging 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate typedef struct filed_stats { 877c478bd9Sstevel@tonic-gate int flag; /* flag word */ 887c478bd9Sstevel@tonic-gate int total; /* total messages logged */ 897c478bd9Sstevel@tonic-gate int dups; /* duplicate messages */ 907c478bd9Sstevel@tonic-gate int cantfwd; /* can't forward */ 917c478bd9Sstevel@tonic-gate int errs; /* write errors */ 927c478bd9Sstevel@tonic-gate } filed_stats_t; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * internal representation of a log message. Includes all routing & bookkeeping 977c478bd9Sstevel@tonic-gate * information for the message. created in the system & network poll routines, 987c478bd9Sstevel@tonic-gate * and passed among the various processing threads as necessary 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate typedef struct log_message { 1027c478bd9Sstevel@tonic-gate pthread_mutex_t msg_mutex; /* protects this structs members */ 1037c478bd9Sstevel@tonic-gate int refcnt; /* message reference count */ 1047c478bd9Sstevel@tonic-gate int pri; /* message priority */ 1057c478bd9Sstevel@tonic-gate int flags; /* misc flags */ 1067c478bd9Sstevel@tonic-gate time_t ts; /* timestamp */ 1077c478bd9Sstevel@tonic-gate host_list_t *hlp; /* ptr to host list struct */ 1087c478bd9Sstevel@tonic-gate void *ptr; /* for anonymous use */ 1097c478bd9Sstevel@tonic-gate char msg[MAXLINE+1]; /* the message itself */ 1107c478bd9Sstevel@tonic-gate } log_message_t; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(log_message_t::msg_mutex, log_message_t)) 1137c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(log_message_t)) 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* 1177c478bd9Sstevel@tonic-gate * format of a saved message. For each active file we are logging 1187c478bd9Sstevel@tonic-gate * we save the last message and the current message, to make it 1197c478bd9Sstevel@tonic-gate * possible to suppress duplicates on a per file basis. Earlier 1207c478bd9Sstevel@tonic-gate * syslogd's used a global buffer for duplicate checking, so 1217c478bd9Sstevel@tonic-gate * strict per file duplicate suppression was not always possible. 1227c478bd9Sstevel@tonic-gate */ 1237c478bd9Sstevel@tonic-gate typedef struct saved_msg { 1247c478bd9Sstevel@tonic-gate int pri; 1257c478bd9Sstevel@tonic-gate int flags; 1267c478bd9Sstevel@tonic-gate time_t time; 1277c478bd9Sstevel@tonic-gate char host[SYS_NMLN+1]; 1287c478bd9Sstevel@tonic-gate char msg[MAXLINE+1]; 1297c478bd9Sstevel@tonic-gate } saved_message_t; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate /* 1337c478bd9Sstevel@tonic-gate * Flags to logmsg(). 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #define IGN_CONS 0x001 /* don't print on console */ 1377c478bd9Sstevel@tonic-gate #define IGN_FILE 0x002 /* don't write to log file */ 1387c478bd9Sstevel@tonic-gate #define SYNC_FILE 0x004 /* do fsync on file after printing */ 1397c478bd9Sstevel@tonic-gate #define NOCOPY 0x008 /* don't suppress duplicate messages */ 1407c478bd9Sstevel@tonic-gate #define ADDDATE 0x010 /* add a date to the message */ 1417c478bd9Sstevel@tonic-gate #define MARK 0x020 /* this message is a mark */ 1427c478bd9Sstevel@tonic-gate #define LOGSYNC 0x040 /* nightly log update message */ 1437c478bd9Sstevel@tonic-gate #define NETWORK 0x100 /* message came from the net */ 1447c478bd9Sstevel@tonic-gate #define SHUTDOWN 0x200 /* internal shutdown message */ 1457c478bd9Sstevel@tonic-gate #define FLUSHMSG 0x400 /* internal flush message */ 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate /* 1487c478bd9Sstevel@tonic-gate * This structure represents the files that will have log 1497c478bd9Sstevel@tonic-gate * copies printed. There is one instance of this for each 1507c478bd9Sstevel@tonic-gate * file that is being logged to. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate struct filed { 1537c478bd9Sstevel@tonic-gate pthread_mutex_t filed_mutex; /* protects this filed */ 1547c478bd9Sstevel@tonic-gate pthread_t f_thread; /* thread that handles this file */ 1557c478bd9Sstevel@tonic-gate dataq_t f_queue; /* queue of messages for this file */ 1567c478bd9Sstevel@tonic-gate int f_queue_count; /* count of messages on the queue */ 1577c478bd9Sstevel@tonic-gate int f_prev_queue_count; /* prev count of msgs on the queue */ 1587c478bd9Sstevel@tonic-gate short f_type; /* entry type, see below */ 1597c478bd9Sstevel@tonic-gate short f_orig_type; /* save entry type */ 1607c478bd9Sstevel@tonic-gate int f_file; /* file descriptor */ 1617c478bd9Sstevel@tonic-gate int f_msgflag; /* message disposition */ 1627c478bd9Sstevel@tonic-gate filed_stats_t f_stat; /* statistics */ 1637c478bd9Sstevel@tonic-gate saved_message_t f_prevmsg; /* previous message */ 1647c478bd9Sstevel@tonic-gate saved_message_t f_current; /* current message */ 1657c478bd9Sstevel@tonic-gate int f_prevcount; /* message repeat count */ 1667c478bd9Sstevel@tonic-gate uchar_t f_pmask[LOG_NFACILITIES+1]; /* priority mask */ 1677c478bd9Sstevel@tonic-gate union { 1687c478bd9Sstevel@tonic-gate char f_uname[MAXUNAMES][SYS_NMLN + 1]; 1697c478bd9Sstevel@tonic-gate struct { 1707c478bd9Sstevel@tonic-gate char f_hname[SYS_NMLN + 1]; 1717c478bd9Sstevel@tonic-gate struct netbuf f_addr; 1727c478bd9Sstevel@tonic-gate } f_forw; /* forwarding address */ 1737c478bd9Sstevel@tonic-gate char f_fname[MAXPATHLEN + 1]; 1747c478bd9Sstevel@tonic-gate } f_un; 1757c478bd9Sstevel@tonic-gate }; 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(filed::filed_mutex, filed)) 1787c478bd9Sstevel@tonic-gate _NOTE(DATA_READABLE_WITHOUT_LOCK(filed)) 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* values for f_type */ 1817c478bd9Sstevel@tonic-gate #define F_UNUSED 0 /* unused entry */ 1827c478bd9Sstevel@tonic-gate #define F_FILE 1 /* regular file */ 1837c478bd9Sstevel@tonic-gate #define F_TTY 2 /* terminal */ 1847c478bd9Sstevel@tonic-gate #define F_CONSOLE 3 /* console terminal */ 1857c478bd9Sstevel@tonic-gate #define F_FORW 4 /* remote machine */ 1867c478bd9Sstevel@tonic-gate #define F_USERS 5 /* list of users */ 1877c478bd9Sstevel@tonic-gate #define F_WALL 6 /* everyone logged on */ 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* 1907c478bd9Sstevel@tonic-gate * values for logit routine 1917c478bd9Sstevel@tonic-gate */ 1927c478bd9Sstevel@tonic-gate #define CURRENT 0 /* print current message */ 1937c478bd9Sstevel@tonic-gate #define SAVED 1 /* print saved message */ 1947c478bd9Sstevel@tonic-gate /* 1957c478bd9Sstevel@tonic-gate * values for f_msgflag 1967c478bd9Sstevel@tonic-gate */ 1977c478bd9Sstevel@tonic-gate #define CURRENT_VALID 0x01 /* new message is good */ 1987c478bd9Sstevel@tonic-gate #define OLD_VALID 0x02 /* old message is valid */ 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * code translation struct for use in processing config file 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate struct code { 2047c478bd9Sstevel@tonic-gate char *c_name; 2057c478bd9Sstevel@tonic-gate int c_val; 2067c478bd9Sstevel@tonic-gate }; 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate /* 2097c478bd9Sstevel@tonic-gate * structure describing a message to be sent to the wall thread. 2107c478bd9Sstevel@tonic-gate * the thread id and attributes are stored in the structure 2117c478bd9Sstevel@tonic-gate * passed to the thread, and the thread is created detached. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate typedef struct wall_device { 2147c478bd9Sstevel@tonic-gate pthread_t thread; 2157c478bd9Sstevel@tonic-gate pthread_attr_t thread_attr; 2167c478bd9Sstevel@tonic-gate char dev[PATH_MAX + 1]; 2177c478bd9Sstevel@tonic-gate char msg[MAXLINE+1]; 2187c478bd9Sstevel@tonic-gate char ut_name[sizeof (dummy.ut_name)]; 2197c478bd9Sstevel@tonic-gate } walldev_t; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* 2227c478bd9Sstevel@tonic-gate * hostname caching struct to reduce hostname name lookup. 2237c478bd9Sstevel@tonic-gate */ 2247c478bd9Sstevel@tonic-gate struct hostname_cache { 2257c478bd9Sstevel@tonic-gate struct hostname_cache *next; 2267c478bd9Sstevel@tonic-gate struct netbuf addr; 2277c478bd9Sstevel@tonic-gate struct netconfig *ncp; 2287c478bd9Sstevel@tonic-gate host_list_t *h; 2297c478bd9Sstevel@tonic-gate time_t expire; 2307c478bd9Sstevel@tonic-gate }; 2317c478bd9Sstevel@tonic-gate 232*293d1fc4Spd155743 #define DEF_HNC_SIZE 2037 233*293d1fc4Spd155743 #define DEF_HNC_TTL 1200 /* 20 minutes */ 234*293d1fc4Spd155743 #define MAX_BUCKETS 30 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* 2377c478bd9Sstevel@tonic-gate * function prototypes 2387c478bd9Sstevel@tonic-gate */ 2397c478bd9Sstevel@tonic-gate int main(int argc, char **argv); 2407c478bd9Sstevel@tonic-gate static void usage(void); 2417c478bd9Sstevel@tonic-gate static void untty(void); 2427c478bd9Sstevel@tonic-gate static void formatnet(struct netbuf *nbp, log_message_t *mp); 2437c478bd9Sstevel@tonic-gate static void formatsys(struct log_ctl *lp, char *msg, int sync); 2447c478bd9Sstevel@tonic-gate static void *logmsg(void *ap); 2457c478bd9Sstevel@tonic-gate static void wallmsg(struct filed *f, char *from, char *msg); 2467c478bd9Sstevel@tonic-gate static host_list_t *cvthname(struct netbuf *nbp, struct netconfig *ncp, char *); 2477c478bd9Sstevel@tonic-gate static void set_flush_msg(struct filed *f); 2487c478bd9Sstevel@tonic-gate static void flushmsg(int flags); 2497c478bd9Sstevel@tonic-gate void logerror(const char *type, ...); 2507c478bd9Sstevel@tonic-gate static void init(void); 2517c478bd9Sstevel@tonic-gate static void conf_init(void); 2527c478bd9Sstevel@tonic-gate static void cfline(char *line, int lineno, struct filed *f); 2537c478bd9Sstevel@tonic-gate static int decode(char *name, struct code *codetab); 2547c478bd9Sstevel@tonic-gate static int ismyaddr(struct netbuf *nbp); 2557c478bd9Sstevel@tonic-gate static void getnets(void); 2567c478bd9Sstevel@tonic-gate static int addnet(struct netconfig *ncp, struct netbuf *nbp); 2577c478bd9Sstevel@tonic-gate static void bindnet(void); 2587c478bd9Sstevel@tonic-gate static int logforward(struct filed *f, char *ebuf); 2597c478bd9Sstevel@tonic-gate static int amiloghost(void); 2607c478bd9Sstevel@tonic-gate static int same_addr(struct netbuf *, struct netbuf *); 2617c478bd9Sstevel@tonic-gate static void prepare_sys_poll(void); 2627c478bd9Sstevel@tonic-gate static void *sys_poll(void *ap); 2637c478bd9Sstevel@tonic-gate static void getkmsg(int); 2647c478bd9Sstevel@tonic-gate static void *net_poll(void *ap); 2657c478bd9Sstevel@tonic-gate static log_message_t *new_msg(void); 2667c478bd9Sstevel@tonic-gate static void free_msg(log_message_t *lm); 2677c478bd9Sstevel@tonic-gate static int logmymsg(int pri, char *msg, int flags, int); 2687c478bd9Sstevel@tonic-gate static void *logit(void *ap); 2697c478bd9Sstevel@tonic-gate static void freehl(host_list_t *h); 2707c478bd9Sstevel@tonic-gate static int filed_init(struct filed *h); 2717c478bd9Sstevel@tonic-gate static void copy_msg(struct filed *f); 2727c478bd9Sstevel@tonic-gate static void dumpstats(int fd); 2737c478bd9Sstevel@tonic-gate static void filter_string(char *orig, char *new, size_t max); 2747c478bd9Sstevel@tonic-gate static int openklog(char *name, int mode); 2757c478bd9Sstevel@tonic-gate static void writemsg(int selection, struct filed *f); 2767c478bd9Sstevel@tonic-gate static void *writetodev(void *ap); 2777c478bd9Sstevel@tonic-gate static int shutdown_msg(void); 2787c478bd9Sstevel@tonic-gate static void server(void *, char *, size_t, door_desc_t *, uint_t); 2797c478bd9Sstevel@tonic-gate static char *alloc_stacks(int); 2807c478bd9Sstevel@tonic-gate static void dealloc_stacks(int); 2817c478bd9Sstevel@tonic-gate static int checkm4(void); 2827c478bd9Sstevel@tonic-gate static void filed_destroy(struct filed *f); 2837c478bd9Sstevel@tonic-gate static void open_door(void); 2847c478bd9Sstevel@tonic-gate static void close_door(void); 2857c478bd9Sstevel@tonic-gate static void delete_doorfiles(void); 2867c478bd9Sstevel@tonic-gate static void signull(int, siginfo_t *, void *); 2877c478bd9Sstevel@tonic-gate static int putctrlc(int, char **, size_t *, size_t); 2887c478bd9Sstevel@tonic-gate static size_t findnl_bkwd(const char *, const size_t); 2897c478bd9Sstevel@tonic-gate static size_t copynl_frwd(char *, const size_t, const char *, const size_t); 2907c478bd9Sstevel@tonic-gate static size_t copy_frwd(char *, const size_t, const char *, const size_t); 2917c478bd9Sstevel@tonic-gate static void logerror_format(const char *, char *, va_list); 2927c478bd9Sstevel@tonic-gate static int logerror_to_console(int, const char *); 2937c478bd9Sstevel@tonic-gate static void defaults(void); 2947c478bd9Sstevel@tonic-gate static void shutdown_input(void); 2957c478bd9Sstevel@tonic-gate static void *hostname_lookup(void *); 2967c478bd9Sstevel@tonic-gate static void reconfigure(void); 2977c478bd9Sstevel@tonic-gate static void disable_errorlog(void); 2987c478bd9Sstevel@tonic-gate static void enable_errorlog(void); 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate static void hnc_init(int); 301*293d1fc4Spd155743 static host_list_t *hnc_lookup(struct netbuf *, 302*293d1fc4Spd155743 struct netconfig *, int *); 303*293d1fc4Spd155743 static void hnc_register(struct netbuf *, 304*293d1fc4Spd155743 struct netconfig *, host_list_t *, int); 3057c478bd9Sstevel@tonic-gate static void hnc_unreg(struct hostname_cache **); 306*293d1fc4Spd155743 static int addr_hash(struct netbuf *nbp); 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate #ifdef __cplusplus 3107c478bd9Sstevel@tonic-gate } 3117c478bd9Sstevel@tonic-gate #endif 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate #endif /* _SYSLOGD_H */ 314