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 */
54 #include <sys/tsol/label.h>
57 * These are the control tokens
63 * pointer to au_membuf chain containing a header token.
66 au_to_header(int byte_count
, au_event_t e_type
, au_emod_t e_mod
)
68 adr_t adr
; /* adr memory stream header */
69 token_t
*m
; /* au_membuf pointer */
71 char data_header
= AUT_HEADER64
; /* header for this token */
72 static int64_t zerotime
[2];
74 char data_header
= AUT_HEADER32
;
75 static int32_t zerotime
[2];
77 char version
= TOKEN_VERSION
; /* version of token family */
81 adr_start(&adr
, memtod(m
, char *));
82 adr_char(&adr
, &data_header
, 1); /* token ID */
83 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
85 adr_char(&adr
, &version
, 1); /* version of audit tokens */
86 adr_ushort(&adr
, &e_type
, 1); /* event ID */
87 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
89 adr_int64(&adr
, zerotime
, 2); /* time & date space */
91 adr_int32(&adr
, zerotime
, 2);
93 m
->len
= adr_count(&adr
);
99 au_to_header_ex(int byte_count
, au_event_t e_type
, au_emod_t e_mod
)
101 adr_t adr
; /* adr memory stream header */
102 token_t
*m
; /* au_membuf pointer */
103 au_kcontext_t
*kctx
= GET_KCTX_PZ
;
106 char data_header
= AUT_HEADER64_EX
; /* header for this token */
107 static int64_t zerotime
[2];
109 char data_header
= AUT_HEADER32_EX
;
110 static int32_t zerotime
[2];
112 char version
= TOKEN_VERSION
; /* version of token family */
116 adr_start(&adr
, memtod(m
, char *));
117 adr_char(&adr
, &data_header
, 1); /* token ID */
118 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
120 adr_char(&adr
, &version
, 1); /* version of audit tokens */
121 adr_ushort(&adr
, &e_type
, 1); /* event ID */
122 adr_ushort(&adr
, &e_mod
, 1); /* event ID modifier */
123 adr_uint32(&adr
, &kctx
->auk_info
.ai_termid
.at_type
, 1);
124 adr_char(&adr
, (char *)&kctx
->auk_info
.ai_termid
.at_addr
[0],
125 (int)kctx
->auk_info
.ai_termid
.at_type
);
127 adr_int64(&adr
, zerotime
, 2); /* time & date */
129 adr_int32(&adr
, zerotime
, 2);
131 m
->len
= adr_count(&adr
);
139 * pointer to au_membuf chain containing a trailer token.
142 au_to_trailer(int byte_count
)
144 adr_t adr
; /* adr memory stream header */
145 token_t
*m
; /* au_membuf pointer */
146 char data_header
= AUT_TRAILER
; /* header for this token */
147 short magic
= (short)AUT_TRAILER_MAGIC
; /* trailer magic number */
151 adr_start(&adr
, memtod(m
, char *));
152 adr_char(&adr
, &data_header
, 1); /* token ID */
153 adr_short(&adr
, &magic
, 1); /* magic number */
154 adr_int32(&adr
, (int32_t *)&byte_count
, 1); /* length of */
157 m
->len
= adr_count(&adr
);
162 * These are the data tokens
168 * pointer to au_membuf chain containing a data token.
171 au_to_data(char unit_print
, char unit_type
, char unit_count
, char *p
)
173 adr_t adr
; /* adr memory stream header */
174 token_t
*m
; /* au_membuf pointer */
175 char data_header
= AUT_DATA
; /* header for this token */
178 ASSERT(unit_count
!= 0);
182 if (sizeof (short) * unit_count
>= AU_BUFSIZE
)
183 return (au_to_text("au_to_data: unit count too big"));
186 if (sizeof (int32_t) * unit_count
>= AU_BUFSIZE
)
187 return (au_to_text("au_to_data: unit count too big"));
190 if (sizeof (int64_t) * unit_count
>= AU_BUFSIZE
)
191 return (au_to_text("au_to_data: unit count too big"));
195 #ifdef _CHAR_IS_UNSIGNED
196 if (sizeof (char) * unit_count
>= AU_BUFSIZE
)
197 return (au_to_text("au_to_data: unit count too big"));
200 * we used to check for this:
201 * sizeof (char) * (int)unit_count >= AU_BUFSIZE).
202 * but the compiler is smart enough to see that
203 * will never be >= AU_BUFSIZE, since that's 128
204 * and unit_count maxes out at 127 (signed char),
212 adr_start(&adr
, memtod(m
, char *));
213 adr_char(&adr
, &data_header
, 1);
214 adr_char(&adr
, &unit_print
, 1);
215 adr_char(&adr
, &unit_type
, 1);
216 adr_char(&adr
, &unit_count
, 1);
220 adr_short(&adr
, (short *)p
, unit_count
);
223 adr_int32(&adr
, (int32_t *)p
, unit_count
);
226 adr_int64(&adr
, (int64_t *)p
, unit_count
);
230 adr_char(&adr
, p
, unit_count
);
234 m
->len
= adr_count(&adr
);
243 * pointer to au_membuf chain containing a process token.
245 static token_t
*au_to_any_process(char, uid_t
, gid_t
, uid_t
, gid_t
,
246 pid_t
, au_id_t
, au_asid_t
, const au_tid_addr_t
*atid
);
249 au_to_process(uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
250 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
255 if (atid
->at_type
== AU_IPv6
)
256 data_header
= AUT_PROCESS64_EX
;
258 data_header
= AUT_PROCESS64
;
260 if (atid
->at_type
== AU_IPv6
)
261 data_header
= AUT_PROCESS32_EX
;
263 data_header
= AUT_PROCESS32
;
266 return (au_to_any_process(data_header
, uid
, gid
, ruid
,
267 rgid
, pid
, auid
, asid
, atid
));
271 au_to_subject(uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
272 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
277 if (atid
->at_type
== AU_IPv6
)
278 data_header
= AUT_SUBJECT64_EX
;
280 data_header
= AUT_SUBJECT64
;
282 if (atid
->at_type
== AU_IPv6
)
283 data_header
= AUT_SUBJECT32_EX
;
285 data_header
= AUT_SUBJECT32
;
287 return (au_to_any_process(data_header
, uid
, gid
, ruid
,
288 rgid
, pid
, auid
, asid
, atid
));
293 au_to_any_process(char data_header
,
294 uid_t uid
, gid_t gid
, uid_t ruid
, gid_t rgid
, pid_t pid
,
295 au_id_t auid
, au_asid_t asid
, const au_tid_addr_t
*atid
)
297 token_t
*m
; /* local au_membuf */
298 adr_t adr
; /* adr memory stream header */
303 adr_start(&adr
, memtod(m
, char *));
304 adr_char(&adr
, &data_header
, 1);
305 value
= (int32_t)auid
;
306 adr_int32(&adr
, &value
, 1);
307 value
= (int32_t)uid
;
308 adr_int32(&adr
, &value
, 1);
309 value
= (int32_t)gid
;
310 adr_int32(&adr
, &value
, 1);
311 value
= (int32_t)ruid
;
312 adr_int32(&adr
, &value
, 1);
313 value
= (int32_t)rgid
;
314 adr_int32(&adr
, &value
, 1);
315 value
= (int32_t)pid
;
316 adr_int32(&adr
, &value
, 1);
317 value
= (int32_t)asid
;
318 adr_int32(&adr
, &value
, 1);
320 adr_int64(&adr
, (int64_t *)&(atid
->at_port
), 1);
322 adr_int32(&adr
, (int32_t *)&(atid
->at_port
), 1);
324 if (atid
->at_type
== AU_IPv6
) {
325 adr_uint32(&adr
, (uint_t
*)&atid
->at_type
, 1);
326 adr_char(&adr
, (char *)&atid
->at_addr
[0], 16);
328 adr_char(&adr
, (char *)&(atid
->at_addr
[0]), 4);
331 m
->len
= adr_count(&adr
);
339 * pointer to au_membuf chain containing a text token.
342 au_to_text(const char *text
)
344 token_t
*token
; /* local au_membuf */
345 adr_t adr
; /* adr memory stream header */
346 char data_header
= AUT_TEXT
; /* header for this token */
347 short bytes
; /* length of string */
351 bytes
= (short)strlen(text
) + 1;
352 adr_start(&adr
, memtod(token
, char *));
353 adr_char(&adr
, &data_header
, 1);
354 adr_short(&adr
, &bytes
, 1);
356 token
->len
= (char)adr_count(&adr
);
358 * Now attach the text
360 (void) au_append_buf(text
, bytes
, token
);
368 * - length of zonename token to be generated
369 * - zone name up to ZONENAME_MAX + 1 in length
371 #define ZONE_TOKEN_OVERHEAD 3
375 * string length (2 bytes)
376 * the string (strlen(zonename) + 1)
379 au_zonename_length(zone_t
*zone
)
382 zone
= curproc
->p_zone
;
383 return (strlen(zone
->zone_name
) + 1 +
384 ZONE_TOKEN_OVERHEAD
);
390 * A length of zero input to au_to_zonename means the length is not
393 * The caller is responsible for checking the AUDIT_ZONENAME policy
394 * before calling au_zonename_length() and au_to_zonename(). If
395 * the policy changes between the calls, no harm is done, so the
396 * policy only needs to be checked once.
399 * pointer to au_membuf chain containing a zonename token; NULL if
402 * if the zonename token is generated at token generation close time,
403 * the length of the token is already known and it is ASSERTed that
404 * it has not changed. If not precalculated, zone_length must be
408 au_to_zonename(size_t zone_length
, zone_t
*zone
)
410 token_t
*token
; /* local au_membuf */
411 adr_t adr
; /* adr memory stream header */
412 char data_header
= AUT_ZONENAME
; /* header for this token */
413 short bytes
; /* length of string */
418 zone
= curproc
->p_zone
;
419 bytes
= (short)strlen(zone
->zone_name
) + 1;
421 * If zone_length != 0, it was precalculated and is
422 * the token length, not the string length.
424 ASSERT((zone_length
== 0) ||
425 (zone_length
== (bytes
+ ZONE_TOKEN_OVERHEAD
)));
427 adr_start(&adr
, memtod(token
, char *));
428 adr_char(&adr
, &data_header
, 1);
429 adr_short(&adr
, &bytes
, 1);
431 token
->len
= (char)adr_count(&adr
);
432 (void) au_append_buf(zone
->zone_name
, bytes
, token
);
440 * pointer to au_membuf chain containing a strings array token.
444 char header
, /* token type */
445 const char *kstrp
, /* kernel string pointer */
446 ssize_t count
) /* count of arguments */
448 token_t
*token
; /* local au_membuf */
449 token_t
*m
; /* local au_membuf */
450 adr_t adr
; /* adr memory stream header */
456 adr_start(&adr
, memtod(token
, char *));
457 adr_char(&adr
, &header
, 1);
458 tlen
= (int32_t)count
;
459 adr_int32(&adr
, &tlen
, 1);
461 token
->len
= (char)adr_count(&adr
);
463 while (count
-- > 0) {
465 len
= strlen(kstrp
) + 1;
466 (void) au_append_buf(kstrp
, len
, m
);
467 (void) au_append_rec((token_t
*)token
, (token_t
*)m
, AU_PACK
);
477 * pointer to au_membuf chain containing a argv token.
480 au_to_exec_args(const char *kstrp
, ssize_t argc
)
482 return (au_to_strings(AUT_EXEC_ARGS
, kstrp
, argc
));
488 * pointer to au_membuf chain containing a arge token.
491 au_to_exec_env(const char *kstrp
, ssize_t envc
)
493 return (au_to_strings(AUT_EXEC_ENV
, kstrp
, envc
));
498 * char n; argument # being used
499 * char *text; text describing argument
500 * uint32_t v; argument value
502 * pointer to au_membuf chain containing an argument token.
505 au_to_arg32(char n
, char *text
, uint32_t v
)
507 token_t
*token
; /* local au_membuf */
508 adr_t adr
; /* adr memory stream header */
509 char data_header
= AUT_ARG32
; /* header for this token */
510 short bytes
; /* length of string */
514 bytes
= strlen(text
) + 1;
515 adr_start(&adr
, memtod(token
, char *));
516 adr_char(&adr
, &data_header
, 1); /* token type */
517 adr_char(&adr
, &n
, 1); /* argument id */
518 adr_uint32(&adr
, &v
, 1); /* argument value */
519 adr_short(&adr
, &bytes
, 1);
521 token
->len
= adr_count(&adr
);
523 * Now add the description
525 (void) au_append_buf(text
, bytes
, token
);
533 * char n; argument # being used
534 * char *text; text describing argument
535 * uint64_t v; argument value
537 * pointer to au_membuf chain containing an argument token.
540 au_to_arg64(char n
, char *text
, uint64_t v
)
542 token_t
*token
; /* local au_membuf */
543 adr_t adr
; /* adr memory stream header */
544 char data_header
= AUT_ARG64
; /* header for this token */
545 short bytes
; /* length of string */
549 bytes
= strlen(text
) + 1;
550 adr_start(&adr
, memtod(token
, char *));
551 adr_char(&adr
, &data_header
, 1); /* token type */
552 adr_char(&adr
, &n
, 1); /* argument id */
553 adr_uint64(&adr
, &v
, 1); /* argument value */
554 adr_short(&adr
, &bytes
, 1);
556 token
->len
= adr_count(&adr
);
558 * Now the description
560 (void) au_append_buf(text
, bytes
, token
);
569 * pointer to au_membuf chain containing a path token.
572 au_to_path(struct audit_path
*app
)
574 token_t
*token
; /* local au_membuf */
575 token_t
*m
; /* local au_membuf */
576 adr_t adr
; /* adr memory stream header */
577 char data_header
= AUT_PATH
; /* header for this token */
578 short bytes
; /* length of string */
579 char *path
= app
->audp_sect
[0];
581 bytes
= (short)(app
->audp_sect
[1] - app
->audp_sect
[0]);
584 * generate path token header
587 adr_start(&adr
, memtod(m
, char *));
588 adr_char(&adr
, &data_header
, 1);
589 adr_short(&adr
, &bytes
, 1);
590 m
->len
= adr_count(&adr
);
592 /* append path string */
594 (void) au_append_buf(path
, bytes
, token
);
596 if (app
->audp_cnt
> 1) {
597 /* generate attribute path strings token */
598 m
= au_to_strings(AUT_XATPATH
, app
->audp_sect
[1],
601 token
= au_append_token(token
, m
);
610 * pointer to au_membuf chain containing a System V IPC token.
613 au_to_ipc(char type
, int id
)
615 token_t
*m
; /* local au_membuf */
616 adr_t adr
; /* adr memory stream header */
617 char data_header
= AUT_IPC
; /* header for this token */
621 adr_start(&adr
, memtod(m
, char *));
622 adr_char(&adr
, &data_header
, 1);
623 adr_char(&adr
, &type
, 1); /* type of IPC object */
624 adr_int32(&adr
, (int32_t *)&id
, 1);
626 m
->len
= adr_count(&adr
);
634 * pointer to au_membuf chain containing a return value token.
637 au_to_return32(int error
, int32_t rv
)
639 token_t
*m
; /* local au_membuf */
640 adr_t adr
; /* adr memory stream header */
641 char data_header
= AUT_RETURN32
; /* header for this token */
647 adr_start(&adr
, memtod(m
, char *));
648 adr_char(&adr
, &data_header
, 1);
649 adr_char(&adr
, &ed
, 1);
653 adr_int32(&adr
, &val
, 1);
655 adr_int32(&adr
, &rv
, 1);
657 m
->len
= adr_count(&adr
);
665 * pointer to au_membuf chain containing a return value token.
668 au_to_return64(int error
, int64_t rv
)
670 token_t
*m
; /* local au_membuf */
671 adr_t adr
; /* adr memory stream header */
672 char data_header
= AUT_RETURN64
; /* header for this token */
678 adr_start(&adr
, memtod(m
, char *));
679 adr_char(&adr
, &data_header
, 1);
680 adr_char(&adr
, &ed
, 1);
684 adr_int64(&adr
, &val
, 1);
686 adr_int64(&adr
, &rv
, 1);
688 m
->len
= adr_count(&adr
);
693 #ifdef AU_MAY_USE_SOMEDAY
697 * pointer to au_membuf chain containing a opaque token.
700 au_to_opaque(short bytes
, char *opaque
)
702 token_t
*token
; /* local au_membuf */
703 adr_t adr
; /* adr memory stream header */
704 char data_header
= AUT_OPAQUE
; /* header for this token */
708 adr_start(&adr
, memtod(token
, char *));
709 adr_char(&adr
, &data_header
, 1);
710 adr_short(&adr
, &bytes
, 1);
712 token
->len
= adr_count(&adr
);
715 * Now attach the data
717 (void) au_append_buf(opaque
, bytes
, token
);
721 #endif /* AU_MAY_USE_SOMEDAY */
726 * pointer to au_membuf chain containing a ip header token
729 au_to_ip(struct ip
*ipp
)
731 token_t
*m
; /* local au_membuf */
732 adr_t adr
; /* adr memory stream header */
733 char data_header
= AUT_IP
; /* header for this token */
737 adr_start(&adr
, memtod(m
, char *));
738 adr_char(&adr
, &data_header
, 1);
739 adr_char(&adr
, (char *)ipp
, 2);
740 adr_short(&adr
, (short *)&(ipp
->ip_len
), 3);
741 adr_char(&adr
, (char *)&(ipp
->ip_ttl
), 2);
742 adr_short(&adr
, (short *)&(ipp
->ip_sum
), 1);
743 adr_int32(&adr
, (int32_t *)&(ipp
->ip_src
), 2);
745 m
->len
= adr_count(&adr
);
753 * pointer to au_membuf chain containing a ip path token
756 au_to_iport(ushort_t iport
)
758 token_t
*m
; /* local au_membuf */
759 adr_t adr
; /* adr memory stream header */
760 char data_header
= AUT_IPORT
; /* header for this token */
764 adr_start(&adr
, memtod(m
, char *));
765 adr_char(&adr
, &data_header
, 1);
766 adr_ushort(&adr
, &iport
, 1);
768 m
->len
= adr_count(&adr
);
776 * pointer to au_membuf chain containing a ip path token
779 au_to_in_addr(struct in_addr
*internet_addr
)
781 token_t
*m
; /* local au_membuf */
782 adr_t adr
; /* adr memory stream header */
783 char data_header
= AUT_IN_ADDR
; /* header for this token */
787 adr_start(&adr
, memtod(m
, char *));
788 adr_char(&adr
, &data_header
, 1);
789 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in_addr
));
791 m
->len
= adr_count(&adr
);
799 * pointer to au_membuf chain containing an ipv6 token
802 au_to_in_addr_ex(int32_t *internet_addr
)
804 token_t
*m
; /* local au_membuf */
805 adr_t adr
; /* adr memory stream header */
806 char data_header_v4
= AUT_IN_ADDR
; /* header for v4 token */
807 char data_header_v6
= AUT_IN_ADDR_EX
; /* header for v6 token */
808 int32_t type
= AU_IPv6
;
811 adr_start(&adr
, memtod(m
, char *));
813 if (IN6_IS_ADDR_V4MAPPED((in6_addr_t
*)internet_addr
)) {
817 * An IPv4-mapped IPv6 address is really an IPv4 address
820 IN6_V4MAPPED_TO_IPADDR((in6_addr_t
*)internet_addr
, in4
);
822 adr_char(&adr
, &data_header_v4
, 1);
823 adr_char(&adr
, (char *)&in4
, sizeof (ipaddr_t
));
825 adr_char(&adr
, &data_header_v6
, 1);
826 adr_int32(&adr
, &type
, 1);
827 adr_char(&adr
, (char *)internet_addr
, sizeof (struct in6_addr
));
830 m
->len
= adr_count(&adr
);
836 * The Modifier tokens
842 * pointer to au_membuf chain containing an attribute token.
845 au_to_attr(struct vattr
*attr
)
847 token_t
*m
; /* local au_membuf */
848 adr_t adr
; /* adr memory stream header */
850 char data_header
= AUT_ATTR64
; /* header for this token */
852 char data_header
= AUT_ATTR32
;
858 adr_start(&adr
, memtod(m
, char *));
859 adr_char(&adr
, &data_header
, 1);
860 value
= (int32_t)attr
->va_mode
;
861 value
|= (int32_t)(VTTOIF(attr
->va_type
));
862 adr_int32(&adr
, &value
, 1);
863 value
= (int32_t)attr
->va_uid
;
864 adr_int32(&adr
, &value
, 1);
865 value
= (int32_t)attr
->va_gid
;
866 adr_int32(&adr
, &value
, 1);
867 adr_int32(&adr
, (int32_t *)&(attr
->va_fsid
), 1);
868 adr_int64(&adr
, (int64_t *)&(attr
->va_nodeid
), 1);
870 adr_int64(&adr
, (int64_t *)&(attr
->va_rdev
), 1);
872 adr_int32(&adr
, (int32_t *)&(attr
->va_rdev
), 1);
875 m
->len
= adr_count(&adr
);
881 au_to_acl(struct acl
*aclp
)
883 token_t
*m
; /* local au_membuf */
884 adr_t adr
; /* adr memory stream header */
885 char data_header
= AUT_ACL
; /* header for this token */
890 adr_start(&adr
, memtod(m
, char *));
891 adr_char(&adr
, &data_header
, 1);
893 value
= (int32_t)aclp
->a_type
;
894 adr_int32(&adr
, &value
, 1);
895 value
= (int32_t)aclp
->a_id
;
896 adr_int32(&adr
, &value
, 1);
897 value
= (int32_t)aclp
->a_perm
;
898 adr_int32(&adr
, &value
, 1);
900 m
->len
= adr_count(&adr
);
905 au_to_ace(ace_t
*acep
)
907 token_t
*m
; /* local au_membuf */
908 adr_t adr
; /* adr memory stream header */
909 char data_header
= AUT_ACE
; /* header for this token */
913 adr_start(&adr
, memtod(m
, char *));
914 adr_char(&adr
, &data_header
, 1);
916 adr_uint32(&adr
, &(acep
->a_who
), 1);
917 adr_uint32(&adr
, &(acep
->a_access_mask
), 1);
918 adr_ushort(&adr
, &(acep
->a_flags
), 1);
919 adr_ushort(&adr
, &(acep
->a_type
), 1);
921 m
->len
= adr_count(&adr
);
928 * pointer to au_membuf chain containing a System V IPC attribute token.
931 au_to_ipc_perm(struct kipc_perm
*perm
)
933 token_t
*m
; /* local au_membuf */
934 adr_t adr
; /* adr memory stream header */
935 char data_header
= AUT_IPC_PERM
; /* header for this token */
940 adr_start(&adr
, memtod(m
, char *));
941 adr_char(&adr
, &data_header
, 1);
942 value
= (int32_t)perm
->ipc_uid
;
943 adr_int32(&adr
, &value
, 1);
944 value
= (int32_t)perm
->ipc_gid
;
945 adr_int32(&adr
, &value
, 1);
946 value
= (int32_t)perm
->ipc_cuid
;
947 adr_int32(&adr
, &value
, 1);
948 value
= (int32_t)perm
->ipc_cgid
;
949 adr_int32(&adr
, &value
, 1);
950 value
= (int32_t)perm
->ipc_mode
;
951 adr_int32(&adr
, &value
, 1);
952 value
= 0; /* seq is now obsolete */
953 adr_int32(&adr
, &value
, 1);
954 value
= (int32_t)perm
->ipc_key
;
955 adr_int32(&adr
, &value
, 1);
957 m
->len
= adr_count(&adr
);
963 au_to_groups(const gid_t
*crgroups
, uint_t crngroups
)
965 token_t
*m
; /* local au_membuf */
966 adr_t adr
; /* adr memory stream header */
967 char data_header
= AUT_NEWGROUPS
; /* header for this token */
972 adr_start(&adr
, memtod(m
, char *));
973 adr_char(&adr
, &data_header
, 1);
974 n_groups
= (short)crngroups
;
975 adr_short(&adr
, &n_groups
, 1);
976 adr_int32(&adr
, (int32_t *)crgroups
, (int)crngroups
);
978 m
->len
= adr_count(&adr
);
986 * pointer to au_membuf chain containing a socket token.
989 au_to_socket_ex(short dom
, short type
, char *l
, char *f
)
993 char data_header
= AUT_SOCKET_EX
;
994 struct sockaddr_in6
*addr6
;
995 struct sockaddr_in
*addr4
;
1000 adr_start(&adr
, memtod(m
, char *));
1001 adr_char(&adr
, &data_header
, 1);
1002 adr_short(&adr
, &dom
, 1); /* dom of socket */
1003 adr_short(&adr
, &type
, 1); /* type of socket */
1005 if (dom
== AF_INET6
) {
1007 adr_short(&adr
, &size
, 1); /* type of addresses */
1008 addr6
= (struct sockaddr_in6
*)l
;
1009 adr_short(&adr
, (short *)&addr6
->sin6_port
, 1);
1010 adr_char(&adr
, (char *)&addr6
->sin6_addr
, size
);
1011 addr6
= (struct sockaddr_in6
*)f
;
1012 adr_short(&adr
, (short *)&addr6
->sin6_port
, 1);
1013 adr_char(&adr
, (char *)&addr6
->sin6_addr
, size
);
1014 } else if (dom
== AF_INET
) {
1016 adr_short(&adr
, &size
, 1); /* type of addresses */
1017 addr4
= (struct sockaddr_in
*)l
;
1018 adr_short(&adr
, (short *)&addr4
->sin_port
, 1);
1019 adr_char(&adr
, (char *)&addr4
->sin_addr
, size
);
1020 addr4
= (struct sockaddr_in
*)f
;
1021 adr_short(&adr
, (short *)&addr4
->sin_port
, 1);
1022 adr_char(&adr
, (char *)&addr4
->sin_addr
, size
);
1026 m
->len
= adr_count(&adr
);
1034 * pointer to au_membuf chain containing a sequence token.
1041 char data_header
= AUT_SEQ
;
1042 static int32_t zerocount
;
1046 adr_start(&adr
, memtod(m
, char *));
1048 adr_char(&adr
, &data_header
, 1);
1050 adr_int32(&adr
, &zerocount
, 1);
1052 m
->len
= adr_count(&adr
);
1058 au_to_sock_inet(struct sockaddr_in
*s_inet
)
1062 char data_header
= AUT_SOCKET
;
1066 adr_start(&adr
, memtod(m
, char *));
1067 adr_char(&adr
, &data_header
, 1);
1068 adr_short(&adr
, (short *)&s_inet
->sin_family
, 1);
1069 adr_short(&adr
, (short *)&s_inet
->sin_port
, 1);
1072 adr_int32(&adr
, (int32_t *)&s_inet
->sin_addr
.s_addr
, 1);
1074 m
->len
= (uchar_t
)adr_count(&adr
);
1079 extern int maxprivbytes
;
1084 const priv_set_t
*pset
,
1092 char sf
= (char)success
;
1097 token
= au_getclr();
1099 adr_start(&adr
, memtod(token
, char *));
1100 adr_char(&adr
, &data_header
, 1);
1102 * set is not used for AUT_UPRIV and sf (== success) is not
1105 if (data_header
== AUT_UPRIV
) {
1106 adr_char(&adr
, &sf
, 1);
1108 sz
= strlen(set
) + 1;
1109 adr_short(&adr
, &sz
, 1);
1111 token
->len
= (uchar_t
)adr_count(&adr
);
1114 (void) au_append_buf(set
, sz
, m
);
1115 (void) au_append_rec(token
, m
, AU_PACK
);
1119 full
= priv_isfullset(pset
);
1123 sz
= strlen(buf
) + 1;
1125 q
= buf
= kmem_alloc(maxprivbytes
, KM_SLEEP
);
1128 for (priv
= 0; (pname
= priv_getbynum(priv
)) != NULL
; priv
++) {
1129 if (priv_ismember(pset
, priv
)) {
1132 (void) strcpy(q
, pname
);
1139 adr_short(&adr
, &sz
, 1);
1140 token
->len
= (uchar_t
)adr_count(&adr
);
1143 (void) au_append_buf(buf
, sz
, m
);
1144 (void) au_append_rec(token
, m
, AU_PACK
);
1147 kmem_free(buf
, maxprivbytes
);
1155 * pointer to au_membuf chain containing a label token.
1158 au_to_label(bslabel_t
*label
)
1160 token_t
*m
; /* local au_membuf */
1161 adr_t adr
; /* adr memory stream header */
1162 char data_header
= AUT_LABEL
; /* header for this token */
1166 adr_start(&adr
, memtod(m
, char *));
1167 adr_char(&adr
, &data_header
, 1);
1168 adr_char(&adr
, (char *)label
, sizeof (_mac_label_impl_t
));
1170 m
->len
= adr_count(&adr
);