10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*11706SJan.Friedel@Sun.COM * Common Development and Distribution License (the "License").
6*11706SJan.Friedel@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*11706SJan.Friedel@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23*11706SJan.Friedel@Sun.COM * Use is subject to license terms.
24*11706SJan.Friedel@Sun.COM *
250Sstevel@tonic-gate */
260Sstevel@tonic-gate #include <sys/types.h>
270Sstevel@tonic-gate #include <sys/param.h>
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <sys/fcntl.h>
300Sstevel@tonic-gate #include <bsm/audit.h>
310Sstevel@tonic-gate #include <bsm/audit_record.h>
320Sstevel@tonic-gate #include <bsm/audit_uevents.h>
330Sstevel@tonic-gate #include <bsm/libbsm.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <syslog.h>
370Sstevel@tonic-gate #include <netinet/in.h>
380Sstevel@tonic-gate #include <sys/socket.h>
390Sstevel@tonic-gate #include <rpc/rpc.h>
400Sstevel@tonic-gate #include <tiuser.h>
410Sstevel@tonic-gate #include <unistd.h>
420Sstevel@tonic-gate #include <generic.h>
430Sstevel@tonic-gate #include <note.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate #ifdef C2_DEBUG2
46*11706SJan.Friedel@Sun.COM #define dprintf(x) { (void) printf x; }
470Sstevel@tonic-gate #else
480Sstevel@tonic-gate #define dprintf(x)
490Sstevel@tonic-gate #endif
500Sstevel@tonic-gate
510Sstevel@tonic-gate /*
520Sstevel@tonic-gate * netbuf2pm()
530Sstevel@tonic-gate *
540Sstevel@tonic-gate * Given an endpt in netbuf form, return the port and machine.
550Sstevel@tonic-gate * kadmind (currently) only works over IPv4, so only handle IPv4 addresses.
560Sstevel@tonic-gate */
570Sstevel@tonic-gate static void
netbuf2pm(struct netbuf * addr,in_port_t * port,uint32_t * machine)580Sstevel@tonic-gate netbuf2pm(
590Sstevel@tonic-gate struct netbuf *addr,
600Sstevel@tonic-gate in_port_t *port,
610Sstevel@tonic-gate uint32_t *machine)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate struct sockaddr_in sin4;
640Sstevel@tonic-gate
650Sstevel@tonic-gate if (!addr) {
660Sstevel@tonic-gate syslog(LOG_DEBUG, "netbuf2pm: addr == NULL");
670Sstevel@tonic-gate return;
680Sstevel@tonic-gate }
690Sstevel@tonic-gate
700Sstevel@tonic-gate if (!addr->buf) {
710Sstevel@tonic-gate syslog(LOG_DEBUG, "netbuf2pm: addr->buf == NULL");
720Sstevel@tonic-gate return;
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate (void) memcpy(&sin4, addr->buf, sizeof (struct sockaddr_in));
760Sstevel@tonic-gate if (sin4.sin_family == AF_INET) {
770Sstevel@tonic-gate if (machine)
780Sstevel@tonic-gate *machine = sin4.sin_addr.s_addr;
790Sstevel@tonic-gate if (port)
800Sstevel@tonic-gate *port = sin4.sin_port;
810Sstevel@tonic-gate } else {
820Sstevel@tonic-gate dprintf(("netbuf2pm: unknown caller IP address family %d",
83*11706SJan.Friedel@Sun.COM sin4.sin_family));
840Sstevel@tonic-gate syslog(LOG_DEBUG,
850Sstevel@tonic-gate "netbuf2pm: unknown caller IP address family %d",
860Sstevel@tonic-gate sin4.sin_family);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate #define AUD_NULL_STR(s) ((s) ? (s) : "(null)")
910Sstevel@tonic-gate
920Sstevel@tonic-gate static void
common_audit(au_event_t event,SVCXPRT * xprt,in_port_t l_port,char * op,char * prime_arg,char * clnt_name,int sorf)930Sstevel@tonic-gate common_audit(
940Sstevel@tonic-gate au_event_t event, /* audit event */
950Sstevel@tonic-gate SVCXPRT *xprt, /* net transport handle */
960Sstevel@tonic-gate in_port_t l_port, /* local port */
970Sstevel@tonic-gate char *op, /* requested operation */
980Sstevel@tonic-gate char *prime_arg, /* argument for op */
990Sstevel@tonic-gate char *clnt_name, /* client principal name */
1000Sstevel@tonic-gate int sorf) /* flag for success or failure */
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate auditinfo_t ai;
1040Sstevel@tonic-gate in_port_t r_port = 0;
1050Sstevel@tonic-gate dev_t port;
1060Sstevel@tonic-gate uint32_t machine = 0;
1070Sstevel@tonic-gate char text_buf[512];
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate dprintf(("common_audit() start\n"));
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate /* if auditing turned off, then don't do anything */
1120Sstevel@tonic-gate if (cannot_audit(0))
1130Sstevel@tonic-gate return;
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate (void) aug_save_namask();
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate * set default values. We will overwrite them if appropriate.
1190Sstevel@tonic-gate */
1200Sstevel@tonic-gate if (getaudit(&ai)) {
1210Sstevel@tonic-gate perror("kadmind");
1220Sstevel@tonic-gate return;
1230Sstevel@tonic-gate }
1240Sstevel@tonic-gate aug_save_auid(ai.ai_auid); /* Audit ID */
1250Sstevel@tonic-gate aug_save_uid(getuid()); /* User ID */
1260Sstevel@tonic-gate aug_save_euid(geteuid()); /* Effective User ID */
1270Sstevel@tonic-gate aug_save_gid(getgid()); /* Group ID */
1280Sstevel@tonic-gate aug_save_egid(getegid()); /* Effective Group ID */
1290Sstevel@tonic-gate aug_save_pid(getpid()); /* process ID */
1300Sstevel@tonic-gate aug_save_asid(getpid()); /* session ID */
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate aug_save_event(event);
1330Sstevel@tonic-gate aug_save_sorf(sorf);
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate (void) snprintf(text_buf, sizeof (text_buf), "Op: %s",
1360Sstevel@tonic-gate AUD_NULL_STR(op));
1370Sstevel@tonic-gate aug_save_text(text_buf);
1380Sstevel@tonic-gate (void) snprintf(text_buf, sizeof (text_buf), "Arg: %s",
1390Sstevel@tonic-gate AUD_NULL_STR(prime_arg));
1400Sstevel@tonic-gate aug_save_text1(text_buf);
1410Sstevel@tonic-gate (void) snprintf(text_buf, sizeof (text_buf), "Client: %s",
1420Sstevel@tonic-gate AUD_NULL_STR(clnt_name));
1430Sstevel@tonic-gate aug_save_text2(text_buf);
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate netbuf2pm(svc_getrpccaller(xprt), &r_port, &machine);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate dprintf(("common_audit(): l_port=%d, r_port=%d,\n",
1480Sstevel@tonic-gate ntohs(l_port), ntohs(r_port)));
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate port = (r_port<<16 | l_port);
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate aug_save_tid_ex(port, &machine, AU_IPv4);
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate (void) aug_audit();
1550Sstevel@tonic-gate }
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate void
audit_kadmind_auth(SVCXPRT * xprt,in_port_t l_port,char * op,char * prime_arg,char * clnt_name,int sorf)1580Sstevel@tonic-gate audit_kadmind_auth(
1590Sstevel@tonic-gate SVCXPRT *xprt,
1600Sstevel@tonic-gate in_port_t l_port,
1610Sstevel@tonic-gate char *op,
1620Sstevel@tonic-gate char *prime_arg,
1630Sstevel@tonic-gate char *clnt_name,
1640Sstevel@tonic-gate int sorf)
1650Sstevel@tonic-gate {
1660Sstevel@tonic-gate common_audit(AUE_kadmind_auth, xprt, l_port, op, prime_arg,
167*11706SJan.Friedel@Sun.COM clnt_name, sorf);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate void
audit_kadmind_unauth(SVCXPRT * xprt,in_port_t l_port,char * op,char * prime_arg,char * clnt_name)1710Sstevel@tonic-gate audit_kadmind_unauth(
1720Sstevel@tonic-gate SVCXPRT *xprt,
1730Sstevel@tonic-gate in_port_t l_port,
1740Sstevel@tonic-gate char *op,
1750Sstevel@tonic-gate char *prime_arg,
1760Sstevel@tonic-gate char *clnt_name)
1770Sstevel@tonic-gate {
1780Sstevel@tonic-gate common_audit(AUE_kadmind_unauth, xprt, l_port, op, prime_arg,
179*11706SJan.Friedel@Sun.COM clnt_name, 1);
1800Sstevel@tonic-gate }
181