1657a8c20SJan Friedel /*
2657a8c20SJan Friedel  * CDDL HEADER START
3657a8c20SJan Friedel  *
4657a8c20SJan Friedel  * The contents of this file are subject to the terms of the
5657a8c20SJan Friedel  * Common Development and Distribution License (the "License").
6657a8c20SJan Friedel  * You may not use this file except in compliance with the License.
7657a8c20SJan Friedel  *
8657a8c20SJan Friedel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9657a8c20SJan Friedel  * or http://www.opensolaris.org/os/licensing.
10657a8c20SJan Friedel  * See the License for the specific language governing permissions
11657a8c20SJan Friedel  * and limitations under the License.
12657a8c20SJan Friedel  *
13657a8c20SJan Friedel  * When distributing Covered Code, include this CDDL HEADER in each
14657a8c20SJan Friedel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15657a8c20SJan Friedel  * If applicable, add the following below this CDDL HEADER, with the
16657a8c20SJan Friedel  * fields enclosed by brackets "[]" replaced with your own identifying
17657a8c20SJan Friedel  * information: Portions Copyright [yyyy] [name of copyright owner]
18657a8c20SJan Friedel  *
19657a8c20SJan Friedel  * CDDL HEADER END
20657a8c20SJan Friedel  */
21657a8c20SJan Friedel /*
22657a8c20SJan Friedel  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23657a8c20SJan Friedel  * Use is subject to license terms.
24657a8c20SJan Friedel  *
25657a8c20SJan Friedel  */
26657a8c20SJan Friedel 
27657a8c20SJan Friedel #ifndef	_AUDIT_REMOTE_H
28657a8c20SJan Friedel #define	_AUDIT_REMOTE_H
29657a8c20SJan Friedel 
30657a8c20SJan Friedel 
31657a8c20SJan Friedel #ifdef __cplusplus
32657a8c20SJan Friedel extern "C" {
33657a8c20SJan Friedel #endif
34657a8c20SJan Friedel 
35657a8c20SJan Friedel #include <stdio.h>
36657a8c20SJan Friedel #include <security/auditd.h>
37657a8c20SJan Friedel 
38657a8c20SJan Friedel /* gettext() obfuscation routine for lint */
39657a8c20SJan Friedel #ifdef __lint
40657a8c20SJan Friedel #define	gettext(x)	x
41657a8c20SJan Friedel #endif
42657a8c20SJan Friedel 
43657a8c20SJan Friedel 
44657a8c20SJan Friedel /* send_record() return code */
45657a8c20SJan Friedel enum send_record_rc {
46657a8c20SJan Friedel 	SEND_RECORD_SUCCESS,
47657a8c20SJan Friedel 	SEND_RECORD_NEXT,
48657a8c20SJan Friedel 	SEND_RECORD_RETRY,
49657a8c20SJan Friedel 	SEND_RECORD_FAIL
50657a8c20SJan Friedel };
51657a8c20SJan Friedel typedef enum send_record_rc send_record_rc_t;
52657a8c20SJan Friedel 
53657a8c20SJan Friedel /* closing helpers - the reason of connection closure */
54657a8c20SJan Friedel enum close_rsn_e {
55657a8c20SJan Friedel 		RSN_UNDEFINED,		/* reason not defined */
56657a8c20SJan Friedel 		RSN_INIT_POLL,		/* poll() initialization failed */
57657a8c20SJan Friedel 		RSN_TOK_RECV_FAILED,	/* token receiving failed */
58657a8c20SJan Friedel 		RSN_TOK_TOO_BIG,	/* unacceptable token size */
59657a8c20SJan Friedel 		RSN_TOK_UNVERIFIABLE,	/* received unverifiable token */
60657a8c20SJan Friedel 		RSN_SOCKET_CLOSE,	/* socket closure */
61657a8c20SJan Friedel 		RSN_SOCKET_CREATE,	/* socket creation */
62657a8c20SJan Friedel 		RSN_CONNECTION_CREATE,	/* connection creation */
63657a8c20SJan Friedel 		RSN_PROTOCOL_NEGOTIATE,	/* protocol version negotiation */
64657a8c20SJan Friedel 		RSN_GSS_CTX_ESTABLISH,	/* establish GSS-API context */
65657a8c20SJan Friedel 		RSN_GSS_CTX_EXP,	/* expiration of the GSS-API context */
66657a8c20SJan Friedel 		RSN_UNKNOWN_AF,		/* unknown address family */
67657a8c20SJan Friedel 		RSN_MEMORY_ALLOCATE,	/* memory allocation failure */
68657a8c20SJan Friedel 		RSN_OTHER_ERR		/* other, not classified error */
69657a8c20SJan Friedel };
70657a8c20SJan Friedel typedef enum close_rsn_e close_rsn_t;
71657a8c20SJan Friedel 
72657a8c20SJan Friedel /* linked list of remote audit hosts (servers) */
73657a8c20SJan Friedel typedef struct hostlist_s hostlist_t;
74657a8c20SJan Friedel struct hostlist_s {
75657a8c20SJan Friedel 	hostlist_t	*next_host;
76657a8c20SJan Friedel 	struct hostent	*host;
77657a8c20SJan Friedel 	in_port_t	port;		/* TCP port number */
78*bbf21555SRichard Lowe 	gss_OID		mech;		/* GSS mechanism - see mech(5) */
79657a8c20SJan Friedel };
80657a8c20SJan Friedel 
81657a8c20SJan Friedel /* transq_t - single, already sent token in the transmit queue. */
82657a8c20SJan Friedel struct transq_node_s {
83657a8c20SJan Friedel 	struct transq_node_s	*next;
84657a8c20SJan Friedel 	struct transq_node_s	*prev;
85657a8c20SJan Friedel 	gss_buffer_desc		seq_token;	/* seq num || plain token */
86657a8c20SJan Friedel 	uint64_t		seq_num;	/* seq number */
87657a8c20SJan Friedel };
88657a8c20SJan Friedel typedef struct transq_node_s transq_node_t;
89657a8c20SJan Friedel 
90657a8c20SJan Friedel /* transq_hdr_t - the transmit queue header structure */
91657a8c20SJan Friedel struct transq_hdr_s {
92657a8c20SJan Friedel 	struct transq_node_s	*head;
93657a8c20SJan Friedel 	struct transq_node_s	*end;
94657a8c20SJan Friedel 	long			count;	/* amount of nodes in the queue */
95657a8c20SJan Friedel };
96657a8c20SJan Friedel typedef struct transq_hdr_s transq_hdr_t;
97657a8c20SJan Friedel 
98657a8c20SJan Friedel /* pipe_msg_s - the notification pipe message */
99657a8c20SJan Friedel struct pipe_msg_s {
100657a8c20SJan Friedel 	int		sock_num;	/* socket fd to be poll()ed and more */
101657a8c20SJan Friedel 	boolean_t	sync;		/* call the sync routines */
102657a8c20SJan Friedel };
103657a8c20SJan Friedel typedef struct pipe_msg_s pipe_msg_t;
104657a8c20SJan Friedel 
105657a8c20SJan Friedel 
106657a8c20SJan Friedel /*
107657a8c20SJan Friedel  * Cross audit_remote plugin source code shared functions and bool parameters.
108657a8c20SJan Friedel  *
109657a8c20SJan Friedel  * reset_transport() helpers:
110657a8c20SJan Friedel  *     arg1) DO_SYNC, DO_NOT_SYNC
111657a8c20SJan Friedel  *     arg2) DO_EXIT, DO_CLOSE, DO_NOT_EXIT, DO_NOT_CLOSE
112657a8c20SJan Friedel  */
113657a8c20SJan Friedel #define	DO_SYNC		B_TRUE
114657a8c20SJan Friedel #define	DO_NOT_SYNC	B_FALSE
115657a8c20SJan Friedel #define	DO_EXIT		B_FALSE
116657a8c20SJan Friedel #define	DO_CLOSE	B_TRUE
117657a8c20SJan Friedel #define	DO_NOT_EXIT	B_CLOSE
118657a8c20SJan Friedel #define	DO_NOT_CLOSE	B_EXIT
119657a8c20SJan Friedel extern void		reset_transport(boolean_t, boolean_t);
120657a8c20SJan Friedel extern send_record_rc_t send_record(struct hostlist_s *, const char *, size_t,
121657a8c20SJan Friedel     uint64_t, close_rsn_t *);
122657a8c20SJan Friedel 
123657a8c20SJan Friedel #if DEBUG
124657a8c20SJan Friedel #define	DPRINT(x) { (void) fprintf x; (void) fflush(dfile); }
125657a8c20SJan Friedel #else
126657a8c20SJan Friedel #define	DPRINT(x)
127657a8c20SJan Friedel #endif
128657a8c20SJan Friedel 
129657a8c20SJan Friedel #if DEBUG
130657a8c20SJan Friedel extern FILE	*dfile;
131657a8c20SJan Friedel #endif
132657a8c20SJan Friedel 
133657a8c20SJan Friedel 
134657a8c20SJan Friedel #ifdef __cplusplus
135657a8c20SJan Friedel }
136657a8c20SJan Friedel #endif
137657a8c20SJan Friedel 
138657a8c20SJan Friedel #endif	/* _AUDIT_REMOTE_H */
139