1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#ifndef	_SYSEVENT_CONF_MOD_H
28#define	_SYSEVENT_CONF_MOD_H
29
30#ifdef	__cplusplus
31extern "C" {
32#endif
33
34
35/*
36 * syseventd_print debug levels for sysevent_conf_mod
37 */
38#define	DBG_TEST	1	/* info of interest when testing */
39#define	DBG_EXEC	2	/* path and args to exec */
40#define	DBG_EVENTS	3	/* received events */
41#define	DBG_MATCHES	4	/* dump specs for matching events */
42#define	DBG_MACRO	5	/* macro expansion */
43#define	DBG_CONF_FILE	6	/* sysevent.conf parsing */
44#define	DBG_DETAILED	7	/* all the above and more */
45
46
47/*
48 * Directory where sysevent.conf files reside
49 */
50#define	SYSEVENT_CONFIG_DIR		"/etc/sysevent/config"
51
52/*
53 * Lock file name to serialize registry updates
54 */
55#define	LOCK_FILENAME			"/var/run/syseventconf.lock"
56
57/*
58 * sysevent.conf files list
59 */
60typedef struct conftab {
61	char		*cf_conf_file;		/* source conf file */
62	struct conftab	*cf_next;
63} conftab_t;
64
65/*
66 * sysevent.conf table
67 */
68typedef struct syseventtab {
69	char	*se_conf_file;			/* source conf file */
70	int	se_lineno;			/* line number */
71	char	*se_vendor;			/* vendor */
72	char	*se_publisher;			/* publisher */
73	char	*se_class;			/* event class */
74	char	*se_subclass;			/* event subclass */
75	char	*se_user;			/* user */
76	char	*se_reserved1;			/* reserved1 */
77	char	*se_reserved2;			/* reserved2 */
78	char	*se_path;			/* event path */
79	char	*se_args;			/* optional args */
80	uid_t	se_uid;				/* user id */
81	gid_t	se_gid;				/* group id */
82	struct	syseventtab *se_next;
83} syseventtab_t;
84
85typedef struct sysevent_hdr_info {
86	char	*class;
87	char	*subclass;
88	char	*vendor;
89	char	*publisher;
90} sysevent_hdr_info_t;
91
92
93/*
94 * Structures for building arbitarily long strings and argument lists
95 */
96typedef struct str {
97	char	*s_str;
98	int	s_len;
99	int	s_alloc;
100	int	s_hint;
101} str_t;
102
103/*
104 * Queue of commands ready to be transported to syseventconfd
105 */
106typedef struct cmdqueue {
107	sysevent_t	*event;
108	struct cmdqueue	*next;
109} cmdqueue_t;
110
111/*
112 * syseventconfd state
113 */
114enum {
115	CONFD_STATE_OK,
116	CONFD_STATE_NOT_RUNNING,
117	CONFD_STATE_STARTED,
118	CONFD_STATE_ERR,
119	CONFD_STATE_DISABLED
120};
121
122
123/*
124 * Prototypes
125 */
126static char *skip_spaces(char **cpp);
127static char *next_field(char **cpp);
128static void *sc_malloc(size_t n);
129static void *sc_realloc(void *p, size_t current, size_t n);
130static void sc_free(void *p, size_t n);
131static char *sc_strdup(char *cp);
132static void sc_strfree(char *s);
133
134static str_t *initstr(int hint);
135static void freestr(str_t *str);
136static void resetstr(str_t *str);
137static int strcopys(str_t *str, char *s);
138static int strcats(str_t *str, char *s);
139static int strcatc(str_t *str, int c);
140static char *fstrgets(str_t *str, FILE *fp);
141static void strtrunc(str_t *str, int pos);
142
143static void build_event_table(void);
144static void free_event_table(void);
145static int enter_lock(char *lock_file);
146static void exit_lock(int lock_fd, char *lock_file);
147static str_t *snip_identifier(char *id, char **end);
148static str_t *snip_delimited_identifier(char *id, char **end);
149static char *se_attr_type_to_str(int se_attr_type);
150static str_t *find_macro_definition(sysevent_t *ev, nvlist_t *nvlist,
151	syseventtab_t *sep, char *token, sysevent_hdr_info_t *hdr);
152static int expand_macros(sysevent_t *ev, nvlist_t *nvlist,
153	syseventtab_t *sep, str_t *line, sysevent_hdr_info_t *hdr);
154static void start_syseventconfd(void);
155static int system1(const char *s_path, const char *s);
156static void abort_cmd_queue(void);
157static int queue_event(sysevent_t *ev, syseventtab_t *sep,
158	sysevent_hdr_info_t *hdr);
159static int transport_event(sysevent_t *cmd);
160static void transport_queued_events(void);
161static int sysevent_conf_event(sysevent_t *ev, int flag);
162
163
164#ifdef	__cplusplus
165}
166#endif
167
168#endif	/* _SYSEVENT_CONF_MOD_H */
169