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