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