4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/socket.h>
29 #include <netinet/in.h>
31 #include <sys/socket.h>
33 #include <bsm/audit.h>
34 #include <bsm/libbsm.h>
35 #include <bsm/audit_private.h>
38 static int do_ipv6_address(struct sockaddr_in6
*, struct sockaddr_in6
*);
39 static int do_ipv4_address(struct sockaddr_in
*, struct sockaddr_in
*);
44 struct sockaddr_in6 peer
;
45 struct sockaddr_in6 sock
;
46 int peerlen
= sizeof (peer
);
47 int socklen
= sizeof (sock
);
50 if (cannot_audit(0)) {
55 if (getpeername(fd
, (struct sockaddr
*)&peer
, (socklen_t
*)&peerlen
)
61 if (getsockname(fd
, (struct sockaddr
*)&sock
, (socklen_t
*)&socklen
)
66 if (peer
.sin6_family
== AF_INET6
)
67 rv
= do_ipv6_address(&peer
, &sock
);
69 rv
= do_ipv4_address((struct sockaddr_in
*)&peer
,
70 (struct sockaddr_in
*)&sock
);
76 do_ipv6_address(struct sockaddr_in6
*peer
, struct sockaddr_in6
*sock
)
80 /* get audit characteristics of process */
81 if (getaudit_addr(&ai
, sizeof (ai
)) < 0) {
86 * if terminal ID already set, i.e. non-zero, then just return
88 if (ai
.ai_termid
.at_port
||
89 ai
.ai_termid
.at_addr
[0] ||
90 ai
.ai_termid
.at_addr
[1] ||
91 ai
.ai_termid
.at_addr
[2] ||
92 ai
.ai_termid
.at_addr
[3]) {
96 ai
.ai_termid
.at_port
= ((peer
->sin6_port
<<16) | (sock
->sin6_port
));
97 ai
.ai_termid
.at_type
= AU_IPv6
;
98 bcopy(&peer
->sin6_addr
, ai
.ai_termid
.at_addr
, 16);
100 if (setaudit_addr(&ai
, sizeof (ai
)) < 0) {
108 do_ipv4_address(struct sockaddr_in
*peer
, struct sockaddr_in
*sock
)
112 /* get audit characteristics of process */
113 if (getaudit(&ai
) < 0) {
118 * if terminal ID already set, i.e. non-zero, then just return
120 if (ai
.ai_termid
.port
|| ai
.ai_termid
.machine
) {
124 ai
.ai_termid
.port
= (peer
->sin_port
<<16 | sock
->sin_port
);
125 ai
.ai_termid
.machine
= (uint32_t)peer
->sin_addr
.s_addr
;
127 if (setaudit(&ai
) < 0) {