xref: /illumos-gate/usr/src/lib/libbsm/common/audit_rexecd.c (revision f89940742f5d14dde79b69b98a414dd7b7f585c7)
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
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * 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*f8994074SJan Friedel  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #include <sys/types.h>
267c478bd9Sstevel@tonic-gate #include <stdio.h>
277c478bd9Sstevel@tonic-gate #include <unistd.h>
287c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
297c478bd9Sstevel@tonic-gate #include <bsm/audit.h>
307c478bd9Sstevel@tonic-gate #include <bsm/audit_record.h>
317c478bd9Sstevel@tonic-gate #include <bsm/audit_uevents.h>
327c478bd9Sstevel@tonic-gate #include <bsm/libbsm.h>
337c478bd9Sstevel@tonic-gate #include <bsm/audit_private.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <syslog.h>
377c478bd9Sstevel@tonic-gate #include <pwd.h>
387c478bd9Sstevel@tonic-gate #include <netinet/in.h>
3945916cd2Sjpk #include <tsol/label.h>
407c478bd9Sstevel@tonic-gate #include <locale.h>
417c478bd9Sstevel@tonic-gate #include "generic.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #ifdef C2_DEBUG
44dfc7be02SJan Friedel #define	dprintf(x) { (void) printf x; }
457c478bd9Sstevel@tonic-gate #else
467c478bd9Sstevel@tonic-gate #define	dprintf(x)
477c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static au_event_t	event;
507c478bd9Sstevel@tonic-gate static int		audit_rexecd_status = 0;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static int
537c478bd9Sstevel@tonic-gate selected(uid, user, event, sf)
547c478bd9Sstevel@tonic-gate uid_t uid;
557c478bd9Sstevel@tonic-gate char	*user;
567c478bd9Sstevel@tonic-gate au_event_t	event;
577c478bd9Sstevel@tonic-gate int	sf;
587c478bd9Sstevel@tonic-gate {
59*f8994074SJan Friedel 	int		sorf;
60*f8994074SJan Friedel 	struct au_mask	mask;
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	mask.am_success = mask.am_failure = 0;
63f48205beScasper 	if (uid > MAXEPHUID) {
64*f8994074SJan Friedel 		/* get non-attrib flags */
65*f8994074SJan Friedel 		(void) auditon(A_GETKMASK, (caddr_t)&mask, sizeof (mask));
667c478bd9Sstevel@tonic-gate 	} else {
67*f8994074SJan Friedel 		(void) au_user_mask(user, &mask);
687c478bd9Sstevel@tonic-gate 	}
697c478bd9Sstevel@tonic-gate 
70*f8994074SJan Friedel 	if (sf == 0) {
717c478bd9Sstevel@tonic-gate 		sorf = AU_PRS_SUCCESS;
72*f8994074SJan Friedel 	} else if (sf == -1) {
737c478bd9Sstevel@tonic-gate 		sorf = AU_PRS_FAILURE;
74*f8994074SJan Friedel 	} else {
757c478bd9Sstevel@tonic-gate 		sorf = AU_PRS_BOTH;
76*f8994074SJan Friedel 	}
77*f8994074SJan Friedel 
78*f8994074SJan Friedel 	return (au_preselect(event, &mask, sorf, AU_PRS_REREAD));
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate void
827c478bd9Sstevel@tonic-gate audit_rexecd_setup()
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate 	dprintf(("audit_rexecd_setup()\n"));
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	event = AUE_rexecd;
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate static void
917c478bd9Sstevel@tonic-gate audit_rexecd_session_setup(char *name, char *mach, uid_t uid)
927c478bd9Sstevel@tonic-gate {
937c478bd9Sstevel@tonic-gate 	int			rc;
947c478bd9Sstevel@tonic-gate 	au_mask_t		mask;
957c478bd9Sstevel@tonic-gate 	struct auditinfo_addr	info;
967c478bd9Sstevel@tonic-gate 	uint32_t addr[4], type;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	info.ai_auid = uid;
997c478bd9Sstevel@tonic-gate 	info.ai_asid = getpid();
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	mask.am_success = 0;
1027c478bd9Sstevel@tonic-gate 	mask.am_failure = 0;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	(void) au_user_mask(name, &mask);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	info.ai_mask.am_success  = mask.am_success;
1077c478bd9Sstevel@tonic-gate 	info.ai_mask.am_failure  = mask.am_failure;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	rc = aug_get_machine(mach, addr, &type);
1107c478bd9Sstevel@tonic-gate 	if (rc < 0) {
1117c478bd9Sstevel@tonic-gate 		perror("get address");
1127c478bd9Sstevel@tonic-gate 	}
1137c478bd9Sstevel@tonic-gate 	info.ai_termid.at_port = aug_get_port();
1147c478bd9Sstevel@tonic-gate 	info.ai_termid.at_type    = type;
1157c478bd9Sstevel@tonic-gate 	info.ai_termid.at_addr[0] = addr[0];
1167c478bd9Sstevel@tonic-gate 	info.ai_termid.at_addr[1] = addr[1];
1177c478bd9Sstevel@tonic-gate 	info.ai_termid.at_addr[2] = addr[2];
1187c478bd9Sstevel@tonic-gate 	info.ai_termid.at_addr[3] = addr[3];
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	rc = setaudit_addr(&info, sizeof (info));
1217c478bd9Sstevel@tonic-gate 	if (rc < 0) {
1227c478bd9Sstevel@tonic-gate 		perror("setaudit");
1237c478bd9Sstevel@tonic-gate 	}
1247c478bd9Sstevel@tonic-gate }
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate void
1277c478bd9Sstevel@tonic-gate audit_rexecd_fail(msg, hostname, user, cmdbuf)
1287c478bd9Sstevel@tonic-gate char	*msg;		/* message containing failure information */
1297c478bd9Sstevel@tonic-gate char	*hostname;	/* hostname of machine requesting service */
1307c478bd9Sstevel@tonic-gate char	*user;		/* username of user requesting service */
1317c478bd9Sstevel@tonic-gate char	*cmdbuf;	/* command line to be executed locally */
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	int	rd;		/* audit record descriptor */
1347c478bd9Sstevel@tonic-gate 	char	buf[256];	/* temporary buffer */
1357c478bd9Sstevel@tonic-gate 	char	*tbuf;		/* temporary buffer */
1367c478bd9Sstevel@tonic-gate 	int	tlen;
1377c478bd9Sstevel@tonic-gate 	const char *gtxt;
1387c478bd9Sstevel@tonic-gate 	uid_t 	uid;
1397c478bd9Sstevel@tonic-gate 	gid_t	gid;
1407c478bd9Sstevel@tonic-gate 	pid_t	pid;
1417c478bd9Sstevel@tonic-gate 	au_tid_addr_t	tid;
1427c478bd9Sstevel@tonic-gate 	struct passwd	*pwd;
1437c478bd9Sstevel@tonic-gate 	uint32_t addr[4], type;
1447c478bd9Sstevel@tonic-gate 	int rc;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	dprintf(("audit_rexecd_fail()\n"));
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	/*
1497c478bd9Sstevel@tonic-gate 	 * check if audit_rexecd_fail() or audit_rexecd_success()
1507c478bd9Sstevel@tonic-gate 	 * have been called already.
1517c478bd9Sstevel@tonic-gate 	 */
1527c478bd9Sstevel@tonic-gate 	if (audit_rexecd_status == 1) {
1537c478bd9Sstevel@tonic-gate 		return;
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	if (cannot_audit(0)) {
1577c478bd9Sstevel@tonic-gate 		return;
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	/*
1617c478bd9Sstevel@tonic-gate 	 * set status to prevent multiple calls
1627c478bd9Sstevel@tonic-gate 	 * to audit_rexecd_fail() and audit_rexecd_success()
1637c478bd9Sstevel@tonic-gate 	 */
1647c478bd9Sstevel@tonic-gate 	audit_rexecd_status = 1;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	pwd = getpwnam(user);
1677c478bd9Sstevel@tonic-gate 	if (pwd == NULL) {
168f48205beScasper 		uid = (uid_t)-1;
169f48205beScasper 		gid = (gid_t)-1;
1707c478bd9Sstevel@tonic-gate 	} else {
1717c478bd9Sstevel@tonic-gate 		uid = pwd->pw_uid;
1727c478bd9Sstevel@tonic-gate 		gid = pwd->pw_gid;
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* determine if we're preselected */
1767c478bd9Sstevel@tonic-gate 	if (!selected(uid, user, event, -1))
1777c478bd9Sstevel@tonic-gate 		return;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	pid = getpid();
1807c478bd9Sstevel@tonic-gate 	rc = aug_get_machine(hostname, addr, &type);
1817c478bd9Sstevel@tonic-gate 	if (rc < 0) {
1827c478bd9Sstevel@tonic-gate 		perror("get address");
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	tid.at_port    = aug_get_port();
1867c478bd9Sstevel@tonic-gate 	tid.at_addr[0] = addr[0];
1877c478bd9Sstevel@tonic-gate 	tid.at_addr[1] = addr[1];
1887c478bd9Sstevel@tonic-gate 	tid.at_addr[2] = addr[2];
1897c478bd9Sstevel@tonic-gate 	tid.at_addr[3] = addr[3];
1907c478bd9Sstevel@tonic-gate 	tid.at_type    = type;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 	rd = au_open();
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/* add subject token */
1957c478bd9Sstevel@tonic-gate 	(void) au_write(rd,
1967c478bd9Sstevel@tonic-gate 		au_to_subject_ex(uid, uid, gid, uid, gid, pid, pid, &tid));
19745916cd2Sjpk 	if (is_system_labeled())
19845916cd2Sjpk 		(void) au_write(rd, au_to_mylabel());
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	/* add reason for failure */
2017c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(msg));
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	/* add hostname of machine requesting service */
2047c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), dgettext(bsm_dom,
2057c478bd9Sstevel@tonic-gate 		"Remote execution requested by: %s"), hostname);
2067c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(buf));
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	/* add username of user requesting service */
2097c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), dgettext(bsm_dom,
2107c478bd9Sstevel@tonic-gate 		"Username: %s"), user);
2117c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(buf));
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate 	/* add command line to be executed locally */
2147c478bd9Sstevel@tonic-gate 	gtxt = dgettext(bsm_dom, "Command line: %s");
2157c478bd9Sstevel@tonic-gate 	tlen = strlen(gtxt) + strlen(cmdbuf) + 1;
2167c478bd9Sstevel@tonic-gate 	if ((tbuf = malloc(tlen)) == NULL) {
2177c478bd9Sstevel@tonic-gate 		(void) au_close(rd, 0, 0);
2187c478bd9Sstevel@tonic-gate 		return;
2197c478bd9Sstevel@tonic-gate 	}
2207c478bd9Sstevel@tonic-gate 	(void) snprintf(tbuf, tlen, gtxt, cmdbuf);
2217c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(tbuf));
2227c478bd9Sstevel@tonic-gate 	(void) free(tbuf);
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	/* add return token */
2257c478bd9Sstevel@tonic-gate #ifdef _LP64
2267c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_return64(-1, (int64_t)0));
2277c478bd9Sstevel@tonic-gate #else
2287c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_return32(-1, (int32_t)0));
2297c478bd9Sstevel@tonic-gate #endif
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	/* write audit record */
2327c478bd9Sstevel@tonic-gate 	if (au_close(rd, 1, event) < 0) {
2337c478bd9Sstevel@tonic-gate 		(void) au_close(rd, 0, 0);
2347c478bd9Sstevel@tonic-gate 		return;
2357c478bd9Sstevel@tonic-gate 	}
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate void
2397c478bd9Sstevel@tonic-gate audit_rexecd_success(hostname, user, cmdbuf)
2407c478bd9Sstevel@tonic-gate char	*hostname;	/* hostname of machine requesting service */
2417c478bd9Sstevel@tonic-gate char	*user;		/* username of user requesting service */
2427c478bd9Sstevel@tonic-gate char	*cmdbuf;	/* command line to be executed locally */
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate 	int	rd;		/* audit record descriptor */
2457c478bd9Sstevel@tonic-gate 	char	buf[256];	/* temporary buffer */
2467c478bd9Sstevel@tonic-gate 	char	*tbuf;		/* temporary buffer */
2477c478bd9Sstevel@tonic-gate 	int	tlen;
2487c478bd9Sstevel@tonic-gate 	const char *gtxt;
2497c478bd9Sstevel@tonic-gate 	uid_t 	uid;
2507c478bd9Sstevel@tonic-gate 	gid_t	gid;
2517c478bd9Sstevel@tonic-gate 	pid_t	pid;
2527c478bd9Sstevel@tonic-gate 	au_tid_addr_t	tid;
2537c478bd9Sstevel@tonic-gate 	struct passwd	*pwd;
2547c478bd9Sstevel@tonic-gate 	uint32_t addr[4], type;
2557c478bd9Sstevel@tonic-gate 	int rc;
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	dprintf(("audit_rexecd_success()\n"));
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/*
2607c478bd9Sstevel@tonic-gate 	 * check if audit_rexecd_fail() or audit_rexecd_success()
2617c478bd9Sstevel@tonic-gate 	 * have been called already.
2627c478bd9Sstevel@tonic-gate 	 */
2637c478bd9Sstevel@tonic-gate 	if (audit_rexecd_status == 1) {
2647c478bd9Sstevel@tonic-gate 		return;
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	if (cannot_audit(0)) {
2687c478bd9Sstevel@tonic-gate 		return;
2697c478bd9Sstevel@tonic-gate 	}
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	/*
2727c478bd9Sstevel@tonic-gate 	 * set status to prevent multiple calls
2737c478bd9Sstevel@tonic-gate 	 * to audit_rexecd_fail() and audit_rexecd_success()
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	audit_rexecd_status = 1;
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	pwd = getpwnam(user);
2787c478bd9Sstevel@tonic-gate 	if (pwd == NULL) {
279f48205beScasper 		uid = (uid_t)-1;
280f48205beScasper 		gid = (gid_t)-1;
2817c478bd9Sstevel@tonic-gate 	} else {
2827c478bd9Sstevel@tonic-gate 		uid = pwd->pw_uid;
2837c478bd9Sstevel@tonic-gate 		gid = pwd->pw_gid;
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	/* determine if we're preselected */
2877c478bd9Sstevel@tonic-gate 	if (!selected(uid, user, event, 0))
2887c478bd9Sstevel@tonic-gate 		goto rexecd_audit_session;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	pid = getpid();
2917c478bd9Sstevel@tonic-gate 	rc = aug_get_machine(hostname, addr, &type);
2927c478bd9Sstevel@tonic-gate 	if (rc < 0) {
2937c478bd9Sstevel@tonic-gate 		perror("get address");
2947c478bd9Sstevel@tonic-gate 	}
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	tid.at_port    = aug_get_port();
2977c478bd9Sstevel@tonic-gate 	tid.at_addr[0] = addr[0];
2987c478bd9Sstevel@tonic-gate 	tid.at_addr[1] = addr[1];
2997c478bd9Sstevel@tonic-gate 	tid.at_addr[2] = addr[2];
3007c478bd9Sstevel@tonic-gate 	tid.at_addr[3] = addr[3];
3017c478bd9Sstevel@tonic-gate 	tid.at_type    = type;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	rd = au_open();
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	/* add subject token */
3067c478bd9Sstevel@tonic-gate 	(void) au_write(rd,
3077c478bd9Sstevel@tonic-gate 		au_to_subject_ex(uid, uid, gid, uid, gid, pid, pid, &tid));
30845916cd2Sjpk 	if (is_system_labeled())
30945916cd2Sjpk 		(void) au_write(rd, au_to_mylabel());
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	/* add hostname of machine requesting service */
3127c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), dgettext(bsm_dom,
3137c478bd9Sstevel@tonic-gate 		"Remote execution requested by: %s"), hostname);
3147c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(buf));
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	/* add username at machine requesting service */
3177c478bd9Sstevel@tonic-gate 	(void) snprintf(buf, sizeof (buf), dgettext(bsm_dom,
3187c478bd9Sstevel@tonic-gate 	    "Username: %s"), user);
3197c478bd9Sstevel@tonic-gate 	(void) au_write(rd, au_to_text(buf));
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	/* add command line to be executed locally */
3227c478bd9Sstevel@tonic-gate 	gtxt = dgettext(bsm_dom, "Command line: %s");
3237c478bd9Sstevel@tonic-gate 	tlen = strlen(gtxt) + strlen(cmdbuf) + 1;
3247c478bd9Sstevel@tonic-gate 	if ((tbuf = malloc(tlen)) == NULL) {
3257c478bd9Sstevel@tonic-gate 		(void) au_close(rd, 0, 0);
3267c478bd9Sstevel@tonic-gate 	} else {
3277c478bd9Sstevel@tonic-gate 		(void) snprintf(tbuf, tlen, gtxt, cmdbuf);
3287c478bd9Sstevel@tonic-gate 		(void) au_write(rd, au_to_text(tbuf));
3297c478bd9Sstevel@tonic-gate 		(void) free(tbuf);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 		/* add return token */
3327c478bd9Sstevel@tonic-gate #ifdef _LP64
3337c478bd9Sstevel@tonic-gate 		(void) au_write(rd, au_to_return64(0, (int64_t)0));
3347c478bd9Sstevel@tonic-gate #else
3357c478bd9Sstevel@tonic-gate 		(void) au_write(rd, au_to_return32(0, (int32_t)0));
3367c478bd9Sstevel@tonic-gate #endif
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 		/* write audit record */
3397c478bd9Sstevel@tonic-gate 		if (au_close(rd, 1, event) < 0) {
3407c478bd9Sstevel@tonic-gate 			(void) au_close(rd, 0, 0);
3417c478bd9Sstevel@tonic-gate 		}
3427c478bd9Sstevel@tonic-gate 	}
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate rexecd_audit_session:
3457c478bd9Sstevel@tonic-gate 	audit_rexecd_session_setup(user, hostname, uid);
3467c478bd9Sstevel@tonic-gate }
347