1*45916cd2Sjpk /* 2*45916cd2Sjpk * CDDL HEADER START 3*45916cd2Sjpk * 4*45916cd2Sjpk * The contents of this file are subject to the terms of the 5*45916cd2Sjpk * Common Development and Distribution License (the "License"). 6*45916cd2Sjpk * You may not use this file except in compliance with the License. 7*45916cd2Sjpk * 8*45916cd2Sjpk * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*45916cd2Sjpk * or http://www.opensolaris.org/os/licensing. 10*45916cd2Sjpk * See the License for the specific language governing permissions 11*45916cd2Sjpk * and limitations under the License. 12*45916cd2Sjpk * 13*45916cd2Sjpk * When distributing Covered Code, include this CDDL HEADER in each 14*45916cd2Sjpk * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*45916cd2Sjpk * If applicable, add the following below this CDDL HEADER, with the 16*45916cd2Sjpk * fields enclosed by brackets "[]" replaced with your own identifying 17*45916cd2Sjpk * information: Portions Copyright [yyyy] [name of copyright owner] 18*45916cd2Sjpk * 19*45916cd2Sjpk * CDDL HEADER END 20*45916cd2Sjpk */ 21*45916cd2Sjpk /* 22*45916cd2Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*45916cd2Sjpk * Use is subject to license terms. 24*45916cd2Sjpk */ 25*45916cd2Sjpk 26*45916cd2Sjpk #pragma ident "%Z%%M% %I% %E% SMI" 27*45916cd2Sjpk 28*45916cd2Sjpk #include <errno.h> 29*45916cd2Sjpk #include <priv.h> 30*45916cd2Sjpk #include <sys/tsol/priv.h> 31*45916cd2Sjpk #include <sys/varargs.h> 32*45916cd2Sjpk 33*45916cd2Sjpk /* 34*45916cd2Sjpk * set_effective_priv(op, num_priv, priv_id1, priv_id2, ... ) 35*45916cd2Sjpk * 36*45916cd2Sjpk * Library routine to enable a user process to set its effective 37*45916cd2Sjpk * privilege set appropriately using a single call. User is 38*45916cd2Sjpk * required to specify the number of privilege ids that follow as 39*45916cd2Sjpk * arguments, rather than depending on the compiler to terminate 40*45916cd2Sjpk * the argument list with a NULL, which may be compiler-dependent. 41*45916cd2Sjpk */ 42*45916cd2Sjpk int 43*45916cd2Sjpk set_effective_priv(priv_op_t op, int num_priv, ...) 44*45916cd2Sjpk { 45*45916cd2Sjpk priv_set_t *priv_set; 46*45916cd2Sjpk priv_t priv_id; 47*45916cd2Sjpk va_list ap; 48*45916cd2Sjpk int status; 49*45916cd2Sjpk 50*45916cd2Sjpk priv_set = priv_allocset(); 51*45916cd2Sjpk PRIV_EMPTY(priv_set); 52*45916cd2Sjpk 53*45916cd2Sjpk va_start(ap, num_priv); 54*45916cd2Sjpk while (num_priv--) { 55*45916cd2Sjpk char *priv_name; 56*45916cd2Sjpk /* 57*45916cd2Sjpk * Do sanity checking on priv_id's here to assure 58*45916cd2Sjpk * valid inputs to privilege macros. This checks 59*45916cd2Sjpk * num_priv argument as well. 60*45916cd2Sjpk */ 61*45916cd2Sjpk priv_id = va_arg(ap, priv_t); 62*45916cd2Sjpk priv_name = (char *)priv_getbynum((int)(uintptr_t)priv_id); 63*45916cd2Sjpk if (priv_name == NULL) { 64*45916cd2Sjpk errno = EINVAL; 65*45916cd2Sjpk priv_freeset(priv_set); 66*45916cd2Sjpk return (-1); 67*45916cd2Sjpk } 68*45916cd2Sjpk (void) priv_addset(priv_set, priv_name); 69*45916cd2Sjpk } 70*45916cd2Sjpk va_end(ap); 71*45916cd2Sjpk 72*45916cd2Sjpk /* 73*45916cd2Sjpk * Depend on system call to do sanity checking on "op" 74*45916cd2Sjpk */ 75*45916cd2Sjpk status = setppriv(op, PRIV_EFFECTIVE, priv_set); 76*45916cd2Sjpk priv_freeset(priv_set); 77*45916cd2Sjpk return (status); 78*45916cd2Sjpk 79*45916cd2Sjpk } /* set_effective_priv() */ 80*45916cd2Sjpk 81*45916cd2Sjpk 82*45916cd2Sjpk 83*45916cd2Sjpk 84*45916cd2Sjpk /* 85*45916cd2Sjpk * set_inheritable_priv(op, num_priv, priv_id1, priv_id2, ... ) 86*45916cd2Sjpk * 87*45916cd2Sjpk * Library routine to enable a user process to set its inheritable 88*45916cd2Sjpk * privilege set appropriately using a single call. User is 89*45916cd2Sjpk * required to specify the number of privilege ids that follow as 90*45916cd2Sjpk * arguments, rather than depending on the compiler to terminate 91*45916cd2Sjpk * the argument list with a NULL, which may be compiler-dependent. 92*45916cd2Sjpk */ 93*45916cd2Sjpk int 94*45916cd2Sjpk set_inheritable_priv(priv_op_t op, int num_priv, ...) 95*45916cd2Sjpk { 96*45916cd2Sjpk priv_set_t *priv_set; 97*45916cd2Sjpk priv_t priv_id; 98*45916cd2Sjpk va_list ap; 99*45916cd2Sjpk int status; 100*45916cd2Sjpk 101*45916cd2Sjpk priv_set = priv_allocset(); 102*45916cd2Sjpk 103*45916cd2Sjpk PRIV_EMPTY(priv_set); 104*45916cd2Sjpk 105*45916cd2Sjpk va_start(ap, num_priv); 106*45916cd2Sjpk while (num_priv--) { 107*45916cd2Sjpk /* 108*45916cd2Sjpk * Do sanity checking on priv_id's here to assure 109*45916cd2Sjpk * valid inputs to privilege macros. This checks 110*45916cd2Sjpk * num_priv argument as well. 111*45916cd2Sjpk */ 112*45916cd2Sjpk priv_id = va_arg(ap, priv_t); 113*45916cd2Sjpk if ((char *)priv_getbynum((int)(uintptr_t)priv_id) == NULL) { 114*45916cd2Sjpk errno = EINVAL; 115*45916cd2Sjpk priv_freeset(priv_set); 116*45916cd2Sjpk return (-1); 117*45916cd2Sjpk } 118*45916cd2Sjpk (void) PRIV_ASSERT(priv_set, priv_id); 119*45916cd2Sjpk } 120*45916cd2Sjpk va_end(ap); 121*45916cd2Sjpk 122*45916cd2Sjpk /* 123*45916cd2Sjpk * Depend on system call to do sanity checking on "op" 124*45916cd2Sjpk */ 125*45916cd2Sjpk status = setppriv(op, PRIV_INHERITABLE, priv_set); 126*45916cd2Sjpk priv_freeset(priv_set); 127*45916cd2Sjpk return (status); 128*45916cd2Sjpk 129*45916cd2Sjpk } /* set_inheritable_priv() */ 130*45916cd2Sjpk 131*45916cd2Sjpk 132*45916cd2Sjpk 133*45916cd2Sjpk 134*45916cd2Sjpk /* 135*45916cd2Sjpk * set_permitted_priv(op, num_priv, priv_id1, priv_id2, ... ) 136*45916cd2Sjpk * 137*45916cd2Sjpk * Library routine to enable a user process to set its permitted 138*45916cd2Sjpk * privilege set appropriately using a single call. User is 139*45916cd2Sjpk * required to specify the number of privilege ids that follow as 140*45916cd2Sjpk * arguments, rather than depending on the compiler to terminate 141*45916cd2Sjpk * the argument list with a NULL, which may be compiler-dependent. 142*45916cd2Sjpk */ 143*45916cd2Sjpk int 144*45916cd2Sjpk set_permitted_priv(priv_op_t op, int num_priv, ...) 145*45916cd2Sjpk { 146*45916cd2Sjpk priv_set_t *priv_set; 147*45916cd2Sjpk priv_t priv_id; 148*45916cd2Sjpk va_list ap; 149*45916cd2Sjpk int status; 150*45916cd2Sjpk 151*45916cd2Sjpk priv_set = priv_allocset(); 152*45916cd2Sjpk 153*45916cd2Sjpk PRIV_EMPTY(priv_set); 154*45916cd2Sjpk 155*45916cd2Sjpk va_start(ap, num_priv); 156*45916cd2Sjpk while (num_priv--) { 157*45916cd2Sjpk /* 158*45916cd2Sjpk * Do sanity checking on priv_id's here to assure 159*45916cd2Sjpk * valid inputs to privilege macros. This checks 160*45916cd2Sjpk * num_priv argument as well. 161*45916cd2Sjpk */ 162*45916cd2Sjpk priv_id = va_arg(ap, priv_t); 163*45916cd2Sjpk if ((char *)priv_getbynum((int)(uintptr_t)priv_id) == NULL) { 164*45916cd2Sjpk errno = EINVAL; 165*45916cd2Sjpk priv_freeset(priv_set); 166*45916cd2Sjpk return (-1); 167*45916cd2Sjpk } 168*45916cd2Sjpk (void) PRIV_ASSERT(priv_set, priv_id); 169*45916cd2Sjpk } 170*45916cd2Sjpk va_end(ap); 171*45916cd2Sjpk 172*45916cd2Sjpk /* 173*45916cd2Sjpk * Depend on system call to do sanity checking on "op" 174*45916cd2Sjpk */ 175*45916cd2Sjpk status = setppriv(op, PRIV_PERMITTED, priv_set); 176*45916cd2Sjpk priv_freeset(priv_set); 177*45916cd2Sjpk return (status); 178*45916cd2Sjpk 179*45916cd2Sjpk } /* set_permitted_priv() */ 180