xref: /onnv-gate/usr/src/lib/libtsol/common/private.c (revision 2664:e5ed3b6cf1db)
11676Sjpk /*
21676Sjpk  * CDDL HEADER START
31676Sjpk  *
41676Sjpk  * The contents of this file are subject to the terms of the
51676Sjpk  * Common Development and Distribution License (the "License").
61676Sjpk  * You may not use this file except in compliance with the License.
71676Sjpk  *
81676Sjpk  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91676Sjpk  * or http://www.opensolaris.org/os/licensing.
101676Sjpk  * See the License for the specific language governing permissions
111676Sjpk  * and limitations under the License.
121676Sjpk  *
131676Sjpk  * When distributing Covered Code, include this CDDL HEADER in each
141676Sjpk  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151676Sjpk  * If applicable, add the following below this CDDL HEADER, with the
161676Sjpk  * fields enclosed by brackets "[]" replaced with your own identifying
171676Sjpk  * information: Portions Copyright [yyyy] [name of copyright owner]
181676Sjpk  *
191676Sjpk  * CDDL HEADER END
201676Sjpk  */
211676Sjpk /*
221676Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
231676Sjpk  * Use is subject to license terms.
241676Sjpk  */
251676Sjpk 
261676Sjpk #pragma ident	"%Z%%M%	%I%	%E% SMI"
271676Sjpk 
281676Sjpk /*
291676Sjpk  *	Label library contract private interfaces.
301676Sjpk  *
311676Sjpk  *	Binary labels to String labels with dimming word lists.
321676Sjpk  *	Dimming word list titles.
331676Sjpk  *	Default user labels.
341676Sjpk  */
351676Sjpk 
361676Sjpk #include <locale.h>
371676Sjpk #include <stdlib.h>
381676Sjpk #include <stdio.h>
391676Sjpk #include <strings.h>
401676Sjpk 
411676Sjpk #include <sys/mman.h>
421676Sjpk 
431676Sjpk #include <tsol/label.h>
441676Sjpk 
451676Sjpk #include "clnt.h"
461676Sjpk #include "labeld.h"
471676Sjpk 
481676Sjpk /*
491676Sjpk  *	cvt memory:
501676Sjpk  *
511676Sjpk  * cvt:	char	*long_words[display_size];	Pointers to long words
521676Sjpk  *	char	*short_words[display_size];	Pointers to short words
531676Sjpk  * dim:	char	display[display_size];		Dim | Set
541676Sjpk  *
551676Sjpk  *	    strings associated with long and short words.
561676Sjpk  *
571676Sjpk  */
581676Sjpk 
591676Sjpk /*
601676Sjpk  *	Sensitivity Label words.
611676Sjpk  */
621676Sjpk 
631676Sjpk static	char *slcvt = NULL;
641676Sjpk static	int   slcvtsize = 0;
651676Sjpk static	char *sldim;
661676Sjpk 
671676Sjpk static	char *slstring = NULL;
681676Sjpk static	int   slstringsize = 0;
691676Sjpk static	brange_t sbounds;
701676Sjpk 
711676Sjpk /*
721676Sjpk  *	Clearance words.
731676Sjpk  */
741676Sjpk 
751676Sjpk static	char *clrcvt = NULL;
761676Sjpk static	int   clrcvtsize = 0;
771676Sjpk static	char *clrdim;
781676Sjpk 
791676Sjpk static	char *clrstring = NULL;
801676Sjpk static	int   clrstringsize = 0;
811676Sjpk static	brange_t cbounds;
821676Sjpk 
831676Sjpk static
841676Sjpk int
alloc_words(char ** words,const size_t size)851676Sjpk alloc_words(char **words, const size_t size)
861676Sjpk {
871676Sjpk 	if (*words == NULL) {
881676Sjpk 		if ((*words = malloc(size)) == NULL)
891676Sjpk 			return (0);
901676Sjpk 	} else {
911676Sjpk 		if ((*words = realloc(*words, size)) == NULL) {
921676Sjpk 			return (0);
931676Sjpk 		}
941676Sjpk 	}
951676Sjpk 	return (1);
961676Sjpk }
971676Sjpk 
981676Sjpk /*
991676Sjpk  *	build_strings - Build the static strings and dimming list for a
1001676Sjpk  *			converted label.
1011676Sjpk  *
1021676Sjpk  *	Entry	new_string = Newly converted string.
1031676Sjpk  *		new_words_size = Size of words associated with newly converted
1041676Sjpk  *				 label.
1051676Sjpk  *		number_of_words = Number of words associated with newly
1061676Sjpk  *				  converted label.
1071676Sjpk  *		full =	1, if static words lists to be updated.
1081676Sjpk  *			0, if only string and dimming list to be updated.
1091676Sjpk  *
1101676Sjpk  *	Exit	static_string_size = Updated if needed.
1111676Sjpk  *		static_string = Updated to new label string.
1121676Sjpk  *		static_words_size = Updated if needed.
1131676Sjpk  *		static_words = Updated to new words list, if needed.
1141676Sjpk  *		static_dimming = Updated to new dimming state.
1151676Sjpk  *		long_words = Updated to new long words pointers, if needed.
1161676Sjpk  *		short_words = Updated to new short words pointers, if needed.
1171676Sjpk  *
1181676Sjpk  *
1191676Sjpk  *	Returns	0, If unable to allocate memory.
1201676Sjpk  *		1, If successful.
1211676Sjpk  *
1221676Sjpk  *	Calls	alloc_string, alloc_words, memcpy, strcpy, strlen.
1231676Sjpk  */
1241676Sjpk 
1251676Sjpk static
1261676Sjpk int
build_strings(int * static_string_size,char ** static_string,char * new_string,int * static_words_size,int new_words_size,char ** static_words,char ** static_dimming,int number_of_words,char * long_words,char * short_words,char * dimming_list,int full)1271676Sjpk build_strings(int *static_string_size, char **static_string, char *new_string,
1281676Sjpk     int *static_words_size, int new_words_size, char **static_words,
1291676Sjpk     char **static_dimming, int number_of_words, char *long_words,
1301676Sjpk     char *short_words, char *dimming_list, int full)
1311676Sjpk {
1321676Sjpk 	char	**l;
1331676Sjpk 	char	**s;
1341676Sjpk 	char	*w;
1351676Sjpk 	char	*l_w = long_words;
1361676Sjpk 	char	*s_w = short_words;
1371676Sjpk 	int	i;
1381676Sjpk 	int	len;
1391676Sjpk 	int	newsize;
1401676Sjpk 
1411676Sjpk 	if (*static_string_size == 0) { /* Allocate string memory. */
1421676Sjpk 		if ((*static_string_size = alloc_string(static_string,
1431676Sjpk 		    *static_string_size, 'C')) == 0)
1441676Sjpk 			/* can't get string memory for string */
1451676Sjpk 			return (0);
1461676Sjpk 	}
1471676Sjpk 
1481676Sjpk again:
1491676Sjpk 	if (*static_string_size < (int)strlen(new_string)+1) {
1501676Sjpk 		/* need longer string */
1511676Sjpk 		if ((newsize = alloc_string(static_string, *static_string_size,
1521676Sjpk 		    'C')) == 0)
1531676Sjpk 			/* can't get more string memory */
1541676Sjpk 			return (0);
1551676Sjpk 
1561676Sjpk 		*static_string_size += newsize;
1571676Sjpk 		goto again;
1581676Sjpk 	}
1591676Sjpk 	bcopy(new_string, *static_string, strlen(new_string) + 1);
1601676Sjpk 
1611676Sjpk 	if (full) {
1621676Sjpk 		if (*static_words_size < new_words_size &&
1631676Sjpk 		    !alloc_words(static_words, new_words_size)) {
1641676Sjpk 			/* can't get more words memory */
1651676Sjpk 			return (0);
1661676Sjpk 		} else {
1671676Sjpk 			*static_words_size = new_words_size;
1681676Sjpk 		}
1691676Sjpk 		/*LINTED*/
1701676Sjpk 		l = (char **)*static_words;
1711676Sjpk 		s = l + number_of_words;
1721676Sjpk 		*static_dimming = (char *)(s + number_of_words);
1731676Sjpk 		w = *static_dimming + number_of_words;
1741676Sjpk 		for (i = 0; i < number_of_words; i++) {
1751676Sjpk 			*l = w;
1761676Sjpk 			(void) strcpy(w, l_w);
1771676Sjpk 			w += (len = strlen(l_w) + 1);
1781676Sjpk 			l_w += len;
1791676Sjpk 			if (*s_w == '\000') {
1801676Sjpk 				*s = NULL;
1811676Sjpk 				s_w++;
1821676Sjpk 			} else {
1831676Sjpk 				*s = w;
1841676Sjpk 				(void) strcpy(w, s_w);
1851676Sjpk 				w += (len = strlen(s_w) + 1);
1861676Sjpk 				s_w += len;
1871676Sjpk 			}
1881676Sjpk 
1891676Sjpk 			l++;
1901676Sjpk 			s++;
1911676Sjpk 		}  /* for each word entry */
1921676Sjpk 	}  /* if (full) */
1931676Sjpk 
1941676Sjpk 	bcopy(dimming_list, *static_dimming, number_of_words);
1951676Sjpk 	return (1);
1961676Sjpk }  /* build_strings */
1971676Sjpk 
1981676Sjpk #define	bsfcall callp->param.acall.cargs.bslcvt_arg
1991676Sjpk #define	bsfret callp->param.aret.rvals.bslcvt_ret
2001676Sjpk /*
2011676Sjpk  *	bslcvtfull - Convert Sensitivity Label and initialize static
2021676Sjpk  *			information.
2031676Sjpk  *
2041676Sjpk  *	Entry	label = Sensitivity Label to convert and get dimming list.
2051676Sjpk  *			This label should lie within the bounds or the
2061676Sjpk  *			results may not be meaningful.
2071676Sjpk  *		bounds = Lower and upper bounds for words lists. Must be
2081676Sjpk  *			dominated by clearance.
2091676Sjpk  *		flags = VIEW_INTERNAL, don't promote/demote admin low/high.
2101676Sjpk  *			VIEW_EXTERNAL, promote/demote admin low/high.
2111676Sjpk  *
2121676Sjpk  *	Exit	string = ASCII coded Sensitivity Label.
2131676Sjpk  *		long_words = Array of pointers to visible long word names.
2141676Sjpk  *		short_words = Array of pointers to visible short word names.
2151676Sjpk  *		display = Array of indicators as to whether the word is present
2161676Sjpk  *			  in the converted label (CVT_SET), and/or changeable
2171676Sjpk  *			  (CVT_DIM).
2181676Sjpk  *		first_compartment = Zero based index of first compartment.
2191676Sjpk  *		display_size = Number of entries in the display/words lists.
2201676Sjpk  *
2211676Sjpk  *	Returns	-1, If unable to access label encodings database, or
2221676Sjpk  *			invalid label.
2231676Sjpk  *		 0, If unable to allocate static memory.
2241676Sjpk  *		 1, If successful.
2251676Sjpk  *
2261676Sjpk  *	Calls	RPC - LABELS_BSLCONVERT, STTBLEVEL, SETBSLABEL, TCLNT,
2271676Sjpk  *			build_strings, clnt_call, clnt_perror.
2281676Sjpk  *
2291676Sjpk  *	Uses	sbounds, slrcvt, slrcvtsize, slrdim, slrstring,
2301676Sjpk  *			slrstringsize.
2311676Sjpk  */
2321676Sjpk 
2331676Sjpk int
bslcvtfull(const bslabel_t * label,const blrange_t * bounds,int flags,char ** string,char ** long_words[],char ** short_words[],char * display[],int * first_compartment,int * display_size)2341676Sjpk bslcvtfull(const bslabel_t *label, const blrange_t *bounds, int flags,
2351676Sjpk     char **string, char **long_words[], char **short_words[], char *display[],
2361676Sjpk     int *first_compartment, int *display_size)
2371676Sjpk {
2381676Sjpk 	labeld_data_t	call;
2391676Sjpk 	labeld_data_t	*callp = &call;
2401676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
2411676Sjpk 	size_t	datasize = CALL_SIZE(bslcvt_call_t, 0);
2421676Sjpk 	int	new_words_size;
2431676Sjpk 	int	rval;
2441676Sjpk 
2451676Sjpk 	call.callop = BSLCVT;
2461676Sjpk 	bsfcall.label = *label;
2471676Sjpk 	bsfcall.bounds.upper_bound = *bounds->upper_bound;
2481676Sjpk 	bsfcall.bounds.lower_bound = *bounds->lower_bound;
2491676Sjpk 	bsfcall.flags = LABELS_FULL_CONVERT;
2501676Sjpk 	set_label_view(&bsfcall.flags, flags);
2511676Sjpk 
2521676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) == NOSERVER) {
2531676Sjpk #ifdef	DEBUG
2541676Sjpk 		(void) fprintf(stderr, "No label server.\n");
2551676Sjpk #endif	/* DEBUG */
2561676Sjpk 		return (-1);
2571676Sjpk 	} else if (rval != SUCCESS) {
2581676Sjpk 		return (-1);
2591676Sjpk 	} else {
2601676Sjpk 		if (callp->reterr != 0)
2611676Sjpk 			return (-1);
2621676Sjpk 	}
2631676Sjpk 
2641676Sjpk 	*first_compartment = bsfret.first_comp;
2651676Sjpk 	*display_size = bsfret.d_len;
2661676Sjpk 
2671676Sjpk 	new_words_size = bsfret.l_len + bsfret.s_len + bsfret.d_len +
2681676Sjpk 	    (2 * sizeof (char *)) * bsfret.d_len;
2691676Sjpk 
2701676Sjpk 	if (build_strings(&slstringsize, &slstring, &bsfret.buf[bsfret.string],
2711676Sjpk 	    &slcvtsize, new_words_size, &slcvt, &sldim, bsfret.d_len,
2721676Sjpk 	    &bsfret.buf[bsfret.lwords], &bsfret.buf[bsfret.swords],
2731676Sjpk 	    &bsfret.buf[bsfret.dim], 1) != 1) {
2741676Sjpk 		if (callp != &call)
2751676Sjpk 			/* release return buffer */
2761676Sjpk 			(void) munmap((void *)callp, bufsize);
2771676Sjpk 		return (0);
2781676Sjpk 	}
2791676Sjpk 
2801676Sjpk 	/* save for bslcvt call */
2811676Sjpk 	sbounds.upper_bound = *bounds->upper_bound;
2821676Sjpk 	sbounds.lower_bound = *bounds->lower_bound;
2831676Sjpk 
2841676Sjpk 	*string = slstring;
2851676Sjpk 	*display = sldim;
2861676Sjpk 	/*LINTED*/
2871676Sjpk 	*long_words = (char **)slcvt;
2881676Sjpk 	/*LINTED*/
2891676Sjpk 	*short_words = (char **)(slcvt + *display_size * sizeof (char *));
2901676Sjpk 	if (callp != &call)
2911676Sjpk 		/* release return buffer */
2921676Sjpk 		(void) munmap((void *)callp, bufsize);
2931676Sjpk 	return (1);
2941676Sjpk }  /* bslcvtfull */
2951676Sjpk #undef	bsfcall
2961676Sjpk #undef	bsfret
2971676Sjpk 
2981676Sjpk #define	bsccall callp->param.acall.cargs.bslcvt_arg
2991676Sjpk #define	bscret callp->param.aret.rvals.bslcvt_ret
3001676Sjpk /*
3011676Sjpk  *	bslcvt - Convert Sensitivity Label and update dimming information.
3021676Sjpk  *
3031676Sjpk  *	Entry	label = Sensitivity Label to convert and get dimming list.
3041676Sjpk  *			This label should lie within the bounds of the
3051676Sjpk  *			corresponding bslcvtfull call or the results may
3061676Sjpk  *			not be meaningful.
3071676Sjpk  *		flags = VIEW_INTERNAL, don't promote/demote admin low/high.
3081676Sjpk  *			VIEW_EXTERNAL, promote/demote admin low/high.
3091676Sjpk  *
3101676Sjpk  *	Exit	string = ASCII coded Sensitivity Label.
3111676Sjpk  *		display = Array of indicators as to whether the word is present
3121676Sjpk  *			  in the converted label (CVT_SET), and/or changeable
3131676Sjpk  *			  (CVT_DIM).
3141676Sjpk  *
3151676Sjpk  *	Returns	-1, If unable to access label encodings database, or
3161676Sjpk  *			invalid label.
3171676Sjpk  *		 0, If unable to allocate static memory.
3181676Sjpk  *		 1, If successful.
3191676Sjpk  *
3201676Sjpk  *	Calls	RPC - LABELS_BSLCONVERT, SETBLEVEL, SETBSLABEL, build_strings
3211676Sjpk  *			clnt_call, clnt_perror.
3221676Sjpk  *
3231676Sjpk  *	Uses	sbounds, slrdim, slrstring.
3241676Sjpk  */
3251676Sjpk 
3261676Sjpk int
bslcvt(const bslabel_t * label,int flags,char ** string,char * display[])3271676Sjpk bslcvt(const bslabel_t *label, int flags, char **string, char *display[])
3281676Sjpk {
3291676Sjpk 	labeld_data_t	call;
3301676Sjpk 	labeld_data_t	*callp = &call;
3311676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
3321676Sjpk 	size_t	datasize = CALL_SIZE(bslcvt_call_t, 0);
3331676Sjpk 	int	rval;
3341676Sjpk 
3351676Sjpk 	if (slcvt == NULL)
3361676Sjpk 		return (-1);	/* conversion not initialized */
3371676Sjpk 
3381676Sjpk 	call.callop = BSLCVT;
3391676Sjpk 	bsccall.label = *label;
3401676Sjpk 	bsccall.bounds = sbounds;	/* save from last bslcvtfull() call */
3411676Sjpk 	bsccall.flags = 0;
3421676Sjpk 	set_label_view(&bsccall.flags, flags);
3431676Sjpk 
3441676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) == NOSERVER) {
3451676Sjpk #ifdef	DEBUG
3461676Sjpk 		(void) fprintf(stderr, "No label server.\n");
3471676Sjpk #endif	/* DEBUG */
3481676Sjpk 		return (-1);
3491676Sjpk 	} else if (rval != SUCCESS) {
3501676Sjpk 		return (-1);
3511676Sjpk 	} else {
3521676Sjpk 		if (callp->reterr != 0)
3531676Sjpk 			return (-1);
3541676Sjpk 	}
3551676Sjpk 
3561676Sjpk 	if (build_strings(&slstringsize, &slstring, &bscret.buf[bscret.string],
3571676Sjpk 	    &slcvtsize, 0, &slcvt, &sldim, bscret.d_len,
3581676Sjpk 	    &bscret.buf[bscret.lwords], &bscret.buf[bscret.swords],
3591676Sjpk 	    &bscret.buf[bscret.dim], 0) != 1) {
3601676Sjpk 		if (callp != &call)
3611676Sjpk 			/* release return buffer */
3621676Sjpk 			(void) munmap((void *)callp, bufsize);
3631676Sjpk 		return (0);
3641676Sjpk 	}
3651676Sjpk 
3661676Sjpk 	*string = slstring;
3671676Sjpk 	*display = sldim;
3681676Sjpk 	if (callp != &call)
3691676Sjpk 		/* release return buffer */
3701676Sjpk 		(void) munmap((void *)callp, bufsize);
3711676Sjpk 	return (1);
3721676Sjpk }  /* bslcvt */
3731676Sjpk #undef	bsccall
3741676Sjpk #undef	bscret
3751676Sjpk 
3761676Sjpk #define	bcfcall callp->param.acall.cargs.bclearcvt_arg
3771676Sjpk #define	bcfret callp->param.aret.rvals.bclearcvt_ret
3781676Sjpk /*
3791676Sjpk  *	bclearcvtfull - Convert Clearance and initialize static information.
3801676Sjpk  *
3811676Sjpk  *	Entry	clearance = Clearance to convert and get dimming list.
3821676Sjpk  *			    This clearance should lie within the bounds or
3831676Sjpk  *			    the results may not be meaningful.
3841676Sjpk  *		bounds = Lower and upper bounds for words lists. Must be
3851676Sjpk  *			dominated by clearance.
3861676Sjpk  *		flags = VIEW_INTERNAL, don't promote/demote admin low/high.
3871676Sjpk  *			VIEW_EXTERNAL, promote/demote admin low/high.
3881676Sjpk  *
3891676Sjpk  *	Exit	string = ASCII coded Clearance.
3901676Sjpk  *		long_words = Array of pointers to visible long word names.
3911676Sjpk  *		short_words = Array of pointers to visible short word names.
3921676Sjpk  *		display = Array of indicators as to whether the word is present
3931676Sjpk  *			  in the converted label (CVT_SET), and/or changeable
3941676Sjpk  *			  (CVT_DIM).
3951676Sjpk  *		first_compartment = Zero based index of first compartment.
3961676Sjpk  *		display_size = Number of entries in the display/words lists.
3971676Sjpk  *
3981676Sjpk  *	Returns	-1, If unable to access label encodings database, or
3991676Sjpk  *			invalid label.
4001676Sjpk  *		 0, If unable to allocate static memory.
4011676Sjpk  *		 1, If successful.
4021676Sjpk  *
4031676Sjpk  *	Calls	RPC - LABELS_BCLEARCONVERT, SETBCLEAR, SETBLEVEL, TCLNT,
4041676Sjpk  *			build_strings, clnt_call, clnt_perror.
4051676Sjpk  *
4061676Sjpk  *	Uses	cbounds, clrcvt, clrcvtsize, clrdim, clrstring,
4071676Sjpk  *			clrstringsize.
4081676Sjpk  */
4091676Sjpk 
4101676Sjpk int
bclearcvtfull(const bclear_t * clearance,const blrange_t * bounds,int flags,char ** string,char ** long_words[],char ** short_words[],char * display[],int * first_compartment,int * display_size)4111676Sjpk bclearcvtfull(const bclear_t *clearance, const blrange_t *bounds,
4121676Sjpk     int flags, char **string, char **long_words[], char **short_words[],
4131676Sjpk     char *display[], int *first_compartment, int *display_size)
4141676Sjpk {
4151676Sjpk 	labeld_data_t	call;
4161676Sjpk 	labeld_data_t	*callp = &call;
4171676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
4181676Sjpk 	size_t	datasize = CALL_SIZE(bclearcvt_call_t, 0);
4191676Sjpk 	int	new_words_size;
4201676Sjpk 	int	rval;
4211676Sjpk 
4221676Sjpk 	call.callop = BCLEARCVT;
4231676Sjpk 	bcfcall.clear = *clearance;
4241676Sjpk 	bcfcall.bounds.upper_bound = *bounds->upper_bound;
4251676Sjpk 	bcfcall.bounds.lower_bound = *bounds->lower_bound;
4261676Sjpk 	bcfcall.flags = LABELS_FULL_CONVERT;
4271676Sjpk 	set_label_view(&bcfcall.flags, flags);
4281676Sjpk 
4291676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) == NOSERVER) {
4301676Sjpk #ifdef	DEBUG
4311676Sjpk 		(void) fprintf(stderr, "No label server.\n");
4321676Sjpk #endif	/* DEBUG */
4331676Sjpk 		return (-1);
4341676Sjpk 	} else if (rval != SUCCESS) {
4351676Sjpk 		return (-1);
4361676Sjpk 	} else {
4371676Sjpk 		if (callp->reterr != 0)
4381676Sjpk 			return (-1);
4391676Sjpk 	}
4401676Sjpk 
4411676Sjpk 	*first_compartment = bcfret.first_comp;
4421676Sjpk 	*display_size = bcfret.d_len;
4431676Sjpk 
4441676Sjpk 	new_words_size = bcfret.l_len + bcfret.s_len + bcfret.d_len +
4451676Sjpk 	    (2 * sizeof (char *)) * bcfret.d_len;
4461676Sjpk 
4471676Sjpk 	if (build_strings(&clrstringsize, &clrstring,
4481676Sjpk 	    &bcfret.buf[bcfret.string],
4491676Sjpk 	    &clrcvtsize, new_words_size, &clrcvt,
4501676Sjpk 	    &clrdim, bcfret.d_len,
4511676Sjpk 	    &bcfret.buf[bcfret.lwords], &bcfret.buf[bcfret.swords],
4521676Sjpk 	    &bcfret.buf[bcfret.dim], 1) != 1) {
4531676Sjpk 		if (callp != &call)
4541676Sjpk 			/* release return buffer */
4551676Sjpk 			(void) munmap((void *)callp, bufsize);
4561676Sjpk 		return (0);
4571676Sjpk 	}
4581676Sjpk 
4591676Sjpk 	/* save for bclearcvt call */
4601676Sjpk 	cbounds.upper_bound = *bounds->upper_bound;
4611676Sjpk 	cbounds.lower_bound = *bounds->lower_bound;
4621676Sjpk 
4631676Sjpk 	*string = clrstring;
4641676Sjpk 	*display = clrdim;
4651676Sjpk 	/*LINTED*/
4661676Sjpk 	*long_words = (char **)clrcvt;
4671676Sjpk 	/*LINTED*/
4681676Sjpk 	*short_words = (char **)(clrcvt + *display_size * sizeof (char *));
4691676Sjpk 	if (callp != &call)
4701676Sjpk 		/* release return buffer */
4711676Sjpk 		(void) munmap((void *)callp, bufsize);
4721676Sjpk 	return (1);
4731676Sjpk }  /* bclearcvtfull */
4741676Sjpk #undef	bcfcall
4751676Sjpk #undef	bcfret
4761676Sjpk 
4771676Sjpk #define	bcccall callp->param.acall.cargs.bclearcvt_arg
4781676Sjpk #define	bccret callp->param.aret.rvals.bclearcvt_ret
4791676Sjpk /*
4801676Sjpk  *	bclearcvt - Convert Clearance and update dimming inforamtion.
4811676Sjpk  *
4821676Sjpk  *	Entry	clearance = Clearance to convert and get dimming list.
4831676Sjpk  *			    This clearance should lie within the bounds of the
4841676Sjpk  *			    corresponding bclearcvtfull call or the results may
4851676Sjpk  *			    not be meaningful.
4861676Sjpk  *		flags = VIEW_INTERNAL, don't promote/demote admin low/high.
4871676Sjpk  *			VIEW_EXTERNAL, promote/demote admin low/high.
4881676Sjpk  *
4891676Sjpk  *	Exit	string = ASCII coded Clearance.
4901676Sjpk  *		display = Array of indicators as to whether the word is present
4911676Sjpk  *			  in the converted label (CVT_SET), and/or changeable
4921676Sjpk  *			  (CVT_DIM).
4931676Sjpk  *
4941676Sjpk  *	Returns	-1, If unable to access label encodings database, or
4951676Sjpk  *			invalid label.
4961676Sjpk  *		 0, If unable to allocate static memory.
4971676Sjpk  *		 1, If successful.
4981676Sjpk  *
4991676Sjpk  *	Calls	RPC - LABELS_BCLEARCONVERT, SETBCLEAR, SETBLEVEL, build_strings,
5001676Sjpk  *			clnt_call, clnt_perror.
5011676Sjpk  *
5021676Sjpk  *	Uses	cbounds, clrdim, clrstring.
5031676Sjpk  */
5041676Sjpk 
5051676Sjpk int
bclearcvt(const bclear_t * clearance,int flags,char ** string,char * display[])5061676Sjpk bclearcvt(const bclear_t *clearance, int flags, char **string,
5071676Sjpk     char *display[])
5081676Sjpk {
5091676Sjpk 	labeld_data_t	call;
5101676Sjpk 	labeld_data_t	*callp = &call;
5111676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
5121676Sjpk 	size_t	datasize = CALL_SIZE(bclearcvt_call_t, 0);
5131676Sjpk 	int	rval;
5141676Sjpk 
5151676Sjpk 	if (clrcvt == NULL)
5161676Sjpk 		return (-1);	/* conversion not initialized */
5171676Sjpk 
5181676Sjpk 	call.callop = BCLEARCVT;
5191676Sjpk 	bcccall.clear = *clearance;
5201676Sjpk 	bcccall.bounds = cbounds;	/* save from last bslcvtfull() call */
5211676Sjpk 	bcccall.flags = 0;
5221676Sjpk 	set_label_view(&bcccall.flags, flags);
5231676Sjpk 
5241676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) == NOSERVER) {
5251676Sjpk #ifdef	DEBUG
5261676Sjpk 		(void) fprintf(stderr, "No label server.\n");
5271676Sjpk #endif	/* DEBUG */
5281676Sjpk 		return (-1);
5291676Sjpk 	} else if (rval != SUCCESS) {
5301676Sjpk 		return (-1);
5311676Sjpk 	} else {
5321676Sjpk 		if (callp->reterr != 0)
5331676Sjpk 			return (-1);
5341676Sjpk 	}
5351676Sjpk 
5361676Sjpk 	if (build_strings(&clrstringsize, &clrstring,
5371676Sjpk 	    &bccret.buf[bccret.string],
5381676Sjpk 	    &clrcvtsize, 0, &clrcvt, &clrdim, bccret.d_len,
5391676Sjpk 	    &bccret.buf[bccret.lwords], &bccret.buf[bccret.swords],
5401676Sjpk 	    &bccret.buf[bccret.dim], 0) != 1) {
5411676Sjpk 		if (callp != &call)
5421676Sjpk 			/* release return buffer */
5431676Sjpk 			(void) munmap((void *)callp, bufsize);
5441676Sjpk 		return (0);
5451676Sjpk 	}
5461676Sjpk 
5471676Sjpk 	*string = clrstring;
5481676Sjpk 	*display = clrdim;
5491676Sjpk 	if (callp != &call)
5501676Sjpk 		/* release return buffer */
5511676Sjpk 		(void) munmap((void *)callp, bufsize);
5521676Sjpk 	return (1);
5531676Sjpk }  /* bclearcvt */
5541676Sjpk #undef	bcccall
5551676Sjpk #undef	bccret
5561676Sjpk 
5571676Sjpk #define	lfret callp->param.aret.rvals.fields_ret
5581676Sjpk /*
5591676Sjpk  *	labelfields - Return names for the label fields.
5601676Sjpk  *
5611676Sjpk  *	Entry	None
5621676Sjpk  *
5631676Sjpk  *	Exit	fields = Updated.
5641676Sjpk  *
5651676Sjpk  *	Returns	-1, If unable to access label encodings file, or
5661676Sjpk  *			labels server failure.
5671676Sjpk  *		 0, If unable to allocate memory.
5681676Sjpk  *		 1, If successful.
5691676Sjpk  *
5701676Sjpk  *	Calls __call_labeld(LABELFIELDS).
5711676Sjpk  */
5721676Sjpk 
5731676Sjpk int
labelfields(struct name_fields * fields)5741676Sjpk labelfields(struct name_fields *fields)
5751676Sjpk {
5761676Sjpk 	labeld_data_t	call;
5771676Sjpk 	labeld_data_t	*callp = &call;
5781676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
5791676Sjpk 	size_t	datasize = CALL_SIZE(fields_call_t, 0);
5801676Sjpk 	int	rval;
5811676Sjpk 
5821676Sjpk 	call.callop = LABELFIELDS;
5831676Sjpk 
5841676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) != SUCCESS) {
5851676Sjpk 
5861676Sjpk 		if (callp != &call)
5871676Sjpk 			/* release return buffer */
5881676Sjpk 			(void) munmap((void *)callp, bufsize);
5891676Sjpk 		return (-1);
5901676Sjpk 	}
5911676Sjpk 
5921676Sjpk 	/* unpack results */
5931676Sjpk 
5941676Sjpk 	if ((fields->class_name = strdup(&lfret.buf[lfret.classi])) == NULL) {
5951676Sjpk 		if (callp != &call)
5961676Sjpk 			/* release return buffer */
5971676Sjpk 			(void) munmap((void *)callp, bufsize);
5981676Sjpk 		return (0);
5991676Sjpk 	}
6001676Sjpk 	if ((fields->comps_name = strdup(&lfret.buf[lfret.compsi])) == NULL) {
6011676Sjpk 		free(fields->class_name);
6021676Sjpk 		if (callp != &call)
6031676Sjpk 			/* release return buffer */
6041676Sjpk 			(void) munmap((void *)callp, bufsize);
6051676Sjpk 		return (0);
6061676Sjpk 	}
6071676Sjpk 	if ((fields->marks_name = strdup(&lfret.buf[lfret.marksi])) == NULL) {
6081676Sjpk 		free(fields->class_name);
6091676Sjpk 		free(fields->comps_name);
6101676Sjpk 		if (callp != &call)
6111676Sjpk 			/* release return buffer */
6121676Sjpk 			(void) munmap((void *)callp, bufsize);
6131676Sjpk 		return (0);
6141676Sjpk 	}
6151676Sjpk 
6161676Sjpk 	if (callp != &call)
6171676Sjpk 		/* release return buffer */
6181676Sjpk 		(void) munmap((void *)callp, bufsize);
6191676Sjpk 	return (rval);
6201676Sjpk }  /* labelfields */
6211676Sjpk #undef	lfret
6221676Sjpk 
6231676Sjpk #define	udret callp->param.aret.rvals.udefs_ret
6241676Sjpk /*
625*2664Srica  *	userdefs - Get default user Sensitivity Label and/or Clearance.
6261676Sjpk  *
6271676Sjpk  *	Entry   None.
6281676Sjpk  *
6291676Sjpk  *	Exit	sl = default user Sensitivity Label.
6301676Sjpk  *		clear = default user Clearance.
6311676Sjpk  *
6321676Sjpk  *	Returns -1, If unable to access label encodings file, or
6331676Sjpk  *			labels server failure.
6341676Sjpk  *		1, If successful.
6351676Sjpk  *
6361676Sjpk  *	Calls	__call_labeld(UDEFS).
6371676Sjpk  */
6381676Sjpk 
6391676Sjpk int
userdefs(bslabel_t * sl,bclear_t * clear)6401676Sjpk userdefs(bslabel_t *sl, bclear_t *clear)
6411676Sjpk {
6421676Sjpk 	labeld_data_t	call;
6431676Sjpk 	labeld_data_t	*callp = &call;
6441676Sjpk 	size_t	bufsize = sizeof (labeld_data_t);
6451676Sjpk 	size_t	datasize = CALL_SIZE(udefs_call_t, 0);
6461676Sjpk 	int	rval;
6471676Sjpk 
6481676Sjpk 	call.callop = UDEFS;
6491676Sjpk 
6501676Sjpk 	if ((rval = __call_labeld(&callp, &bufsize, &datasize)) != SUCCESS) {
6511676Sjpk 		/* process error */
6521676Sjpk 
6531676Sjpk 		return (-1);
6541676Sjpk 	}
6551676Sjpk 
656*2664Srica 	if (sl != NULL)
657*2664Srica 		*sl = udret.sl;
658*2664Srica 	if (clear != NULL)
659*2664Srica 		*clear = udret.clear;
6601676Sjpk 	return (rval);
6611676Sjpk }  /* userdefs */
6621676Sjpk #undef	udret
663