4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Support routines for building audit records.
30 #include <sys/param.h>
31 #include <sys/systm.h> /* for rval */
33 #include <sys/types.h>
34 #include <sys/vnode.h>
37 #include <sys/session.h>
39 #include <sys/ipc_impl.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/in.h>
42 #include <netinet/ip.h>
43 #include <sys/socket.h>
44 #include <net/route.h>
45 #include <netinet/in_pcb.h>
47 #include <c2/audit_kernel.h>
48 #include <c2/audit_record.h>
49 #include <sys/model.h> /* for model_t */
50 #include <sys/vmparam.h> /* for USRSTACK/USRSTACK32 */
51 #include <sys/vfs.h> /* for sonode */
52 #include <sys/socketvar.h> /* for sonode */
56 * These are the control tokens
62 * pointer to au_membuf chain containing a header token.
65 au_to_header(int byte_count
, au_event_t e_type
, au_emod_t e_mod
)
67 adr_t adr
; /* adr memory stream header */
68 token_t
*m
; /* au_membuf pointer */
70 char data_header
= AUT_HEADER64
; /* header for this token */
71 static int64_t zerotime
[2];
73 char data_header
= AUT_HEADER32
;
74 static int32_t zerotime
[2];
76 char version
= TOKEN_VERSION
; /* version of token family */
80 adr_start(&adr
, memtod(m
, char *));
81 adr_char(&adr
, &data_header
, 1); /* token ID */
82 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
84 adr_char(&adr
, &version
, 1); /* version of audit tokens */
85 adr_ushort(&adr
, &e_type
, 1); /* event ID */
86 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
88 adr_int64(&adr
, zerotime
, 2); /* time & date space */
90 adr_int32(&adr
, zerotime
, 2);
92 m
->len
= adr_count(&adr
);
98 au_to_header_ex(int byte_count
, au_event_t e_type
, au_emod_t e_mod
)
100 adr_t adr
; /* adr memory stream header */
101 token_t
*m
; /* au_membuf pointer */
102 au_kcontext_t
*kctx
= GET_KCTX_PZ
;
105 char data_header
= AUT_HEADER64_EX
; /* header for this token */
106 static int64_t zerotime
[2];
108 char data_header
= AUT_HEADER32_EX
;
109 static int32_t zerotime
[2];
111 char version
= TOKEN_VERSION
; /* version of token family */
115 adr_start(&adr
, memtod(m
, char *));
116 adr_char(&adr
, &data_header
, 1); /* token ID */
117 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
119 adr_char(&adr
, &version
, 1); /* version of audit tokens */
120 adr_ushort(&adr
, &e_type
, 1); /* event ID */
121 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
122 adr_uint32(&adr
, &kctx
->auk_info
.ai_termid
.at_type
, 1);
123 adr_char(&adr
, (char *)&kctx
->auk_info
.ai_termid
.at_addr
[0],
124 (int)kctx
->auk_info
.ai_termid
.at_type
);
126 adr_int64(&adr
, zerotime
, 2); /* time & date */
128 adr_int32(&adr
, zerotime
, 2);
130 m
->len
= adr_count(&adr
);
138 * pointer to au_membuf chain containing a trailer token.
141 au_to_trailer(int byte_count
)
143 adr_t adr
; /* adr memory stream header */
144 token_t
*m
; /* au_membuf pointer */
145 char data_header
= AUT_TRAILER
; /* header for this token */
146 short magic
= (short)AUT_TRAILER_MAGIC
; /* trailer magic number */
150 adr_start(&adr
, memtod(m
, char *));
151 adr_char(&adr
, &data_header
, 1); /* token ID */
152 adr_short(&adr
, &magic
, 1); /* magic number */
153 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
156 m
->len
= adr_count(&adr
);
161 * These are the data tokens
167 * pointer to au_membuf chain containing a data token.
170 au_to_data(char unit_print
, char unit_type
, char unit_count
, char *p
)
172 adr_t adr
; /* adr memory stream header */
173 token_t
*m
; /* au_membuf pointer */
174 char data_header
= AUT_DATA
; /* header for this token */
177 ASSERT(unit_count
!= 0);
181 if (sizeof (short) * unit_count
>= AU_BUFSIZE
)
182 return (au_to_text("au_to_data: unit count too big"));
185 if (sizeof (int32_t) * unit_count
>= AU_BUFSIZE
)
186 return (au_to_text("au_to_data: unit count too big"));
189 if (sizeof (int64_t) * unit_count
>= AU_BUFSIZE
)
190 return (au_to_text("au_to_data: unit count too big"));
194 #ifdef _CHAR_IS_UNSIGNED
195 if (sizeof (char) * unit_count
>= AU_BUFSIZE
)
196 return (au_to_text("au_to_data: unit count too big"));
199 * we used to check for this:
200 * sizeof (char) * (int)unit_count >= AU_BUFSIZE).
201 * but the compiler is smart enough to see that
202 * will never be >= AU_BUFSIZE, since that's 128
203 * and unit_count maxes out at 127 (signed char),
211 adr_start(&adr
, memtod(m
, char *));
212 adr_char(&adr
, &data_header
, 1);
213 adr_char(&adr
, &unit_print
, 1);
214 adr_char(&adr
, &unit_type
, 1);
215 adr_char(&adr
, &unit_count
, 1);
219 adr_short(&adr
, (short *)p
, unit_count
);
222 adr_int32(&adr
, (int32_t *)p
, unit_count
);
225 adr_int64(&adr
, (int64_t *)p
, unit_count
);
229 adr_char(&adr
, p
, unit_count
);
233 m
->len
= adr_count(&adr
);
242 * pointer to au_membuf chain containing a process token.
244 static token_t
*au_to_any_process(char, uid_t
, gid_t
, uid_t
, gid_t
,
245 pid_t
, au_id_t
, au_asid_t
, const au_tid_addr_t
*atid
);
248 au_to_process(uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
249 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
254 if (atid
->at_type
== AU_IPv6
)
255 data_header
= AUT_PROCESS64_EX
;
257 data_header
= AUT_PROCESS64
;
259 if (atid
->at_type
== AU_IPv6
)
260 data_header
= AUT_PROCESS32_EX
;
262 data_header
= AUT_PROCESS32
;
265 return (au_to_any_process(data_header
, uid
, gid
, ruid
,
266 rgid
, pid
, auid
, asid
, atid
));
270 au_to_subject(uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
271 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
276 if (atid
->at_type
== AU_IPv6
)
277 data_header
= AUT_SUBJECT64_EX
;
279 data_header
= AUT_SUBJECT64
;
281 if (atid
->at_type
== AU_IPv6
)
282 data_header
= AUT_SUBJECT32_EX
;
284 data_header
= AUT_SUBJECT32
;
286 return (au_to_any_process(data_header
, uid
, gid
, ruid
,
287 rgid
, pid
, auid
, asid
, atid
));
292 au_to_any_process(char data_header
,
293 uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
294 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
296 token_t
*m
; /* local au_membuf */
297 adr_t adr
; /* adr memory stream header */
302 adr_start(&adr
, memtod(m
, char *));
303 adr_char(&adr
, &data_header
, 1);
304 value
= (int32_t)auid
;
305 adr_int32(&adr
, &value
, 1);
306 value
= (int32_t)uid
;
307 adr_int32(&adr
, &value
, 1);
308 value
= (int32_t)gid
;
309 adr_int32(&adr
, &value
, 1);
310 value
= (int32_t)ruid
;
311 adr_int32(&adr
, &value
, 1);
312 value
= (int32_t)rgid
;
313 adr_int32(&adr
, &value
, 1);
314 value
= (int32_t)pid
;
315 adr_int32(&adr
, &value
, 1);
316 value
= (int32_t)asid
;
317 adr_int32(&adr
, &value
, 1);
319 adr_int64(&adr
, (int64_t *)&(atid
->at_port
), 1);
321 adr_int32(&adr
, (int32_t *)&(atid
->at_port
), 1);
323 if (atid
->at_type
== AU_IPv6
) {
324 adr_uint32(&adr
, (uint_t
*)&atid
->at_type
, 1);
325 adr_char(&adr
, (char *)&atid
->at_addr
[0], 16);
327 adr_char(&adr
, (char *)&(atid
->at_addr
[0]), 4);
330 m
->len
= adr_count(&adr
);
338 * pointer to au_membuf chain containing a text token.
341 au_to_text(const char *text
)
343 token_t
*token
; /* local au_membuf */
344 adr_t adr
; /* adr memory stream header */
345 char data_header
= AUT_TEXT
; /* header for this token */
346 short bytes
; /* length of string */
350 bytes
= (short)strlen(text
) + 1;
351 adr_start(&adr
, memtod(token
, char *));
352 adr_char(&adr
, &data_header
, 1);
353 adr_short(&adr
, &bytes
, 1);
355 token
->len
= (char)adr_count(&adr
);
357 * Now attach the text
359 (void) au_append_buf(text
, bytes
, token
);
367 * - length of zonename token to be generated
368 * - zone name up to ZONENAME_MAX + 1 in length
370 #define ZONE_TOKEN_OVERHEAD 3
374 * string length (2 bytes)
375 * the string (strlen(zonename) + 1)
378 au_zonename_length(zone_t
*zone
)
381 zone
= curproc
->p_zone
;
382 return (strlen(zone
->zone_name
) + 1 +
383 ZONE_TOKEN_OVERHEAD
);
389 * A length of zero input to au_to_zonename means the length is not
392 * The caller is responsible for checking the AUDIT_ZONENAME policy
393 * before calling au_zonename_length() and au_to_zonename(). If
394 * the policy changes between the calls, no harm is done, so the
395 * policy only needs to be checked once.
398 * pointer to au_membuf chain containing a zonename token; NULL if
401 * if the zonename token is generated at token generation close time,
402 * the length of the token is already known and it is ASSERTed that
403 * it has not changed. If not precalculated, zone_length must be
407 au_to_zonename(size_t zone_length
, zone_t
*zone
)
409 token_t
*token
; /* local au_membuf */
410 adr_t adr
; /* adr memory stream header */
411 char data_header
= AUT_ZONENAME
; /* header for this token */
412 short bytes
; /* length of string */
417 zone
= curproc
->p_zone
;
418 bytes
= (short)strlen(zone
->zone_name
) + 1;
420 * If zone_length != 0, it was precalculated and is
421 * the token length, not the string length.
423 ASSERT((zone_length
== 0) ||
424 (zone_length
== (bytes
+ ZONE_TOKEN_OVERHEAD
)));
426 adr_start(&adr
, memtod(token
, char *));
427 adr_char(&adr
, &data_header
, 1);
428 adr_short(&adr
, &bytes
, 1);
430 token
->len
= (char)adr_count(&adr
);
431 (void) au_append_buf(zone
->zone_name
, bytes
, token
);
439 * pointer to au_membuf chain containing a strings array token.
443 char header
, /* token type */
444 const char *kstrp
, /* kernel string pointer */
445 ssize_t count
) /* count of arguments */
447 token_t
*token
; /* local au_membuf */
448 token_t
*m
; /* local au_membuf */
449 adr_t adr
; /* adr memory stream header */
455 adr_start(&adr
, memtod(token
, char *));
456 adr_char(&adr
, &header
, 1);
457 tlen
= (int32_t)count
;
458 adr_int32(&adr
, &tlen
, 1);
460 token
->len
= (char)adr_count(&adr
);
462 while (count
-- > 0) {
464 len
= strlen(kstrp
) + 1;
465 (void) au_append_buf(kstrp
, len
, m
);
466 (void) au_append_rec((token_t
*)token
, (token_t
*)m
, AU_PACK
);
476 * pointer to au_membuf chain containing a argv token.
479 au_to_exec_args(const char *kstrp
, ssize_t argc
)
481 return (au_to_strings(AUT_EXEC_ARGS
, kstrp
, argc
));
487 * pointer to au_membuf chain containing a arge token.
490 au_to_exec_env(const char *kstrp
, ssize_t envc
)
492 return (au_to_strings(AUT_EXEC_ENV
, kstrp
, envc
));
497 * char n; argument # being used
498 * char *text; text describing argument
499 * uint32_t v; argument value
501 * pointer to au_membuf chain containing an argument token.
504 au_to_arg32(char n
, char *text
, uint32_t v
)
506 token_t
*token
; /* local au_membuf */
507 adr_t adr
; /* adr memory stream header */
508 char data_header
= AUT_ARG32
; /* header for this token */
509 short bytes
; /* length of string */
513 bytes
= strlen(text
) + 1;
514 adr_start(&adr
, memtod(token
, char *));
515 adr_char(&adr
, &data_header
, 1); /* token type */
516 adr_char(&adr
, &n
, 1); /* argument id */
517 adr_uint32(&adr
, &v
, 1); /* argument value */
518 adr_short(&adr
, &bytes
, 1);
520 token
->len
= adr_count(&adr
);
522 * Now add the description
524 (void) au_append_buf(text
, bytes
, token
);
532 * char n; argument # being used
533 * char *text; text describing argument
534 * uint64_t v; argument value
536 * pointer to au_membuf chain containing an argument token.
539 au_to_arg64(char n
, char *text
, uint64_t v
)
541 token_t
*token
; /* local au_membuf */
542 adr_t adr
; /* adr memory stream header */
543 char data_header
= AUT_ARG64
; /* header for this token */
544 short bytes
; /* length of string */
548 bytes
= strlen(text
) + 1;
549 adr_start(&adr
, memtod(token
, char *));
550 adr_char(&adr
, &data_header
, 1); /* token type */
551 adr_char(&adr
, &n
, 1); /* argument id */
552 adr_uint64(&adr
, &v
, 1); /* argument value */
553 adr_short(&adr
, &bytes
, 1);
555 token
->len
= adr_count(&adr
);
557 * Now the description
559 (void) au_append_buf(text
, bytes
, token
);
568 * pointer to au_membuf chain containing a path token.
571 au_to_path(struct audit_path
*app
)
573 token_t
*token
; /* local au_membuf */
574 token_t
*m
; /* local au_membuf */
575 adr_t adr
; /* adr memory stream header */
576 char data_header
= AUT_PATH
; /* header for this token */
577 short bytes
; /* length of string */
578 char *path
= app
->audp_sect
[0];
580 bytes
= (short)(app
->audp_sect
[1] - app
->audp_sect
[0]);
583 * generate path token header
586 adr_start(&adr
, memtod(m
, char *));
587 adr_char(&adr
, &data_header
, 1);
588 adr_short(&adr
, &bytes
, 1);
589 m
->len
= adr_count(&adr
);
591 /* append path string */
593 (void) au_append_buf(path
, bytes
, token
);
595 if (app
->audp_cnt
> 1) {
596 /* generate attribute path strings token */
597 m
= au_to_strings(AUT_XATPATH
, app
->audp_sect
[1],
600 token
= au_append_token(token
, m
);
609 * pointer to au_membuf chain containing a System V IPC token.
612 au_to_ipc(char type
, int id
)
614 token_t
*m
; /* local au_membuf */
615 adr_t adr
; /* adr memory stream header */
616 char data_header
= AUT_IPC
; /* header for this token */
620 adr_start(&adr
, memtod(m
, char *));
621 adr_char(&adr
, &data_header
, 1);
622 adr_char(&adr
, &type
, 1); /* type of IPC object */
623 adr_int32(&adr
, (int32_t *)&id
, 1);
625 m
->len
= adr_count(&adr
);
633 * pointer to au_membuf chain containing a return value token.
636 au_to_return32(int error
, int32_t rv
)
638 token_t
*m
; /* local au_membuf */
639 adr_t adr
; /* adr memory stream header */
640 char data_header
= AUT_RETURN32
; /* header for this token */
646 adr_start(&adr
, memtod(m
, char *));
647 adr_char(&adr
, &data_header
, 1);
648 adr_char(&adr
, &ed
, 1);
652 adr_int32(&adr
, &val
, 1);
654 adr_int32(&adr
, &rv
, 1);
656 m
->len
= adr_count(&adr
);
664 * pointer to au_membuf chain containing a return value token.
667 au_to_return64(int error
, int64_t rv
)
669 token_t
*m
; /* local au_membuf */
670 adr_t adr
; /* adr memory stream header */
671 char data_header
= AUT_RETURN64
; /* header for this token */
677 adr_start(&adr
, memtod(m
, char *));
678 adr_char(&adr
, &data_header
, 1);
679 adr_char(&adr
, &ed
, 1);
683 adr_int64(&adr
, &val
, 1);
685 adr_int64(&adr
, &rv
, 1);
687 m
->len
= adr_count(&adr
);
692 #ifdef AU_MAY_USE_SOMEDAY
696 * pointer to au_membuf chain containing a opaque token.
699 au_to_opaque(short bytes
, char *opaque
)
701 token_t
*token
; /* local au_membuf */
702 adr_t adr
; /* adr memory stream header */
703 char data_header
= AUT_OPAQUE
; /* header for this token */
707 adr_start(&adr
, memtod(token
, char *));
708 adr_char(&adr
, &data_header
, 1);
709 adr_short(&adr
, &bytes
, 1);
711 token
->len
= adr_count(&adr
);
714 * Now attach the data
716 (void) au_append_buf(opaque
, bytes
, token
);
720 #endif /* AU_MAY_USE_SOMEDAY */
725 * pointer to au_membuf chain containing a ip header token
728 au_to_ip(struct ip
*ipp
)
730 token_t
*m
; /* local au_membuf */
731 adr_t adr
; /* adr memory stream header */
732 char data_header
= AUT_IP
; /* header for this token */
736 adr_start(&adr
, memtod(m
, char *));
737 adr_char(&adr
, &data_header
, 1);
738 adr_char(&adr
, (char *)ipp
, 2);
739 adr_short(&adr
, (short *)&(ipp
->ip_len
), 3);
740 adr_char(&adr
, (char *)&(ipp
->ip_ttl
), 2);
741 adr_short(&adr
, (short *)&(ipp
->ip_sum
), 1);
742 adr_int32(&adr
, (int32_t *)&(ipp
->ip_src
), 2);
744 m
->len
= adr_count(&adr
);
752 * pointer to au_membuf chain containing a ip path token
755 au_to_iport(ushort_t iport
)
757 token_t
*m
; /* local au_membuf */
758 adr_t adr
; /* adr memory stream header */
759 char data_header
= AUT_IPORT
; /* header for this token */
763 adr_start(&adr
, memtod(m
, char *));
764 adr_char(&adr
, &data_header
, 1);
765 adr_ushort(&adr
, &iport
, 1);
767 m
->len
= adr_count(&adr
);
775 * pointer to au_membuf chain containing a ip path token
778 au_to_in_addr(struct in_addr
*internet_addr
)
780 token_t
*m
; /* local au_membuf */
781 adr_t adr
; /* adr memory stream header */
782 char data_header
= AUT_IN_ADDR
; /* header for this token */
786 adr_start(&adr
, memtod(m
, char *));
787 adr_char(&adr
, &data_header
, 1);
788 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in_addr
));
790 m
->len
= adr_count(&adr
);
798 * pointer to au_membuf chain containing an ipv6 token
801 au_to_in_addr_ex(int32_t *internet_addr
)
803 token_t
*m
; /* local au_membuf */
804 adr_t adr
; /* adr memory stream header */
805 char data_header_v4
= AUT_IN_ADDR
; /* header for v4 token */
806 char data_header_v6
= AUT_IN_ADDR_EX
; /* header for v6 token */
807 int32_t type
= AU_IPv6
;
810 adr_start(&adr
, memtod(m
, char *));
812 if (IN6_IS_ADDR_V4MAPPED((in6_addr_t
*)internet_addr
)) {
816 * An IPv4-mapped IPv6 address is really an IPv4 address
819 IN6_V4MAPPED_TO_IPADDR((in6_addr_t
*)internet_addr
, in4
);
821 adr_char(&adr
, &data_header_v4
, 1);
822 adr_char(&adr
, (char *)&in4
, sizeof (ipaddr_t
));
824 adr_char(&adr
, &data_header_v6
, 1);
825 adr_int32(&adr
, &type
, 1);
826 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in6_addr
));
829 m
->len
= adr_count(&adr
);
835 * The Modifier tokens
841 * pointer to au_membuf chain containing an attribute token.
844 au_to_attr(struct vattr
*attr
)
846 token_t
*m
; /* local au_membuf */
847 adr_t adr
; /* adr memory stream header */
849 char data_header
= AUT_ATTR64
; /* header for this token */
851 char data_header
= AUT_ATTR32
;
857 adr_start(&adr
, memtod(m
, char *));
858 adr_char(&adr
, &data_header
, 1);
859 value
= (int32_t)attr
->va_mode
;
860 value
|= (int32_t)(VTTOIF(attr
->va_type
));
861 adr_int32(&adr
, &value
, 1);
862 value
= (int32_t)attr
->va_uid
;
863 adr_int32(&adr
, &value
, 1);
864 value
= (int32_t)attr
->va_gid
;
865 adr_int32(&adr
, &value
, 1);
866 adr_int32(&adr
, (int32_t *)&(attr
->va_fsid
), 1);
867 adr_int64(&adr
, (int64_t *)&(attr
->va_nodeid
), 1);
869 adr_int64(&adr
, (int64_t *)&(attr
->va_rdev
), 1);
871 adr_int32(&adr
, (int32_t *)&(attr
->va_rdev
), 1);
874 m
->len
= adr_count(&adr
);
880 au_to_acl(struct acl
*aclp
)
882 token_t
*m
; /* local au_membuf */
883 adr_t adr
; /* adr memory stream header */
884 char data_header
= AUT_ACL
; /* header for this token */
889 adr_start(&adr
, memtod(m
, char *));
890 adr_char(&adr
, &data_header
, 1);
892 value
= (int32_t)aclp
->a_type
;
893 adr_int32(&adr
, &value
, 1);
894 value
= (int32_t)aclp
->a_id
;
895 adr_int32(&adr
, &value
, 1);
896 value
= (int32_t)aclp
->a_perm
;
897 adr_int32(&adr
, &value
, 1);
899 m
->len
= adr_count(&adr
);
904 au_to_ace(ace_t
*acep
)
906 token_t
*m
; /* local au_membuf */
907 adr_t adr
; /* adr memory stream header */
908 char data_header
= AUT_ACE
; /* header for this token */
912 adr_start(&adr
, memtod(m
, char *));
913 adr_char(&adr
, &data_header
, 1);
915 adr_uint32(&adr
, &(acep
->a_who
), 1);
916 adr_uint32(&adr
, &(acep
->a_access_mask
), 1);
917 adr_ushort(&adr
, &(acep
->a_flags
), 1);
918 adr_ushort(&adr
, &(acep
->a_type
), 1);
920 m
->len
= adr_count(&adr
);
927 * pointer to au_membuf chain containing a System V IPC attribute token.
930 au_to_ipc_perm(struct kipc_perm
*perm
)
932 token_t
*m
; /* local au_membuf */
933 adr_t adr
; /* adr memory stream header */
934 char data_header
= AUT_IPC_PERM
; /* header for this token */
939 adr_start(&adr
, memtod(m
, char *));
940 adr_char(&adr
, &data_header
, 1);
941 value
= (int32_t)perm
->ipc_uid
;
942 adr_int32(&adr
, &value
, 1);
943 value
= (int32_t)perm
->ipc_gid
;
944 adr_int32(&adr
, &value
, 1);
945 value
= (int32_t)perm
->ipc_cuid
;
946 adr_int32(&adr
, &value
, 1);
947 value
= (int32_t)perm
->ipc_cgid
;
948 adr_int32(&adr
, &value
, 1);
949 value
= (int32_t)perm
->ipc_mode
;
950 adr_int32(&adr
, &value
, 1);
951 value
= 0; /* seq is now obsolete */
952 adr_int32(&adr
, &value
, 1);
953 value
= (int32_t)perm
->ipc_key
;
954 adr_int32(&adr
, &value
, 1);
956 m
->len
= adr_count(&adr
);
962 au_to_groups(const gid_t
*crgroups
, uint_t crngroups
)
964 token_t
*m
; /* local au_membuf */
965 adr_t adr
; /* adr memory stream header */
966 char data_header
= AUT_NEWGROUPS
; /* header for this token */
971 adr_start(&adr
, memtod(m
, char *));
972 adr_char(&adr
, &data_header
, 1);
973 n_groups
= (short)crngroups
;
974 adr_short(&adr
, &n_groups
, 1);
975 adr_int32(&adr
, (int32_t *)crgroups
, (int)crngroups
);
977 m
->len
= adr_count(&adr
);
985 * pointer to au_membuf chain containing a socket token.
988 au_to_socket_ex(short dom
, short type
, char *l
, char *f
)
992 char data_header
= AUT_SOCKET_EX
;
993 struct sockaddr_in6
*addr6
;
994 struct sockaddr_in
*addr4
;
999 adr_start(&adr
, memtod(m
, char *));
1000 adr_char(&adr
, &data_header
, 1);
1001 adr_short(&adr
, &dom
, 1); /* dom of socket */
1002 adr_short(&adr
, &type
, 1); /* type of socket */
1004 if (dom
== AF_INET6
) {
1006 adr_short(&adr
, &size
, 1); /* type of addresses */
1007 addr6
= (struct sockaddr_in6
*)l
;
1008 adr_short(&adr
, (short *)&addr6
->sin6_port
, 1);
1009 adr_char(&adr
, (char *)&addr6
->sin6_addr
, size
);
1010 addr6
= (struct sockaddr_in6
*)f
;
1011 adr_short(&adr
, (short *)&addr6
->sin6_port
, 1);
1012 adr_char(&adr
, (char *)&addr6
->sin6_addr
, size
);
1013 } else if (dom
== AF_INET
) {
1015 adr_short(&adr
, &size
, 1); /* type of addresses */
1016 addr4
= (struct sockaddr_in
*)l
;
1017 adr_short(&adr
, (short *)&addr4
->sin_port
, 1);
1018 adr_char(&adr
, (char *)&addr4
->sin_addr
, size
);
1019 addr4
= (struct sockaddr_in
*)f
;
1020 adr_short(&adr
, (short *)&addr4
->sin_port
, 1);
1021 adr_char(&adr
, (char *)&addr4
->sin_addr
, size
);
1025 m
->len
= adr_count(&adr
);
1033 * pointer to au_membuf chain containing a sequence token.
1040 char data_header
= AUT_SEQ
;
1041 static int32_t zerocount
;
1045 adr_start(&adr
, memtod(m
, char *));
1047 adr_char(&adr
, &data_header
, 1);
1049 adr_int32(&adr
, &zerocount
, 1);
1051 m
->len
= adr_count(&adr
);
1057 au_to_sock_inet(struct sockaddr_in
*s_inet
)
1061 char data_header
= AUT_SOCKET
;
1065 adr_start(&adr
, memtod(m
, char *));
1066 adr_char(&adr
, &data_header
, 1);
1067 adr_short(&adr
, (short *)&s_inet
->sin_family
, 1);
1068 adr_short(&adr
, (short *)&s_inet
->sin_port
, 1);
1071 adr_int32(&adr
, (int32_t *)&s_inet
->sin_addr
.s_addr
, 1);
1073 m
->len
= (uchar_t
)adr_count(&adr
);
1078 extern int maxprivbytes
;
1083 const priv_set_t
*pset
,
1091 char sf
= (char)success
;
1096 token
= au_getclr();
1098 adr_start(&adr
, memtod(token
, char *));
1099 adr_char(&adr
, &data_header
, 1);
1101 * set is not used for AUT_UPRIV and sf (== success) is not
1104 if (data_header
== AUT_UPRIV
) {
1105 adr_char(&adr
, &sf
, 1);
1107 sz
= strlen(set
) + 1;
1108 adr_short(&adr
, &sz
, 1);
1110 token
->len
= (uchar_t
)adr_count(&adr
);
1113 (void) au_append_buf(set
, sz
, m
);
1114 (void) au_append_rec(token
, m
, AU_PACK
);
1118 full
= priv_isfullset(pset
);
1122 sz
= strlen(buf
) + 1;
1124 q
= buf
= kmem_alloc(maxprivbytes
, KM_SLEEP
);
1127 for (priv
= 0; (pname
= priv_getbynum(priv
)) != NULL
; priv
++) {
1128 if (priv_ismember(pset
, priv
)) {
1131 (void) strcpy(q
, pname
);
1138 adr_short(&adr
, &sz
, 1);
1139 token
->len
= (uchar_t
)adr_count(&adr
);
1142 (void) au_append_buf(buf
, sz
, m
);
1143 (void) au_append_rec(token
, m
, AU_PACK
);
1146 kmem_free(buf
, maxprivbytes
);
1152 au_to_secflags(const char *which
, secflagset_t set
)
1156 char data_header
= AUT_SECFLAGS
;
1160 token
= au_getclr();
1162 adr_start(&adr
, memtod(token
, char *));
1163 adr_char(&adr
, &data_header
, 1);
1165 sz
= strlen(which
) + 1;
1166 adr_short(&adr
, &sz
, 1);
1168 token
->len
= (uchar_t
)adr_count(&adr
);
1170 (void) au_append_buf(which
, sz
, m
);
1171 (void) au_append_rec(token
, m
, AU_PACK
);
1174 secflags_to_str(set
, secstr
, sizeof (secstr
));
1175 sz
= strlen(secstr
) + 1;
1176 adr_short(&adr
, &sz
, 1);
1177 token
->len
= (uchar_t
)adr_count(&adr
);
1179 (void) au_append_buf(secstr
, sz
, m
);
1180 (void) au_append_rec(token
, m
, AU_PACK
);