1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <unistd.h> 31*0Sstevel@tonic-gate #include <bsm/audit.h> 32*0Sstevel@tonic-gate #include <bsm/audit_record.h> 33*0Sstevel@tonic-gate #include <bsm/libbsm.h> 34*0Sstevel@tonic-gate #include <priv.h> 35*0Sstevel@tonic-gate #include <sys/ipc.h> 36*0Sstevel@tonic-gate #include <sys/param.h> 37*0Sstevel@tonic-gate #include <sys/socket.h> 38*0Sstevel@tonic-gate #include <sys/time.h> 39*0Sstevel@tonic-gate #include <sys/vnode.h> 40*0Sstevel@tonic-gate #include <malloc.h> 41*0Sstevel@tonic-gate #include <net/route.h> 42*0Sstevel@tonic-gate #include <netinet/in.h> 43*0Sstevel@tonic-gate #include <netinet/in_pcb.h> 44*0Sstevel@tonic-gate #include <string.h> 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate #define NGROUPS 16 /* XXX - temporary */ 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate token_t *au_to_arg(char n, char *text, uint32_t v); 49*0Sstevel@tonic-gate #pragma weak au_to_arg = au_to_arg32 50*0Sstevel@tonic-gate token_t *au_to_return(char number, uint32_t value); 51*0Sstevel@tonic-gate #pragma weak au_to_return = au_to_return32 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate static token_t *au_to_exec(char **, char); 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate static token_t * 56*0Sstevel@tonic-gate get_token(int s) 57*0Sstevel@tonic-gate { 58*0Sstevel@tonic-gate token_t *token; /* Resultant token */ 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate if ((token = (token_t *)malloc(sizeof (token_t))) == NULL) 61*0Sstevel@tonic-gate return (NULL); 62*0Sstevel@tonic-gate if ((token->tt_data = malloc(s)) == NULL) { 63*0Sstevel@tonic-gate free(token); 64*0Sstevel@tonic-gate return (NULL); 65*0Sstevel@tonic-gate } 66*0Sstevel@tonic-gate token->tt_size = s; 67*0Sstevel@tonic-gate token->tt_next = NULL; 68*0Sstevel@tonic-gate return (token); 69*0Sstevel@tonic-gate } 70*0Sstevel@tonic-gate 71*0Sstevel@tonic-gate /* 72*0Sstevel@tonic-gate * au_to_header 73*0Sstevel@tonic-gate * return s: 74*0Sstevel@tonic-gate * pointer to header token. 75*0Sstevel@tonic-gate */ 76*0Sstevel@tonic-gate token_t * 77*0Sstevel@tonic-gate au_to_header(au_event_t e_type, au_emod_t e_mod) 78*0Sstevel@tonic-gate { 79*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 80*0Sstevel@tonic-gate token_t *token; /* token pointer */ 81*0Sstevel@tonic-gate char version = TOKEN_VERSION; /* version of token family */ 82*0Sstevel@tonic-gate int32_t byte_count; 83*0Sstevel@tonic-gate struct timeval tv; 84*0Sstevel@tonic-gate #ifdef _LP64 85*0Sstevel@tonic-gate char data_header = AUT_HEADER64; /* header for this token */ 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + sizeof (int32_t) + 88*0Sstevel@tonic-gate 2 * sizeof (int64_t) + 2 * sizeof (short)); 89*0Sstevel@tonic-gate #else 90*0Sstevel@tonic-gate char data_header = AUT_HEADER32; 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) + 93*0Sstevel@tonic-gate 2 * sizeof (short)); 94*0Sstevel@tonic-gate #endif 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate if (token == NULL) 97*0Sstevel@tonic-gate return (NULL); 98*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 99*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); /* token ID */ 100*0Sstevel@tonic-gate adr_int32(&adr, &byte_count, 1); /* length of audit record */ 101*0Sstevel@tonic-gate adr_char(&adr, &version, 1); /* version of audit tokens */ 102*0Sstevel@tonic-gate adr_short(&adr, &e_type, 1); /* event ID */ 103*0Sstevel@tonic-gate adr_short(&adr, &e_mod, 1); /* event ID modifier */ 104*0Sstevel@tonic-gate #ifdef _LP64 105*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tv, 2); /* time & date */ 106*0Sstevel@tonic-gate #else 107*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tv, 2); /* time & date */ 108*0Sstevel@tonic-gate #endif 109*0Sstevel@tonic-gate return (token); 110*0Sstevel@tonic-gate } 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate /* 113*0Sstevel@tonic-gate * au_to_header_ex 114*0Sstevel@tonic-gate * return s: 115*0Sstevel@tonic-gate * pointer to header token. 116*0Sstevel@tonic-gate */ 117*0Sstevel@tonic-gate token_t * 118*0Sstevel@tonic-gate au_to_header_ex(au_event_t e_type, au_emod_t e_mod) 119*0Sstevel@tonic-gate { 120*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 121*0Sstevel@tonic-gate token_t *token; /* token pointer */ 122*0Sstevel@tonic-gate char version = TOKEN_VERSION; /* version of token family */ 123*0Sstevel@tonic-gate int32_t byte_count; 124*0Sstevel@tonic-gate struct timeval tv; 125*0Sstevel@tonic-gate auditinfo_addr_t audit_info; 126*0Sstevel@tonic-gate au_tid_addr_t *host_info = &audit_info.ai_termid; 127*0Sstevel@tonic-gate #ifdef _LP64 128*0Sstevel@tonic-gate char data_header = AUT_HEADER64_EX; /* header for this token */ 129*0Sstevel@tonic-gate #else 130*0Sstevel@tonic-gate char data_header = AUT_HEADER32_EX; 131*0Sstevel@tonic-gate #endif 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate /* If our host address can't be determined, revert to un-extended hdr */ 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate if (auditon(A_GETKAUDIT, (caddr_t)&audit_info, 136*0Sstevel@tonic-gate sizeof (audit_info)) < 0) 137*0Sstevel@tonic-gate return (au_to_header(e_type, e_mod)); 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate if (host_info->at_type == AU_IPv6) 140*0Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED((in6_addr_t *)host_info->at_addr)) 141*0Sstevel@tonic-gate return (au_to_header(e_type, e_mod)); 142*0Sstevel@tonic-gate else 143*0Sstevel@tonic-gate if (host_info->at_addr[0] == htonl(INADDR_ANY)) 144*0Sstevel@tonic-gate return (au_to_header(e_type, e_mod)); 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate #ifdef _LP64 147*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + sizeof (int32_t) + 148*0Sstevel@tonic-gate 2 * sizeof (int64_t) + 2 * sizeof (short) + 149*0Sstevel@tonic-gate sizeof (int32_t) + host_info->at_type); 150*0Sstevel@tonic-gate #else 151*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + 3 * sizeof (int32_t) + 152*0Sstevel@tonic-gate 2 * sizeof (short) + sizeof (int32_t) + host_info->at_type); 153*0Sstevel@tonic-gate #endif 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate if (token == NULL) 156*0Sstevel@tonic-gate return (NULL); 157*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 158*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); /* token ID */ 159*0Sstevel@tonic-gate adr_int32(&adr, &byte_count, 1); /* length of audit record */ 160*0Sstevel@tonic-gate adr_char(&adr, &version, 1); /* version of audit tokens */ 161*0Sstevel@tonic-gate adr_short(&adr, &e_type, 1); /* event ID */ 162*0Sstevel@tonic-gate adr_short(&adr, &e_mod, 1); /* event ID modifier */ 163*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&host_info->at_type, 1); 164*0Sstevel@tonic-gate adr_char(&adr, (char *)host_info->at_addr, 165*0Sstevel@tonic-gate (int)host_info->at_type); 166*0Sstevel@tonic-gate #ifdef _LP64 167*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tv, 2); /* time & date */ 168*0Sstevel@tonic-gate #else 169*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tv, 2); /* time & date */ 170*0Sstevel@tonic-gate #endif 171*0Sstevel@tonic-gate return (token); 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate /* 175*0Sstevel@tonic-gate * au_to_trailer 176*0Sstevel@tonic-gate * return s: 177*0Sstevel@tonic-gate * pointer to a trailer token. 178*0Sstevel@tonic-gate */ 179*0Sstevel@tonic-gate token_t * 180*0Sstevel@tonic-gate au_to_trailer(void) 181*0Sstevel@tonic-gate { 182*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 183*0Sstevel@tonic-gate token_t *token; /* token pointer */ 184*0Sstevel@tonic-gate char data_header = AUT_TRAILER; /* header for this token */ 185*0Sstevel@tonic-gate short magic = (short)AUT_TRAILER_MAGIC; /* trailer magic number */ 186*0Sstevel@tonic-gate int32_t byte_count; 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int32_t) + sizeof (short)); 189*0Sstevel@tonic-gate if (token == NULL) 190*0Sstevel@tonic-gate return (NULL); 191*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 192*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); /* token ID */ 193*0Sstevel@tonic-gate adr_short(&adr, &magic, 1); /* magic number */ 194*0Sstevel@tonic-gate adr_int32(&adr, &byte_count, 1); /* length of audit record */ 195*0Sstevel@tonic-gate 196*0Sstevel@tonic-gate return (token); 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate /* 200*0Sstevel@tonic-gate * au_to_arg32 201*0Sstevel@tonic-gate * return s: 202*0Sstevel@tonic-gate * pointer to an argument token. 203*0Sstevel@tonic-gate */ 204*0Sstevel@tonic-gate token_t * 205*0Sstevel@tonic-gate au_to_arg32(char n, char *text, uint32_t v) 206*0Sstevel@tonic-gate { 207*0Sstevel@tonic-gate token_t *token; /* local token */ 208*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 209*0Sstevel@tonic-gate char data_header = AUT_ARG32; /* header for this token */ 210*0Sstevel@tonic-gate short bytes; /* length of string */ 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate bytes = strlen(text) + 1; 213*0Sstevel@tonic-gate 214*0Sstevel@tonic-gate token = get_token((int)(2 * sizeof (char) + sizeof (int32_t) + 215*0Sstevel@tonic-gate sizeof (short) + bytes)); 216*0Sstevel@tonic-gate if (token == NULL) 217*0Sstevel@tonic-gate return (NULL); 218*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 219*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); /* token type */ 220*0Sstevel@tonic-gate adr_char(&adr, &n, 1); /* argument id */ 221*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&v, 1); /* argument value */ 222*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 223*0Sstevel@tonic-gate adr_char(&adr, text, bytes); 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate return (token); 226*0Sstevel@tonic-gate } 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate /* 229*0Sstevel@tonic-gate * au_to_arg64 230*0Sstevel@tonic-gate * return s: 231*0Sstevel@tonic-gate * pointer to an argument token. 232*0Sstevel@tonic-gate */ 233*0Sstevel@tonic-gate token_t * 234*0Sstevel@tonic-gate au_to_arg64(char n, char *text, uint64_t v) 235*0Sstevel@tonic-gate { 236*0Sstevel@tonic-gate token_t *token; /* local token */ 237*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 238*0Sstevel@tonic-gate char data_header = AUT_ARG64; /* header for this token */ 239*0Sstevel@tonic-gate short bytes; /* length of string */ 240*0Sstevel@tonic-gate 241*0Sstevel@tonic-gate bytes = strlen(text) + 1; 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate token = get_token((int)(2 * sizeof (char) + sizeof (int64_t) + 244*0Sstevel@tonic-gate sizeof (short) + bytes)); 245*0Sstevel@tonic-gate if (token == NULL) 246*0Sstevel@tonic-gate return (NULL); 247*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 248*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); /* token type */ 249*0Sstevel@tonic-gate adr_char(&adr, &n, 1); /* argument id */ 250*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&v, 1); /* argument value */ 251*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 252*0Sstevel@tonic-gate adr_char(&adr, text, bytes); 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate return (token); 255*0Sstevel@tonic-gate } 256*0Sstevel@tonic-gate 257*0Sstevel@tonic-gate 258*0Sstevel@tonic-gate /* 259*0Sstevel@tonic-gate * au_to_attr 260*0Sstevel@tonic-gate * return s: 261*0Sstevel@tonic-gate * pointer to an attribute token. 262*0Sstevel@tonic-gate */ 263*0Sstevel@tonic-gate token_t * 264*0Sstevel@tonic-gate au_to_attr(struct vattr *attr) 265*0Sstevel@tonic-gate { 266*0Sstevel@tonic-gate token_t *token; /* local token */ 267*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 268*0Sstevel@tonic-gate int32_t value; 269*0Sstevel@tonic-gate #ifdef _LP64 270*0Sstevel@tonic-gate char data_header = AUT_ATTR64; /* header for this token */ 271*0Sstevel@tonic-gate 272*0Sstevel@tonic-gate token = get_token(sizeof (char) + 273*0Sstevel@tonic-gate sizeof (int32_t) * 4 + 274*0Sstevel@tonic-gate sizeof (int64_t) * 2); 275*0Sstevel@tonic-gate #else 276*0Sstevel@tonic-gate char data_header = AUT_ATTR32; 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int32_t) * 5 + 279*0Sstevel@tonic-gate sizeof (int64_t)); 280*0Sstevel@tonic-gate #endif 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate if (token == NULL) 283*0Sstevel@tonic-gate return (NULL); 284*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 285*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 286*0Sstevel@tonic-gate value = (int32_t)attr->va_mode; 287*0Sstevel@tonic-gate adr_int32(&adr, &value, 1); 288*0Sstevel@tonic-gate value = (int32_t)attr->va_uid; 289*0Sstevel@tonic-gate adr_int32(&adr, &value, 1); 290*0Sstevel@tonic-gate value = (int32_t)attr->va_gid; 291*0Sstevel@tonic-gate adr_int32(&adr, &value, 1); 292*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&(attr->va_fsid), 1); 293*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&(attr->va_nodeid), 1); 294*0Sstevel@tonic-gate #ifdef _LP64 295*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&(attr->va_rdev), 1); 296*0Sstevel@tonic-gate #else 297*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&(attr->va_rdev), 1); 298*0Sstevel@tonic-gate #endif 299*0Sstevel@tonic-gate 300*0Sstevel@tonic-gate return (token); 301*0Sstevel@tonic-gate } 302*0Sstevel@tonic-gate 303*0Sstevel@tonic-gate /* 304*0Sstevel@tonic-gate * au_to_data 305*0Sstevel@tonic-gate * return s: 306*0Sstevel@tonic-gate * pointer to a data token. 307*0Sstevel@tonic-gate */ 308*0Sstevel@tonic-gate token_t * 309*0Sstevel@tonic-gate au_to_data(char unit_print, char unit_type, char unit_count, char *p) 310*0Sstevel@tonic-gate { 311*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 312*0Sstevel@tonic-gate token_t *token; /* token pointer */ 313*0Sstevel@tonic-gate char data_header = AUT_DATA; /* header for this token */ 314*0Sstevel@tonic-gate int byte_count; /* number of bytes */ 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate if (p == NULL || unit_count < 1) 317*0Sstevel@tonic-gate return (NULL); 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate /* 320*0Sstevel@tonic-gate * Check validity of print type 321*0Sstevel@tonic-gate */ 322*0Sstevel@tonic-gate if (unit_print < AUP_BINARY || unit_print > AUP_STRING) 323*0Sstevel@tonic-gate return (NULL); 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate switch (unit_type) { 326*0Sstevel@tonic-gate case AUR_SHORT: 327*0Sstevel@tonic-gate byte_count = unit_count * sizeof (short); 328*0Sstevel@tonic-gate break; 329*0Sstevel@tonic-gate case AUR_INT32: 330*0Sstevel@tonic-gate byte_count = unit_count * sizeof (int32_t); 331*0Sstevel@tonic-gate break; 332*0Sstevel@tonic-gate case AUR_INT64: 333*0Sstevel@tonic-gate byte_count = unit_count * sizeof (int64_t); 334*0Sstevel@tonic-gate break; 335*0Sstevel@tonic-gate /* case AUR_CHAR: */ 336*0Sstevel@tonic-gate case AUR_BYTE: 337*0Sstevel@tonic-gate byte_count = unit_count * sizeof (char); 338*0Sstevel@tonic-gate break; 339*0Sstevel@tonic-gate default: 340*0Sstevel@tonic-gate return (NULL); 341*0Sstevel@tonic-gate } 342*0Sstevel@tonic-gate 343*0Sstevel@tonic-gate token = get_token((int)(4 * sizeof (char) + byte_count)); 344*0Sstevel@tonic-gate if (token == NULL) 345*0Sstevel@tonic-gate return (NULL); 346*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 347*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 348*0Sstevel@tonic-gate adr_char(&adr, &unit_print, 1); 349*0Sstevel@tonic-gate adr_char(&adr, &unit_type, 1); 350*0Sstevel@tonic-gate adr_char(&adr, &unit_count, 1); 351*0Sstevel@tonic-gate 352*0Sstevel@tonic-gate switch (unit_type) { 353*0Sstevel@tonic-gate case AUR_SHORT: 354*0Sstevel@tonic-gate /* LINTED */ 355*0Sstevel@tonic-gate adr_short(&adr, (short *)p, unit_count); 356*0Sstevel@tonic-gate break; 357*0Sstevel@tonic-gate case AUR_INT32: 358*0Sstevel@tonic-gate /* LINTED */ 359*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)p, unit_count); 360*0Sstevel@tonic-gate break; 361*0Sstevel@tonic-gate case AUR_INT64: 362*0Sstevel@tonic-gate /* LINTED */ 363*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)p, unit_count); 364*0Sstevel@tonic-gate break; 365*0Sstevel@tonic-gate /* case AUR_CHAR: */ 366*0Sstevel@tonic-gate case AUR_BYTE: 367*0Sstevel@tonic-gate adr_char(&adr, p, unit_count); 368*0Sstevel@tonic-gate break; 369*0Sstevel@tonic-gate } 370*0Sstevel@tonic-gate 371*0Sstevel@tonic-gate return (token); 372*0Sstevel@tonic-gate } 373*0Sstevel@tonic-gate 374*0Sstevel@tonic-gate /* 375*0Sstevel@tonic-gate * au_to_privset 376*0Sstevel@tonic-gate * 377*0Sstevel@tonic-gate * priv_type (LIMIT, INHERIT...) is the first string and privilege 378*0Sstevel@tonic-gate * in translated into the second string. The format is as follows: 379*0Sstevel@tonic-gate * 380*0Sstevel@tonic-gate * token id adr_char 381*0Sstevel@tonic-gate * priv type adr_string (short, string) 382*0Sstevel@tonic-gate * priv set adr_string (short, string) 383*0Sstevel@tonic-gate * 384*0Sstevel@tonic-gate * return s: 385*0Sstevel@tonic-gate * pointer to a AUT_PRIV token. 386*0Sstevel@tonic-gate */ 387*0Sstevel@tonic-gate token_t * 388*0Sstevel@tonic-gate au_to_privset(const char *priv_type, const priv_set_t *privilege) 389*0Sstevel@tonic-gate { 390*0Sstevel@tonic-gate token_t *token; /* local token */ 391*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 392*0Sstevel@tonic-gate char data_header = AUT_PRIV; /* header for this token */ 393*0Sstevel@tonic-gate short t_bytes; /* length of type string */ 394*0Sstevel@tonic-gate short p_bytes; /* length of privilege string */ 395*0Sstevel@tonic-gate char *priv_string; /* privilege string */ 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate t_bytes = strlen(priv_type) + 1; 398*0Sstevel@tonic-gate 399*0Sstevel@tonic-gate if ((privilege == NULL) || (priv_string = 400*0Sstevel@tonic-gate priv_set_to_str(privilege, ',', 401*0Sstevel@tonic-gate PRIV_STR_LIT)) == NULL) 402*0Sstevel@tonic-gate return (NULL); 403*0Sstevel@tonic-gate 404*0Sstevel@tonic-gate p_bytes = strlen(priv_string) + 1; 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + (2 * sizeof (short)) + t_bytes 407*0Sstevel@tonic-gate + p_bytes)); 408*0Sstevel@tonic-gate if (token == NULL) 409*0Sstevel@tonic-gate return (NULL); 410*0Sstevel@tonic-gate 411*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 412*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 413*0Sstevel@tonic-gate adr_short(&adr, &t_bytes, 1); 414*0Sstevel@tonic-gate adr_char(&adr, (char *)priv_type, t_bytes); 415*0Sstevel@tonic-gate adr_short(&adr, &p_bytes, 1); 416*0Sstevel@tonic-gate adr_char(&adr, priv_string, p_bytes); 417*0Sstevel@tonic-gate 418*0Sstevel@tonic-gate free(priv_string); 419*0Sstevel@tonic-gate 420*0Sstevel@tonic-gate return (token); 421*0Sstevel@tonic-gate } 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate /* 424*0Sstevel@tonic-gate * au_to_process 425*0Sstevel@tonic-gate * return s: 426*0Sstevel@tonic-gate * pointer to a process token. 427*0Sstevel@tonic-gate */ 428*0Sstevel@tonic-gate 429*0Sstevel@tonic-gate token_t * 430*0Sstevel@tonic-gate au_to_process(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, 431*0Sstevel@tonic-gate pid_t pid, au_asid_t sid, au_tid_t *tid) 432*0Sstevel@tonic-gate { 433*0Sstevel@tonic-gate token_t *token; /* local token */ 434*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 435*0Sstevel@tonic-gate #ifdef _LP64 436*0Sstevel@tonic-gate char data_header = AUT_PROCESS64; /* header for this token */ 437*0Sstevel@tonic-gate 438*0Sstevel@tonic-gate token = get_token(sizeof (char) + 8 * sizeof (int32_t) + 439*0Sstevel@tonic-gate sizeof (int64_t)); 440*0Sstevel@tonic-gate #else 441*0Sstevel@tonic-gate char data_header = AUT_PROCESS32; 442*0Sstevel@tonic-gate 443*0Sstevel@tonic-gate token = get_token(sizeof (char) + 9 * sizeof (int32_t)); 444*0Sstevel@tonic-gate #endif 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate if (token == NULL) 447*0Sstevel@tonic-gate return (NULL); 448*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 449*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 450*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&auid, 1); 451*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&euid, 1); 452*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&egid, 1); 453*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&ruid, 1); 454*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&rgid, 1); 455*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&pid, 1); 456*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&sid, 1); 457*0Sstevel@tonic-gate #ifdef _LP64 458*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tid->port, 1); 459*0Sstevel@tonic-gate #else 460*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->port, 1); 461*0Sstevel@tonic-gate #endif 462*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->machine, 1); 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate return (token); 465*0Sstevel@tonic-gate } 466*0Sstevel@tonic-gate 467*0Sstevel@tonic-gate /* 468*0Sstevel@tonic-gate * au_to_process_ex 469*0Sstevel@tonic-gate * return s: 470*0Sstevel@tonic-gate * pointer to a process_ex token. 471*0Sstevel@tonic-gate */ 472*0Sstevel@tonic-gate token_t * 473*0Sstevel@tonic-gate au_to_process_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, 474*0Sstevel@tonic-gate pid_t pid, au_asid_t sid, au_tid_addr_t *tid) 475*0Sstevel@tonic-gate { 476*0Sstevel@tonic-gate token_t *token; /* local token */ 477*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 478*0Sstevel@tonic-gate char data_header; /* header for this token */ 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gate #ifdef _LP64 481*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 482*0Sstevel@tonic-gate data_header = AUT_PROCESS64_EX; 483*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int64_t) + 484*0Sstevel@tonic-gate 12 * sizeof (int32_t)); 485*0Sstevel@tonic-gate } else { 486*0Sstevel@tonic-gate data_header = AUT_PROCESS64; 487*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int64_t) + 488*0Sstevel@tonic-gate 8 * sizeof (int32_t)); 489*0Sstevel@tonic-gate } 490*0Sstevel@tonic-gate #else 491*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 492*0Sstevel@tonic-gate data_header = AUT_PROCESS32_EX; 493*0Sstevel@tonic-gate token = get_token(sizeof (char) + 13 * sizeof (int32_t)); 494*0Sstevel@tonic-gate } else { 495*0Sstevel@tonic-gate data_header = AUT_PROCESS32; 496*0Sstevel@tonic-gate token = get_token(sizeof (char) + 9 * sizeof (int32_t)); 497*0Sstevel@tonic-gate } 498*0Sstevel@tonic-gate #endif 499*0Sstevel@tonic-gate if (token == NULL) 500*0Sstevel@tonic-gate return (NULL); 501*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 502*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 503*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&auid, 1); 504*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&euid, 1); 505*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&egid, 1); 506*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&ruid, 1); 507*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&rgid, 1); 508*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&pid, 1); 509*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&sid, 1); 510*0Sstevel@tonic-gate #ifdef _LP64 511*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tid->at_port, 1); 512*0Sstevel@tonic-gate #else 513*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->at_port, 1); 514*0Sstevel@tonic-gate #endif 515*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 516*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->at_type, 1); 517*0Sstevel@tonic-gate adr_char(&adr, (char *)tid->at_addr, 16); 518*0Sstevel@tonic-gate } else { 519*0Sstevel@tonic-gate adr_char(&adr, (char *)tid->at_addr, 4); 520*0Sstevel@tonic-gate } 521*0Sstevel@tonic-gate 522*0Sstevel@tonic-gate return (token); 523*0Sstevel@tonic-gate } 524*0Sstevel@tonic-gate 525*0Sstevel@tonic-gate /* 526*0Sstevel@tonic-gate * au_to_seq 527*0Sstevel@tonic-gate * return s: 528*0Sstevel@tonic-gate * pointer to token chain containing a sequence token 529*0Sstevel@tonic-gate */ 530*0Sstevel@tonic-gate token_t * 531*0Sstevel@tonic-gate au_to_seq(int audit_count) 532*0Sstevel@tonic-gate { 533*0Sstevel@tonic-gate token_t *token; /* local token */ 534*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 535*0Sstevel@tonic-gate char data_header = AUT_SEQ; /* header for this token */ 536*0Sstevel@tonic-gate 537*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int32_t)); 538*0Sstevel@tonic-gate if (token == NULL) 539*0Sstevel@tonic-gate return (NULL); 540*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 541*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 542*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&audit_count, 1); 543*0Sstevel@tonic-gate 544*0Sstevel@tonic-gate return (token); 545*0Sstevel@tonic-gate } 546*0Sstevel@tonic-gate 547*0Sstevel@tonic-gate /* 548*0Sstevel@tonic-gate * au_to_socket 549*0Sstevel@tonic-gate * return s: 550*0Sstevel@tonic-gate * pointer to mbuf chain containing a socket token. 551*0Sstevel@tonic-gate */ 552*0Sstevel@tonic-gate token_t * 553*0Sstevel@tonic-gate au_to_socket(struct oldsocket *so) 554*0Sstevel@tonic-gate { 555*0Sstevel@tonic-gate adr_t adr; 556*0Sstevel@tonic-gate token_t *token; 557*0Sstevel@tonic-gate char data_header = AUT_SOCKET; 558*0Sstevel@tonic-gate struct inpcb *inp = so->so_pcb; 559*0Sstevel@tonic-gate 560*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (short) * 3 + 561*0Sstevel@tonic-gate sizeof (int32_t) * 2); 562*0Sstevel@tonic-gate if (token == NULL) 563*0Sstevel@tonic-gate return (NULL); 564*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 565*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 566*0Sstevel@tonic-gate adr_short(&adr, (short *)&so->so_type, 1); 567*0Sstevel@tonic-gate adr_short(&adr, (short *)&inp->inp_lport, 1); 568*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&inp->inp_laddr, 1); 569*0Sstevel@tonic-gate adr_short(&adr, (short *)&inp->inp_fport, 1); 570*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&inp->inp_faddr, 1); 571*0Sstevel@tonic-gate 572*0Sstevel@tonic-gate return (token); 573*0Sstevel@tonic-gate } 574*0Sstevel@tonic-gate 575*0Sstevel@tonic-gate /* 576*0Sstevel@tonic-gate * au_to_subject 577*0Sstevel@tonic-gate * return s: 578*0Sstevel@tonic-gate * pointer to a process token. 579*0Sstevel@tonic-gate */ 580*0Sstevel@tonic-gate 581*0Sstevel@tonic-gate token_t * 582*0Sstevel@tonic-gate au_to_subject(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, 583*0Sstevel@tonic-gate pid_t pid, au_asid_t sid, au_tid_t *tid) 584*0Sstevel@tonic-gate { 585*0Sstevel@tonic-gate token_t *token; /* local token */ 586*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 587*0Sstevel@tonic-gate #ifdef _LP64 588*0Sstevel@tonic-gate char data_header = AUT_SUBJECT64; /* header for this token */ 589*0Sstevel@tonic-gate 590*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int64_t) + 591*0Sstevel@tonic-gate 8 * sizeof (int32_t)); 592*0Sstevel@tonic-gate #else 593*0Sstevel@tonic-gate char data_header = AUT_SUBJECT32; 594*0Sstevel@tonic-gate 595*0Sstevel@tonic-gate token = get_token(sizeof (char) + 9 * sizeof (int32_t)); 596*0Sstevel@tonic-gate #endif 597*0Sstevel@tonic-gate 598*0Sstevel@tonic-gate if (token == NULL) 599*0Sstevel@tonic-gate return (NULL); 600*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 601*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 602*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&auid, 1); 603*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&euid, 1); 604*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&egid, 1); 605*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&ruid, 1); 606*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&rgid, 1); 607*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&pid, 1); 608*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&sid, 1); 609*0Sstevel@tonic-gate #ifdef _LP64 610*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tid->port, 1); 611*0Sstevel@tonic-gate #else 612*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->port, 1); 613*0Sstevel@tonic-gate #endif 614*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->machine, 1); 615*0Sstevel@tonic-gate 616*0Sstevel@tonic-gate return (token); 617*0Sstevel@tonic-gate } 618*0Sstevel@tonic-gate 619*0Sstevel@tonic-gate /* 620*0Sstevel@tonic-gate * au_to_subject_ex 621*0Sstevel@tonic-gate * return s: 622*0Sstevel@tonic-gate * pointer to a process token. 623*0Sstevel@tonic-gate */ 624*0Sstevel@tonic-gate 625*0Sstevel@tonic-gate token_t * 626*0Sstevel@tonic-gate au_to_subject_ex(au_id_t auid, uid_t euid, gid_t egid, uid_t ruid, gid_t rgid, 627*0Sstevel@tonic-gate pid_t pid, au_asid_t sid, au_tid_addr_t *tid) 628*0Sstevel@tonic-gate { 629*0Sstevel@tonic-gate token_t *token; /* local token */ 630*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 631*0Sstevel@tonic-gate #ifdef _LP64 632*0Sstevel@tonic-gate char data_header; /* header for this token */ 633*0Sstevel@tonic-gate 634*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 635*0Sstevel@tonic-gate data_header = AUT_SUBJECT64_EX; 636*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int64_t) + 637*0Sstevel@tonic-gate 12 * sizeof (int32_t)); 638*0Sstevel@tonic-gate } else { 639*0Sstevel@tonic-gate data_header = AUT_SUBJECT64; 640*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int64_t) + 641*0Sstevel@tonic-gate 8 * sizeof (int32_t)); 642*0Sstevel@tonic-gate } 643*0Sstevel@tonic-gate #else 644*0Sstevel@tonic-gate char data_header; /* header for this token */ 645*0Sstevel@tonic-gate 646*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 647*0Sstevel@tonic-gate data_header = AUT_SUBJECT32_EX; 648*0Sstevel@tonic-gate token = get_token(sizeof (char) + 13 * sizeof (int32_t)); 649*0Sstevel@tonic-gate } else { 650*0Sstevel@tonic-gate data_header = AUT_SUBJECT32; 651*0Sstevel@tonic-gate token = get_token(sizeof (char) + 9 * sizeof (int32_t)); 652*0Sstevel@tonic-gate } 653*0Sstevel@tonic-gate #endif 654*0Sstevel@tonic-gate 655*0Sstevel@tonic-gate if (token == NULL) 656*0Sstevel@tonic-gate return (NULL); 657*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 658*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 659*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&auid, 1); 660*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&euid, 1); 661*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&egid, 1); 662*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&ruid, 1); 663*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&rgid, 1); 664*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&pid, 1); 665*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&sid, 1); 666*0Sstevel@tonic-gate #ifdef _LP64 667*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&tid->at_port, 1); 668*0Sstevel@tonic-gate #else 669*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->at_port, 1); 670*0Sstevel@tonic-gate #endif 671*0Sstevel@tonic-gate if (tid->at_type == AU_IPv6) { 672*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&tid->at_type, 1); 673*0Sstevel@tonic-gate adr_char(&adr, (char *)tid->at_addr, 16); 674*0Sstevel@tonic-gate } else { 675*0Sstevel@tonic-gate adr_char(&adr, (char *)tid->at_addr, 4); 676*0Sstevel@tonic-gate } 677*0Sstevel@tonic-gate 678*0Sstevel@tonic-gate return (token); 679*0Sstevel@tonic-gate } 680*0Sstevel@tonic-gate 681*0Sstevel@tonic-gate /* 682*0Sstevel@tonic-gate * au_to_me 683*0Sstevel@tonic-gate * return s: 684*0Sstevel@tonic-gate * pointer to a process token. 685*0Sstevel@tonic-gate */ 686*0Sstevel@tonic-gate 687*0Sstevel@tonic-gate token_t * 688*0Sstevel@tonic-gate au_to_me(void) 689*0Sstevel@tonic-gate { 690*0Sstevel@tonic-gate auditinfo_addr_t info; 691*0Sstevel@tonic-gate 692*0Sstevel@tonic-gate if (getaudit_addr(&info, sizeof (info))) 693*0Sstevel@tonic-gate return (NULL); 694*0Sstevel@tonic-gate return (au_to_subject_ex(info.ai_auid, geteuid(), getegid(), getuid(), 695*0Sstevel@tonic-gate getgid(), getpid(), info.ai_asid, &info.ai_termid)); 696*0Sstevel@tonic-gate } 697*0Sstevel@tonic-gate /* 698*0Sstevel@tonic-gate * au_to_text 699*0Sstevel@tonic-gate * return s: 700*0Sstevel@tonic-gate * pointer to a text token. 701*0Sstevel@tonic-gate */ 702*0Sstevel@tonic-gate token_t * 703*0Sstevel@tonic-gate au_to_text(char *text) 704*0Sstevel@tonic-gate { 705*0Sstevel@tonic-gate token_t *token; /* local token */ 706*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 707*0Sstevel@tonic-gate char data_header = AUT_TEXT; /* header for this token */ 708*0Sstevel@tonic-gate short bytes; /* length of string */ 709*0Sstevel@tonic-gate 710*0Sstevel@tonic-gate bytes = strlen(text) + 1; 711*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) + bytes)); 712*0Sstevel@tonic-gate if (token == NULL) 713*0Sstevel@tonic-gate return (NULL); 714*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 715*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 716*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 717*0Sstevel@tonic-gate adr_char(&adr, text, bytes); 718*0Sstevel@tonic-gate 719*0Sstevel@tonic-gate return (token); 720*0Sstevel@tonic-gate } 721*0Sstevel@tonic-gate 722*0Sstevel@tonic-gate /* 723*0Sstevel@tonic-gate * au_to_path 724*0Sstevel@tonic-gate * return s: 725*0Sstevel@tonic-gate * pointer to a path token. 726*0Sstevel@tonic-gate */ 727*0Sstevel@tonic-gate token_t * 728*0Sstevel@tonic-gate au_to_path(char *path) 729*0Sstevel@tonic-gate { 730*0Sstevel@tonic-gate token_t *token; /* local token */ 731*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 732*0Sstevel@tonic-gate char data_header = AUT_PATH; /* header for this token */ 733*0Sstevel@tonic-gate short bytes; /* length of string */ 734*0Sstevel@tonic-gate 735*0Sstevel@tonic-gate bytes = (short)strlen(path) + 1; 736*0Sstevel@tonic-gate 737*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) + bytes)); 738*0Sstevel@tonic-gate if (token == NULL) 739*0Sstevel@tonic-gate return (NULL); 740*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 741*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 742*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 743*0Sstevel@tonic-gate adr_char(&adr, path, bytes); 744*0Sstevel@tonic-gate 745*0Sstevel@tonic-gate return (token); 746*0Sstevel@tonic-gate } 747*0Sstevel@tonic-gate 748*0Sstevel@tonic-gate /* 749*0Sstevel@tonic-gate * au_to_cmd 750*0Sstevel@tonic-gate * return s: 751*0Sstevel@tonic-gate * pointer to an command line argument token 752*0Sstevel@tonic-gate */ 753*0Sstevel@tonic-gate token_t * 754*0Sstevel@tonic-gate au_to_cmd(uint_t argc, char **argv, char **envp) 755*0Sstevel@tonic-gate { 756*0Sstevel@tonic-gate token_t *token; /* local token */ 757*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 758*0Sstevel@tonic-gate char data_header = AUT_CMD; /* header for this token */ 759*0Sstevel@tonic-gate short len = 0; 760*0Sstevel@tonic-gate short cnt = 0; 761*0Sstevel@tonic-gate short envc = 0; 762*0Sstevel@tonic-gate short largc = (short)argc; 763*0Sstevel@tonic-gate 764*0Sstevel@tonic-gate /* 765*0Sstevel@tonic-gate * one char for the header, one short for argc, 766*0Sstevel@tonic-gate * one short for # envp strings. 767*0Sstevel@tonic-gate */ 768*0Sstevel@tonic-gate len = sizeof (char) + sizeof (short) + sizeof (short); 769*0Sstevel@tonic-gate 770*0Sstevel@tonic-gate /* get sizes of strings */ 771*0Sstevel@tonic-gate 772*0Sstevel@tonic-gate for (cnt = 0; cnt < argc; cnt++) { 773*0Sstevel@tonic-gate len += (short)sizeof (short) + (short)(strlen(argv[cnt]) + 1); 774*0Sstevel@tonic-gate } 775*0Sstevel@tonic-gate 776*0Sstevel@tonic-gate if (envp != NULL) { 777*0Sstevel@tonic-gate for (envc = 0; envp[envc] != NULL; envc++) { 778*0Sstevel@tonic-gate len += (short)sizeof (short) + 779*0Sstevel@tonic-gate (short)(strlen(envp[envc]) + 1); 780*0Sstevel@tonic-gate } 781*0Sstevel@tonic-gate } 782*0Sstevel@tonic-gate 783*0Sstevel@tonic-gate token = get_token(len); 784*0Sstevel@tonic-gate if (token == NULL) 785*0Sstevel@tonic-gate return (NULL); 786*0Sstevel@tonic-gate 787*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 788*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 789*0Sstevel@tonic-gate 790*0Sstevel@tonic-gate adr_short(&adr, &largc, 1); 791*0Sstevel@tonic-gate 792*0Sstevel@tonic-gate for (cnt = 0; cnt < argc; cnt++) { 793*0Sstevel@tonic-gate len = (short)(strlen(argv[cnt]) + 1); 794*0Sstevel@tonic-gate adr_short(&adr, &len, 1); 795*0Sstevel@tonic-gate adr_char(&adr, argv[cnt], len); 796*0Sstevel@tonic-gate } 797*0Sstevel@tonic-gate 798*0Sstevel@tonic-gate adr_short(&adr, &envc, 1); 799*0Sstevel@tonic-gate 800*0Sstevel@tonic-gate for (cnt = 0; cnt < envc; cnt++) { 801*0Sstevel@tonic-gate len = (short)(strlen(envp[cnt]) + 1); 802*0Sstevel@tonic-gate adr_short(&adr, &len, 1); 803*0Sstevel@tonic-gate adr_char(&adr, envp[cnt], len); 804*0Sstevel@tonic-gate } 805*0Sstevel@tonic-gate 806*0Sstevel@tonic-gate return (token); 807*0Sstevel@tonic-gate } 808*0Sstevel@tonic-gate 809*0Sstevel@tonic-gate /* 810*0Sstevel@tonic-gate * au_to_exit 811*0Sstevel@tonic-gate * return s: 812*0Sstevel@tonic-gate * pointer to a exit value token. 813*0Sstevel@tonic-gate */ 814*0Sstevel@tonic-gate token_t * 815*0Sstevel@tonic-gate au_to_exit(int retval, int err) 816*0Sstevel@tonic-gate { 817*0Sstevel@tonic-gate token_t *token; /* local token */ 818*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 819*0Sstevel@tonic-gate char data_header = AUT_EXIT; /* header for this token */ 820*0Sstevel@tonic-gate 821*0Sstevel@tonic-gate token = get_token(sizeof (char) + (2 * sizeof (int32_t))); 822*0Sstevel@tonic-gate if (token == NULL) 823*0Sstevel@tonic-gate return (NULL); 824*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 825*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 826*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&retval, 1); 827*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&err, 1); 828*0Sstevel@tonic-gate 829*0Sstevel@tonic-gate return (token); 830*0Sstevel@tonic-gate } 831*0Sstevel@tonic-gate 832*0Sstevel@tonic-gate /* 833*0Sstevel@tonic-gate * au_to_return 834*0Sstevel@tonic-gate * return s: 835*0Sstevel@tonic-gate * pointer to a return value token. 836*0Sstevel@tonic-gate */ 837*0Sstevel@tonic-gate token_t * 838*0Sstevel@tonic-gate au_to_return32(char number, uint32_t value) 839*0Sstevel@tonic-gate { 840*0Sstevel@tonic-gate token_t *token; /* local token */ 841*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 842*0Sstevel@tonic-gate char data_header = AUT_RETURN32; /* header for this token */ 843*0Sstevel@tonic-gate 844*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + sizeof (int32_t)); 845*0Sstevel@tonic-gate if (token == NULL) 846*0Sstevel@tonic-gate return (NULL); 847*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 848*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 849*0Sstevel@tonic-gate adr_char(&adr, &number, 1); 850*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&value, 1); 851*0Sstevel@tonic-gate 852*0Sstevel@tonic-gate return (token); 853*0Sstevel@tonic-gate } 854*0Sstevel@tonic-gate 855*0Sstevel@tonic-gate /* 856*0Sstevel@tonic-gate * au_to_return 857*0Sstevel@tonic-gate * return s: 858*0Sstevel@tonic-gate * pointer to a return value token. 859*0Sstevel@tonic-gate */ 860*0Sstevel@tonic-gate token_t * 861*0Sstevel@tonic-gate au_to_return64(char number, uint64_t value) 862*0Sstevel@tonic-gate { 863*0Sstevel@tonic-gate token_t *token; /* local token */ 864*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 865*0Sstevel@tonic-gate char data_header = AUT_RETURN64; /* header for this token */ 866*0Sstevel@tonic-gate 867*0Sstevel@tonic-gate token = get_token(2 * sizeof (char) + sizeof (int64_t)); 868*0Sstevel@tonic-gate if (token == NULL) 869*0Sstevel@tonic-gate return (NULL); 870*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 871*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 872*0Sstevel@tonic-gate adr_char(&adr, &number, 1); 873*0Sstevel@tonic-gate adr_int64(&adr, (int64_t *)&value, 1); 874*0Sstevel@tonic-gate 875*0Sstevel@tonic-gate return (token); 876*0Sstevel@tonic-gate } 877*0Sstevel@tonic-gate 878*0Sstevel@tonic-gate 879*0Sstevel@tonic-gate /* 880*0Sstevel@tonic-gate * au_to_opaque 881*0Sstevel@tonic-gate * return s: 882*0Sstevel@tonic-gate * pointer to a opaque token. 883*0Sstevel@tonic-gate */ 884*0Sstevel@tonic-gate token_t * 885*0Sstevel@tonic-gate au_to_opaque(char *opaque, short bytes) 886*0Sstevel@tonic-gate { 887*0Sstevel@tonic-gate token_t *token; /* local token */ 888*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 889*0Sstevel@tonic-gate char data_header = AUT_OPAQUE; /* header for this token */ 890*0Sstevel@tonic-gate 891*0Sstevel@tonic-gate if (bytes < 1) 892*0Sstevel@tonic-gate return (NULL); 893*0Sstevel@tonic-gate 894*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) + bytes)); 895*0Sstevel@tonic-gate if (token == NULL) 896*0Sstevel@tonic-gate return (NULL); 897*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 898*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 899*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 900*0Sstevel@tonic-gate adr_char(&adr, opaque, bytes); 901*0Sstevel@tonic-gate 902*0Sstevel@tonic-gate return (token); 903*0Sstevel@tonic-gate } 904*0Sstevel@tonic-gate 905*0Sstevel@tonic-gate /* 906*0Sstevel@tonic-gate * au_to_in_addr 907*0Sstevel@tonic-gate * return s: 908*0Sstevel@tonic-gate * pointer to a internet address token 909*0Sstevel@tonic-gate */ 910*0Sstevel@tonic-gate token_t * 911*0Sstevel@tonic-gate au_to_in_addr(struct in_addr *internet_addr) 912*0Sstevel@tonic-gate { 913*0Sstevel@tonic-gate token_t *token; /* local token */ 914*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 915*0Sstevel@tonic-gate char data_header = AUT_IN_ADDR; /* header for this token */ 916*0Sstevel@tonic-gate 917*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (uint32_t)); 918*0Sstevel@tonic-gate if (token == NULL) 919*0Sstevel@tonic-gate return (NULL); 920*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 921*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 922*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)internet_addr, 1); 923*0Sstevel@tonic-gate 924*0Sstevel@tonic-gate return (token); 925*0Sstevel@tonic-gate } 926*0Sstevel@tonic-gate 927*0Sstevel@tonic-gate /* 928*0Sstevel@tonic-gate * au_to_iport 929*0Sstevel@tonic-gate * return s: 930*0Sstevel@tonic-gate * pointer to token chain containing a ip port address token 931*0Sstevel@tonic-gate */ 932*0Sstevel@tonic-gate token_t * 933*0Sstevel@tonic-gate au_to_iport(ushort_t iport) 934*0Sstevel@tonic-gate { 935*0Sstevel@tonic-gate token_t *token; /* local token */ 936*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 937*0Sstevel@tonic-gate char data_header = AUT_IPORT; /* header for this token */ 938*0Sstevel@tonic-gate 939*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (short)); 940*0Sstevel@tonic-gate if (token == NULL) 941*0Sstevel@tonic-gate return (NULL); 942*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 943*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 944*0Sstevel@tonic-gate adr_short(&adr, (short *)&iport, 1); 945*0Sstevel@tonic-gate 946*0Sstevel@tonic-gate return (token); 947*0Sstevel@tonic-gate } 948*0Sstevel@tonic-gate 949*0Sstevel@tonic-gate token_t * 950*0Sstevel@tonic-gate au_to_ipc(char type, int id) 951*0Sstevel@tonic-gate { 952*0Sstevel@tonic-gate token_t *token; /* local token */ 953*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 954*0Sstevel@tonic-gate char data_header = AUT_IPC; /* header for this token */ 955*0Sstevel@tonic-gate 956*0Sstevel@tonic-gate token = get_token((2 * sizeof (char)) + sizeof (int32_t)); 957*0Sstevel@tonic-gate if (token == NULL) 958*0Sstevel@tonic-gate return (NULL); 959*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 960*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 961*0Sstevel@tonic-gate adr_char(&adr, &type, 1); 962*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&id, 1); 963*0Sstevel@tonic-gate 964*0Sstevel@tonic-gate return (token); 965*0Sstevel@tonic-gate } 966*0Sstevel@tonic-gate 967*0Sstevel@tonic-gate /* 968*0Sstevel@tonic-gate * au_to_tid 969*0Sstevel@tonic-gate * 970*0Sstevel@tonic-gate * output format depends on type; at present only IP v4 and v6 addresses 971*0Sstevel@tonic-gate * are defined. 972*0Sstevel@tonic-gate * 973*0Sstevel@tonic-gate * IPv4 -- tid type, 16 bit remote port, 16 bit local port, ip type, 974*0Sstevel@tonic-gate * 32 bit IP address. 975*0Sstevel@tonic-gate * IPv6 -- tid type, 16 bit remote port, 16 bit local port, ip type, 976*0Sstevel@tonic-gate * 4 x 32 bit IP address. 977*0Sstevel@tonic-gate * 978*0Sstevel@tonic-gate */ 979*0Sstevel@tonic-gate token_t * 980*0Sstevel@tonic-gate au_to_tid(au_generic_tid_t *tid) 981*0Sstevel@tonic-gate { 982*0Sstevel@tonic-gate char data_header = AUT_TID; /* header for this token */ 983*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 984*0Sstevel@tonic-gate token_t *token; /* local token */ 985*0Sstevel@tonic-gate au_ip_t *ip; 986*0Sstevel@tonic-gate 987*0Sstevel@tonic-gate switch (tid->gt_type) { 988*0Sstevel@tonic-gate case AU_IPADR: 989*0Sstevel@tonic-gate ip = &(tid->gt_adr.at_ip); 990*0Sstevel@tonic-gate token = get_token((int)(2 * sizeof (char) + 2 * sizeof (short) + 991*0Sstevel@tonic-gate sizeof (uint32_t) + ip->at_type)); 992*0Sstevel@tonic-gate if (token == NULL) 993*0Sstevel@tonic-gate return (NULL); 994*0Sstevel@tonic-gate 995*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 996*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 997*0Sstevel@tonic-gate adr_char(&adr, (char *)&(tid->gt_type), 1); 998*0Sstevel@tonic-gate adr_short(&adr, (short *)&(ip->at_r_port), 1); 999*0Sstevel@tonic-gate adr_short(&adr, (short *)&(ip->at_l_port), 1); 1000*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&(ip->at_type), 1); 1001*0Sstevel@tonic-gate 1002*0Sstevel@tonic-gate adr_char(&adr, (char *)ip->at_addr, ip->at_type); 1003*0Sstevel@tonic-gate 1004*0Sstevel@tonic-gate break; 1005*0Sstevel@tonic-gate default: 1006*0Sstevel@tonic-gate return (NULL); 1007*0Sstevel@tonic-gate } 1008*0Sstevel@tonic-gate return (token); 1009*0Sstevel@tonic-gate } 1010*0Sstevel@tonic-gate 1011*0Sstevel@tonic-gate /* 1012*0Sstevel@tonic-gate * The Modifier tokens 1013*0Sstevel@tonic-gate */ 1014*0Sstevel@tonic-gate 1015*0Sstevel@tonic-gate /* 1016*0Sstevel@tonic-gate * au_to_groups 1017*0Sstevel@tonic-gate * return s: 1018*0Sstevel@tonic-gate * pointer to a group list token. 1019*0Sstevel@tonic-gate * 1020*0Sstevel@tonic-gate * This function is obsolete. Please use au_to_newgroups. 1021*0Sstevel@tonic-gate */ 1022*0Sstevel@tonic-gate token_t * 1023*0Sstevel@tonic-gate au_to_groups(int *groups) 1024*0Sstevel@tonic-gate { 1025*0Sstevel@tonic-gate token_t *token; /* local token */ 1026*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1027*0Sstevel@tonic-gate char data_header = AUT_GROUPS; /* header for this token */ 1028*0Sstevel@tonic-gate 1029*0Sstevel@tonic-gate token = get_token(sizeof (char) + NGROUPS * sizeof (int32_t)); 1030*0Sstevel@tonic-gate if (token == NULL) 1031*0Sstevel@tonic-gate return (NULL); 1032*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1033*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1034*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)groups, NGROUPS); 1035*0Sstevel@tonic-gate 1036*0Sstevel@tonic-gate return (token); 1037*0Sstevel@tonic-gate } 1038*0Sstevel@tonic-gate 1039*0Sstevel@tonic-gate /* 1040*0Sstevel@tonic-gate * au_to_newgroups 1041*0Sstevel@tonic-gate * return s: 1042*0Sstevel@tonic-gate * pointer to a group list token. 1043*0Sstevel@tonic-gate */ 1044*0Sstevel@tonic-gate token_t * 1045*0Sstevel@tonic-gate au_to_newgroups(int n, gid_t *groups) 1046*0Sstevel@tonic-gate { 1047*0Sstevel@tonic-gate token_t *token; /* local token */ 1048*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1049*0Sstevel@tonic-gate char data_header = AUT_NEWGROUPS; /* header for this token */ 1050*0Sstevel@tonic-gate short n_groups; 1051*0Sstevel@tonic-gate 1052*0Sstevel@tonic-gate if (n < NGROUPS_UMIN || n > NGROUPS_UMAX || groups == NULL) 1053*0Sstevel@tonic-gate return (NULL); 1054*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (short) + n * sizeof (gid_t)); 1055*0Sstevel@tonic-gate if (token == NULL) 1056*0Sstevel@tonic-gate return (NULL); 1057*0Sstevel@tonic-gate n_groups = (short)n; 1058*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1059*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1060*0Sstevel@tonic-gate adr_short(&adr, &n_groups, 1); 1061*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)groups, n_groups); 1062*0Sstevel@tonic-gate 1063*0Sstevel@tonic-gate return (token); 1064*0Sstevel@tonic-gate } 1065*0Sstevel@tonic-gate 1066*0Sstevel@tonic-gate /* 1067*0Sstevel@tonic-gate * au_to_exec_args 1068*0Sstevel@tonic-gate * returns: 1069*0Sstevel@tonic-gate * pointer to an exec args token. 1070*0Sstevel@tonic-gate */ 1071*0Sstevel@tonic-gate token_t * 1072*0Sstevel@tonic-gate au_to_exec_args(char **argv) 1073*0Sstevel@tonic-gate { 1074*0Sstevel@tonic-gate return (au_to_exec(argv, AUT_EXEC_ARGS)); 1075*0Sstevel@tonic-gate } 1076*0Sstevel@tonic-gate 1077*0Sstevel@tonic-gate /* 1078*0Sstevel@tonic-gate * au_to_exec_env 1079*0Sstevel@tonic-gate * returns: 1080*0Sstevel@tonic-gate * pointer to an exec args token. 1081*0Sstevel@tonic-gate */ 1082*0Sstevel@tonic-gate token_t * 1083*0Sstevel@tonic-gate au_to_exec_env(char **envp) 1084*0Sstevel@tonic-gate { 1085*0Sstevel@tonic-gate return (au_to_exec(envp, AUT_EXEC_ENV)); 1086*0Sstevel@tonic-gate } 1087*0Sstevel@tonic-gate 1088*0Sstevel@tonic-gate /* 1089*0Sstevel@tonic-gate * au_to_exec 1090*0Sstevel@tonic-gate * returns: 1091*0Sstevel@tonic-gate * pointer to an exec args token. 1092*0Sstevel@tonic-gate */ 1093*0Sstevel@tonic-gate static token_t * 1094*0Sstevel@tonic-gate au_to_exec(char **v, char data_header) 1095*0Sstevel@tonic-gate { 1096*0Sstevel@tonic-gate token_t *token; 1097*0Sstevel@tonic-gate adr_t adr; 1098*0Sstevel@tonic-gate char **p; 1099*0Sstevel@tonic-gate int32_t n = 0; 1100*0Sstevel@tonic-gate int len = 0; 1101*0Sstevel@tonic-gate 1102*0Sstevel@tonic-gate for (p = v; *p != NULL; p++) { 1103*0Sstevel@tonic-gate len += strlen(*p) + 1; 1104*0Sstevel@tonic-gate n++; 1105*0Sstevel@tonic-gate } 1106*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int32_t) + len); 1107*0Sstevel@tonic-gate if (token == (token_t *)NULL) 1108*0Sstevel@tonic-gate return ((token_t *)NULL); 1109*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1110*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1111*0Sstevel@tonic-gate adr_int32(&adr, &n, 1); 1112*0Sstevel@tonic-gate for (p = v; *p != NULL; p++) { 1113*0Sstevel@tonic-gate adr_char(&adr, *p, strlen(*p) + 1); 1114*0Sstevel@tonic-gate } 1115*0Sstevel@tonic-gate return (token); 1116*0Sstevel@tonic-gate } 1117*0Sstevel@tonic-gate 1118*0Sstevel@tonic-gate /* 1119*0Sstevel@tonic-gate * au_to_uauth 1120*0Sstevel@tonic-gate * return s: 1121*0Sstevel@tonic-gate * pointer to a uauth token. 1122*0Sstevel@tonic-gate */ 1123*0Sstevel@tonic-gate token_t * 1124*0Sstevel@tonic-gate au_to_uauth(char *text) 1125*0Sstevel@tonic-gate { 1126*0Sstevel@tonic-gate token_t *token; /* local token */ 1127*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1128*0Sstevel@tonic-gate char data_header = AUT_UAUTH; /* header for this token */ 1129*0Sstevel@tonic-gate short bytes; /* length of string */ 1130*0Sstevel@tonic-gate 1131*0Sstevel@tonic-gate bytes = strlen(text) + 1; 1132*0Sstevel@tonic-gate 1133*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) + bytes)); 1134*0Sstevel@tonic-gate if (token == NULL) 1135*0Sstevel@tonic-gate return (NULL); 1136*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1137*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1138*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 1139*0Sstevel@tonic-gate adr_char(&adr, text, bytes); 1140*0Sstevel@tonic-gate 1141*0Sstevel@tonic-gate return (token); 1142*0Sstevel@tonic-gate } 1143*0Sstevel@tonic-gate 1144*0Sstevel@tonic-gate /* 1145*0Sstevel@tonic-gate * au_to_xatom 1146*0Sstevel@tonic-gate * return s: 1147*0Sstevel@tonic-gate * pointer to a xatom token. 1148*0Sstevel@tonic-gate */ 1149*0Sstevel@tonic-gate token_t * 1150*0Sstevel@tonic-gate au_to_xatom(ushort_t len, char *atom) 1151*0Sstevel@tonic-gate { 1152*0Sstevel@tonic-gate token_t *token; /* local token */ 1153*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1154*0Sstevel@tonic-gate char data_header = AUT_XATOM; /* header for this token */ 1155*0Sstevel@tonic-gate 1156*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (ushort_t) + len)); 1157*0Sstevel@tonic-gate if (token == NULL) 1158*0Sstevel@tonic-gate return (NULL); 1159*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1160*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1161*0Sstevel@tonic-gate adr_short(&adr, (short *)&len, 1); 1162*0Sstevel@tonic-gate adr_char(&adr, atom, len); 1163*0Sstevel@tonic-gate 1164*0Sstevel@tonic-gate return (token); 1165*0Sstevel@tonic-gate } 1166*0Sstevel@tonic-gate 1167*0Sstevel@tonic-gate /* 1168*0Sstevel@tonic-gate * au_to_xproto 1169*0Sstevel@tonic-gate * return s: 1170*0Sstevel@tonic-gate * pointer to a X protocol token. 1171*0Sstevel@tonic-gate */ 1172*0Sstevel@tonic-gate token_t * 1173*0Sstevel@tonic-gate au_to_xproto(pid_t pid) 1174*0Sstevel@tonic-gate { 1175*0Sstevel@tonic-gate token_t *token; /* local token */ 1176*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1177*0Sstevel@tonic-gate char data_header = AUT_XPROTO; /* header for this token */ 1178*0Sstevel@tonic-gate int32_t v = pid; 1179*0Sstevel@tonic-gate 1180*0Sstevel@tonic-gate token = get_token(sizeof (char) + sizeof (int32_t)); 1181*0Sstevel@tonic-gate if (token == NULL) 1182*0Sstevel@tonic-gate return (NULL); 1183*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1184*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1185*0Sstevel@tonic-gate adr_int32(&adr, &v, 1); 1186*0Sstevel@tonic-gate 1187*0Sstevel@tonic-gate return (token); 1188*0Sstevel@tonic-gate } 1189*0Sstevel@tonic-gate 1190*0Sstevel@tonic-gate /* 1191*0Sstevel@tonic-gate * au_to_xobj 1192*0Sstevel@tonic-gate * return s: 1193*0Sstevel@tonic-gate * pointer to a X object token. 1194*0Sstevel@tonic-gate */ 1195*0Sstevel@tonic-gate token_t * 1196*0Sstevel@tonic-gate au_to_xobj(int oid, int xid, int cuid) 1197*0Sstevel@tonic-gate { 1198*0Sstevel@tonic-gate token_t *token; /* local token */ 1199*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1200*0Sstevel@tonic-gate char data_header = AUT_XOBJ; /* header for this token */ 1201*0Sstevel@tonic-gate 1202*0Sstevel@tonic-gate token = get_token(sizeof (char) + 3 * sizeof (int32_t)); 1203*0Sstevel@tonic-gate if (token == NULL) 1204*0Sstevel@tonic-gate return (NULL); 1205*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1206*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1207*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&oid, 1); 1208*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&xid, 1); 1209*0Sstevel@tonic-gate adr_int32(&adr, (int32_t *)&cuid, 1); 1210*0Sstevel@tonic-gate 1211*0Sstevel@tonic-gate return (token); 1212*0Sstevel@tonic-gate } 1213*0Sstevel@tonic-gate 1214*0Sstevel@tonic-gate /* 1215*0Sstevel@tonic-gate * au_to_xselect 1216*0Sstevel@tonic-gate * return s: 1217*0Sstevel@tonic-gate * pointer to a X select token. 1218*0Sstevel@tonic-gate */ 1219*0Sstevel@tonic-gate token_t * 1220*0Sstevel@tonic-gate au_to_xselect(char *pstring, char *type, short dlen, char *data) 1221*0Sstevel@tonic-gate { 1222*0Sstevel@tonic-gate token_t *token; /* local token */ 1223*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1224*0Sstevel@tonic-gate char data_header = AUT_XSELECT; /* header for this token */ 1225*0Sstevel@tonic-gate short bytes; 1226*0Sstevel@tonic-gate 1227*0Sstevel@tonic-gate bytes = strlen(pstring) + strlen(type) + 2 + dlen; 1228*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) * 3 + bytes)); 1229*0Sstevel@tonic-gate if (token == NULL) 1230*0Sstevel@tonic-gate return (NULL); 1231*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1232*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1233*0Sstevel@tonic-gate bytes = strlen(pstring) + 1; 1234*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 1235*0Sstevel@tonic-gate adr_char(&adr, pstring, bytes); 1236*0Sstevel@tonic-gate bytes = strlen(type) + 1; 1237*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 1238*0Sstevel@tonic-gate adr_char(&adr, type, bytes); 1239*0Sstevel@tonic-gate adr_short(&adr, &dlen, 1); 1240*0Sstevel@tonic-gate adr_char(&adr, data, dlen); 1241*0Sstevel@tonic-gate return (token); 1242*0Sstevel@tonic-gate } 1243*0Sstevel@tonic-gate 1244*0Sstevel@tonic-gate /* 1245*0Sstevel@tonic-gate * au_to_zonename 1246*0Sstevel@tonic-gate * return s: 1247*0Sstevel@tonic-gate * pointer to a zonename token. 1248*0Sstevel@tonic-gate */ 1249*0Sstevel@tonic-gate token_t * 1250*0Sstevel@tonic-gate au_to_zonename(char *name) 1251*0Sstevel@tonic-gate { 1252*0Sstevel@tonic-gate token_t *token; /* local token */ 1253*0Sstevel@tonic-gate adr_t adr; /* adr memory stream header */ 1254*0Sstevel@tonic-gate char data_header = AUT_ZONENAME; /* header for this token */ 1255*0Sstevel@tonic-gate short bytes; /* length of string */ 1256*0Sstevel@tonic-gate 1257*0Sstevel@tonic-gate if (name == NULL) 1258*0Sstevel@tonic-gate return (NULL); 1259*0Sstevel@tonic-gate 1260*0Sstevel@tonic-gate bytes = strlen(name) + 1; 1261*0Sstevel@tonic-gate token = get_token((int)(sizeof (char) + sizeof (short) + bytes)); 1262*0Sstevel@tonic-gate if (token == NULL) 1263*0Sstevel@tonic-gate return (NULL); 1264*0Sstevel@tonic-gate adr_start(&adr, token->tt_data); 1265*0Sstevel@tonic-gate adr_char(&adr, &data_header, 1); 1266*0Sstevel@tonic-gate adr_short(&adr, &bytes, 1); 1267*0Sstevel@tonic-gate adr_char(&adr, name, bytes); 1268*0Sstevel@tonic-gate 1269*0Sstevel@tonic-gate return (token); 1270*0Sstevel@tonic-gate } 1271