17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*dd5829d1Sbaban  * Common Development and Distribution License (the "License").
6*dd5829d1Sbaban  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*dd5829d1Sbaban  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * Test nfsmapid. This program is not shipped on the binary release.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <stropts.h>
327c478bd9Sstevel@tonic-gate #include <strings.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate #include <fcntl.h>
357c478bd9Sstevel@tonic-gate #include <locale.h>
367c478bd9Sstevel@tonic-gate #include <unistd.h>
377c478bd9Sstevel@tonic-gate #include <netconfig.h>
387c478bd9Sstevel@tonic-gate #include <door.h>
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
417c478bd9Sstevel@tonic-gate #include <sys/param.h>
427c478bd9Sstevel@tonic-gate #include <sys/errno.h>
437c478bd9Sstevel@tonic-gate #include <sys/cred.h>
447c478bd9Sstevel@tonic-gate #include <sys/systm.h>
457c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
467c478bd9Sstevel@tonic-gate #include <sys/debug.h>
477c478bd9Sstevel@tonic-gate #include <rpcsvc/nfs4_prot.h>
487c478bd9Sstevel@tonic-gate #include <nfs/nfsid_map.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static char nobody_str[] = "nobody";
517c478bd9Sstevel@tonic-gate static int nfs_idmap_str_uid(utf8string *, uid_t *);
527c478bd9Sstevel@tonic-gate static int nfs_idmap_uid_str(uid_t, utf8string *);
537c478bd9Sstevel@tonic-gate static int nfs_idmap_str_gid(utf8string *, gid_t *);
547c478bd9Sstevel@tonic-gate static int nfs_idmap_gid_str(gid_t, utf8string *);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate static void
usage()577c478bd9Sstevel@tonic-gate usage()
587c478bd9Sstevel@tonic-gate {
597c478bd9Sstevel@tonic-gate 	fprintf(stderr, gettext(
60*dd5829d1Sbaban 	    "\nUsage:\tstr2uid string\n"
61*dd5829d1Sbaban 	    "\tstr2gid string\n"
62*dd5829d1Sbaban 	    "\tuid2str uid\n"
63*dd5829d1Sbaban 	    "\tgid2str gid\n"
64*dd5829d1Sbaban 	    "\techo string\n"
65*dd5829d1Sbaban 	    "\texit|quit\n"));
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
read_line(char * buf,int size)687c478bd9Sstevel@tonic-gate static int read_line(char *buf, int size)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	int len;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	/* read the next line. If cntl-d, return with zero char count */
737c478bd9Sstevel@tonic-gate 	printf(gettext("\n> "));
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	if (fgets(buf, size, stdin) == NULL)
767c478bd9Sstevel@tonic-gate 		return (0);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	len = strlen(buf);
797c478bd9Sstevel@tonic-gate 	buf[--len] = '\0';
807c478bd9Sstevel@tonic-gate 	return (len);
817c478bd9Sstevel@tonic-gate }
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static int
parse_input_line(char * input_line,int * argc,char *** argv)847c478bd9Sstevel@tonic-gate parse_input_line(char *input_line, int *argc, char ***argv)
857c478bd9Sstevel@tonic-gate {
867c478bd9Sstevel@tonic-gate 	const char nil = '\0';
877c478bd9Sstevel@tonic-gate 	char *chptr;
887c478bd9Sstevel@tonic-gate 	int chr_cnt;
897c478bd9Sstevel@tonic-gate 	int arg_cnt = 0;
907c478bd9Sstevel@tonic-gate 	int ch_was_space = 1;
917c478bd9Sstevel@tonic-gate 	int ch_is_space;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	chr_cnt = strlen(input_line);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	/* Count the arguments in the input_line string */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	*argc = 1;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	for (chptr = &input_line[0]; *chptr != nil; chptr++) {
1007c478bd9Sstevel@tonic-gate 		ch_is_space = isspace(*chptr);
1017c478bd9Sstevel@tonic-gate 		if (ch_is_space && !ch_was_space) {
1027c478bd9Sstevel@tonic-gate 			(*argc)++;
1037c478bd9Sstevel@tonic-gate 		}
1047c478bd9Sstevel@tonic-gate 		ch_was_space = ch_is_space;
1057c478bd9Sstevel@tonic-gate 	}
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate 	if (ch_was_space) {
1087c478bd9Sstevel@tonic-gate 		(*argc)--;
1097c478bd9Sstevel@tonic-gate 	}	/* minus trailing spaces */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	/* Now that we know how many args calloc the argv array */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	*argv = calloc((*argc)+1, sizeof (char *));
1147c478bd9Sstevel@tonic-gate 	chptr = (char *)(&input_line[0]);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	for (ch_was_space = 1; *chptr != nil; chptr++) {
1177c478bd9Sstevel@tonic-gate 		ch_is_space = isspace(*chptr);
1187c478bd9Sstevel@tonic-gate 		if (ch_is_space) {
1197c478bd9Sstevel@tonic-gate 			*chptr = nil;	/* replace each space with nil  */
1207c478bd9Sstevel@tonic-gate 		} else if (ch_was_space) {	/* begining of word? */
1217c478bd9Sstevel@tonic-gate 			(*argv)[arg_cnt++] = chptr;	/* new argument ? */
1227c478bd9Sstevel@tonic-gate 		}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		ch_was_space = ch_is_space;
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	return (chr_cnt);
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate char *
mapstat(int stat)1317c478bd9Sstevel@tonic-gate mapstat(int stat)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	switch (stat) {
1347c478bd9Sstevel@tonic-gate 	case NFSMAPID_OK:
1357c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_OK");
1367c478bd9Sstevel@tonic-gate 	case NFSMAPID_NUMSTR:
1377c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_NUMSTR");
1387c478bd9Sstevel@tonic-gate 	case NFSMAPID_UNMAPPABLE:
1397c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_UNMAPPABLE");
1407c478bd9Sstevel@tonic-gate 	case NFSMAPID_INVALID:
1417c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_INVALID");
1427c478bd9Sstevel@tonic-gate 	case NFSMAPID_INTERNAL:
1437c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_INTERNAL");
1447c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADDOMAIN:
1457c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_BADDOMAIN");
1467c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADID:
1477c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_BADID");
1487c478bd9Sstevel@tonic-gate 	case NFSMAPID_NOTFOUND:
1497c478bd9Sstevel@tonic-gate 		return ("NFSMAPID_NOTFOUND");
1507c478bd9Sstevel@tonic-gate 	case EINVAL:
1517c478bd9Sstevel@tonic-gate 		return ("EINVAL");
1527c478bd9Sstevel@tonic-gate 	case ECOMM:
1537c478bd9Sstevel@tonic-gate 		return ("ECOMM");
1547c478bd9Sstevel@tonic-gate 	case ENOMEM:
1557c478bd9Sstevel@tonic-gate 		return ("ENOMEM");
1567c478bd9Sstevel@tonic-gate 	default:
1577c478bd9Sstevel@tonic-gate 		printf(" unknown error %d ", stat);
1587c478bd9Sstevel@tonic-gate 		return ("...");
1597c478bd9Sstevel@tonic-gate 	}
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate int
do_test(char * input_buf)1637c478bd9Sstevel@tonic-gate do_test(char *input_buf)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	int argc, seal_argc;
1667c478bd9Sstevel@tonic-gate 	char **argv, **argv_array;
1677c478bd9Sstevel@tonic-gate 	char *cmd;
1687c478bd9Sstevel@tonic-gate 	int i, bufsize = 512;
1697c478bd9Sstevel@tonic-gate 	char str_buf[512];
1707c478bd9Sstevel@tonic-gate 	utf8string str;
1717c478bd9Sstevel@tonic-gate 	uid_t uid;
1727c478bd9Sstevel@tonic-gate 	gid_t gid;
1737c478bd9Sstevel@tonic-gate 	int stat;
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	argv = 0;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	if (parse_input_line(input_buf, &argc, &argv) == 0) {
1787c478bd9Sstevel@tonic-gate 		printf(gettext("\n"));
1797c478bd9Sstevel@tonic-gate 		return (1);
1807c478bd9Sstevel@tonic-gate 	}
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	/*
1837c478bd9Sstevel@tonic-gate 	 * remember argv_array address, which is memory calloc'd by
1847c478bd9Sstevel@tonic-gate 	 * parse_input_line, so it can be free'd at the end of the loop.
1857c478bd9Sstevel@tonic-gate 	 */
1867c478bd9Sstevel@tonic-gate 	argv_array = argv;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	if (argc < 1) {
1897c478bd9Sstevel@tonic-gate 		usage();
1907c478bd9Sstevel@tonic-gate 		free(argv_array);
1917c478bd9Sstevel@tonic-gate 		return (0);
1927c478bd9Sstevel@tonic-gate 	}
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	cmd = argv[0];
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	if (strcmp(cmd, "str2uid") == 0) {
1977c478bd9Sstevel@tonic-gate 		if (argc < 2) {
1987c478bd9Sstevel@tonic-gate 			usage();
1997c478bd9Sstevel@tonic-gate 			free(argv_array);
2007c478bd9Sstevel@tonic-gate 			return (0);
2017c478bd9Sstevel@tonic-gate 		}
2027c478bd9Sstevel@tonic-gate 		str.utf8string_val = argv[1];
2037c478bd9Sstevel@tonic-gate 		str.utf8string_len = strlen(argv[1]);
2047c478bd9Sstevel@tonic-gate 		stat = nfs_idmap_str_uid(&str, &uid);
205*dd5829d1Sbaban 		printf(gettext("%u stat=%s \n"), uid, mapstat(stat));
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	} else if (strcmp(cmd, "str2gid") == 0) {
2087c478bd9Sstevel@tonic-gate 		if (argc < 2) {
2097c478bd9Sstevel@tonic-gate 			usage();
2107c478bd9Sstevel@tonic-gate 			free(argv_array);
2117c478bd9Sstevel@tonic-gate 			return (0);
2127c478bd9Sstevel@tonic-gate 		}
2137c478bd9Sstevel@tonic-gate 		str.utf8string_val = argv[1];
2147c478bd9Sstevel@tonic-gate 		str.utf8string_len = strlen(argv[1]);
2157c478bd9Sstevel@tonic-gate 		stat = nfs_idmap_str_gid(&str, &gid);
216*dd5829d1Sbaban 		printf(gettext("%u stat=%s \n"), gid, mapstat(stat));
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	} else if (strcmp(cmd, "uid2str") == 0) {
2197c478bd9Sstevel@tonic-gate 		if (argc < 2) {
2207c478bd9Sstevel@tonic-gate 			usage();
2217c478bd9Sstevel@tonic-gate 			free(argv_array);
2227c478bd9Sstevel@tonic-gate 			return (0);
2237c478bd9Sstevel@tonic-gate 		}
2247c478bd9Sstevel@tonic-gate 		uid = atoi(argv[1]);
2257c478bd9Sstevel@tonic-gate 		bzero(str_buf, bufsize);
2267c478bd9Sstevel@tonic-gate 		str.utf8string_val = str_buf;
2277c478bd9Sstevel@tonic-gate 		stat = nfs_idmap_uid_str(uid, &str);
2287c478bd9Sstevel@tonic-gate 		printf(gettext("%s stat=%s\n"), str.utf8string_val,
229*dd5829d1Sbaban 		    mapstat(stat));
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	} else if (strcmp(cmd, "gid2str") == 0) {
2327c478bd9Sstevel@tonic-gate 		if (argc < 2) {
2337c478bd9Sstevel@tonic-gate 			usage();
2347c478bd9Sstevel@tonic-gate 			free(argv_array);
2357c478bd9Sstevel@tonic-gate 			return (0);
2367c478bd9Sstevel@tonic-gate 		}
2377c478bd9Sstevel@tonic-gate 		gid = atoi(argv[1]);
2387c478bd9Sstevel@tonic-gate 		bzero(str_buf, bufsize);
2397c478bd9Sstevel@tonic-gate 		str.utf8string_val = str_buf;
2407c478bd9Sstevel@tonic-gate 		stat = nfs_idmap_gid_str(gid, &str);
2417c478bd9Sstevel@tonic-gate 		printf(gettext("%s stat=%s\n"), str.utf8string_val,
242*dd5829d1Sbaban 		    mapstat(stat));
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	} else if (strcmp(cmd, "echo") == 0) {
2457c478bd9Sstevel@tonic-gate 		for (i = 1; i < argc; i++)
2467c478bd9Sstevel@tonic-gate 			printf("%s ", argv[i]);
2477c478bd9Sstevel@tonic-gate 		printf("\n");
2487c478bd9Sstevel@tonic-gate 	} else if (strcmp(cmd, "exit") == 0 ||
249*dd5829d1Sbaban 	    strcmp(cmd, "quit") == 0) {
2507c478bd9Sstevel@tonic-gate 		printf(gettext("\n"));
2517c478bd9Sstevel@tonic-gate 		free(argv_array);
2527c478bd9Sstevel@tonic-gate 		return (1);
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	} else
2557c478bd9Sstevel@tonic-gate 		usage();
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	/* free argv array */
2587c478bd9Sstevel@tonic-gate 	free(argv_array);
2597c478bd9Sstevel@tonic-gate 	return (0);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)2647c478bd9Sstevel@tonic-gate main(int argc, char **argv)
2657c478bd9Sstevel@tonic-gate {
2667c478bd9Sstevel@tonic-gate 	char buf[512];
2677c478bd9Sstevel@tonic-gate 	int len, ret;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
2707c478bd9Sstevel@tonic-gate #ifndef TEXT_DOMAIN
2717c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	""
2727c478bd9Sstevel@tonic-gate #endif
2737c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	usage();
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	/*
2787c478bd9Sstevel@tonic-gate 	 * Loop, repeatedly calling parse_input_line() to get the
2797c478bd9Sstevel@tonic-gate 	 * next line and parse it into argc and argv. Act on the
2807c478bd9Sstevel@tonic-gate 	 * arguements found on the line.
2817c478bd9Sstevel@tonic-gate 	 */
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	do {
2847c478bd9Sstevel@tonic-gate 		len = read_line(buf, 512);
2857c478bd9Sstevel@tonic-gate 		if (len)
2867c478bd9Sstevel@tonic-gate 			ret = do_test(buf);
2877c478bd9Sstevel@tonic-gate 	} while (!ret);
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	return (0);
2907c478bd9Sstevel@tonic-gate }
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate #define	NFSMAPID_DOOR	"/var/run/nfsmapid_door"
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate  * Gen the door handle for connecting to the nfsmapid process.
2967c478bd9Sstevel@tonic-gate  * Keep the door cached.  This call may be made quite often.
2977c478bd9Sstevel@tonic-gate  */
2987c478bd9Sstevel@tonic-gate int
nfs_idmap_doorget()2997c478bd9Sstevel@tonic-gate nfs_idmap_doorget()
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate 	static int doorfd = -1;
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	if (doorfd != -1)
3047c478bd9Sstevel@tonic-gate 		return (doorfd);
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	if ((doorfd = open(NFSMAPID_DOOR, O_RDWR)) == -1) {
3077c478bd9Sstevel@tonic-gate 		perror(NFSMAPID_DOOR);
3087c478bd9Sstevel@tonic-gate 		exit(1);
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 	return (doorfd);
3117c478bd9Sstevel@tonic-gate }
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate /*
3147c478bd9Sstevel@tonic-gate  * Convert a user utf-8 string identifier into its local uid.
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate int
nfs_idmap_str_uid(utf8string * u8s,uid_t * uid)3177c478bd9Sstevel@tonic-gate nfs_idmap_str_uid(utf8string *u8s, uid_t *uid)
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	struct mapid_arg *mapargp;
3207c478bd9Sstevel@tonic-gate 	struct mapid_res mapres;
3217c478bd9Sstevel@tonic-gate 	struct mapid_res *mapresp = &mapres;
3227c478bd9Sstevel@tonic-gate 	struct mapid_res *resp = mapresp;
3237c478bd9Sstevel@tonic-gate 	door_arg_t	door_args;
3247c478bd9Sstevel@tonic-gate 	int		doorfd;
3257c478bd9Sstevel@tonic-gate 	int		error = 0;
3267c478bd9Sstevel@tonic-gate 	static int	msg_done = 0;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	if (!u8s || !u8s->utf8string_val || !u8s->utf8string_len ||
329*dd5829d1Sbaban 	    (u8s->utf8string_val[0] == '\0')) {
3307c478bd9Sstevel@tonic-gate 		error = EINVAL;
3317c478bd9Sstevel@tonic-gate 		goto s2u_done;
3327c478bd9Sstevel@tonic-gate 	}
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	if (bcmp(u8s->utf8string_val, "nobody", 6) == 0) {
3357c478bd9Sstevel@tonic-gate 		/*
3367c478bd9Sstevel@tonic-gate 		 * If "nobody", just short circuit and bail
3377c478bd9Sstevel@tonic-gate 		 */
3387c478bd9Sstevel@tonic-gate 		*uid = UID_NOBODY;
3397c478bd9Sstevel@tonic-gate 		goto s2u_done;
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	if ((mapargp = malloc(MAPID_ARG_LEN(u8s->utf8string_len))) == NULL) {
3447c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Unable to malloc %d bytes\n",
345*dd5829d1Sbaban 		    MAPID_ARG_LEN(u8s->utf8string_len));
3467c478bd9Sstevel@tonic-gate 		error = ENOMEM;
3477c478bd9Sstevel@tonic-gate 		goto s2u_done;
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate 	mapargp->cmd = NFSMAPID_STR_UID;
3507c478bd9Sstevel@tonic-gate 	mapargp->u_arg.len = u8s->utf8string_len;
3517c478bd9Sstevel@tonic-gate 	(void) bcopy(u8s->utf8string_val, mapargp->str, mapargp->u_arg.len);
3527c478bd9Sstevel@tonic-gate 	mapargp->str[mapargp->u_arg.len] = '\0';
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate 	door_args.data_ptr = (char *)mapargp;
3557c478bd9Sstevel@tonic-gate 	door_args.data_size = MAPID_ARG_LEN(mapargp->u_arg.len);
3567c478bd9Sstevel@tonic-gate 	door_args.desc_ptr = NULL;
3577c478bd9Sstevel@tonic-gate 	door_args.desc_num = 0;
3587c478bd9Sstevel@tonic-gate 	door_args.rbuf = (char *)mapresp;
3597c478bd9Sstevel@tonic-gate 	door_args.rsize = sizeof (struct mapid_res);
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	/*
3627c478bd9Sstevel@tonic-gate 	 * call to the nfsmapid daemon
3637c478bd9Sstevel@tonic-gate 	 */
3647c478bd9Sstevel@tonic-gate 	if ((doorfd = nfs_idmap_doorget()) == -1) {
3657c478bd9Sstevel@tonic-gate 		if (!msg_done) {
3667c478bd9Sstevel@tonic-gate 			fprintf(stderr, "nfs_idmap_str_uid: Can't communicate"
367*dd5829d1Sbaban 			    " with mapping daemon nfsmapid\n");
3687c478bd9Sstevel@tonic-gate 			msg_done = 1;
3697c478bd9Sstevel@tonic-gate 		}
3707c478bd9Sstevel@tonic-gate 		error = ECOMM;
3717c478bd9Sstevel@tonic-gate 		free(mapargp);
3727c478bd9Sstevel@tonic-gate 		goto s2u_done;
3737c478bd9Sstevel@tonic-gate 	}
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	if (door_call(doorfd, &door_args) == -1) {
3767c478bd9Sstevel@tonic-gate 		perror("door_call failed");
3777c478bd9Sstevel@tonic-gate 		error = EINVAL;
3787c478bd9Sstevel@tonic-gate 		free(mapargp);
3797c478bd9Sstevel@tonic-gate 		goto s2u_done;
3807c478bd9Sstevel@tonic-gate 	}
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	free(mapargp);
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	resp = (struct mapid_res *)door_args.rbuf;
3857c478bd9Sstevel@tonic-gate 	switch (resp->status) {
3867c478bd9Sstevel@tonic-gate 	case NFSMAPID_OK:
3877c478bd9Sstevel@tonic-gate 		*uid = resp->u_res.uid;
3887c478bd9Sstevel@tonic-gate 		break;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 	case NFSMAPID_NUMSTR:
3917c478bd9Sstevel@tonic-gate 		*uid = resp->u_res.uid;
3927c478bd9Sstevel@tonic-gate 		error = resp->status;
3937c478bd9Sstevel@tonic-gate 		goto out;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	default:
3967c478bd9Sstevel@tonic-gate 	case NFSMAPID_UNMAPPABLE:
3977c478bd9Sstevel@tonic-gate 	case NFSMAPID_INVALID:
3987c478bd9Sstevel@tonic-gate 	case NFSMAPID_INTERNAL:
3997c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADDOMAIN:
4007c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADID:
4017c478bd9Sstevel@tonic-gate 	case NFSMAPID_NOTFOUND:
4027c478bd9Sstevel@tonic-gate 		error = resp->status;
4037c478bd9Sstevel@tonic-gate 		goto s2u_done;
4047c478bd9Sstevel@tonic-gate 	}
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate s2u_done:
4077c478bd9Sstevel@tonic-gate 	if (error)
4087c478bd9Sstevel@tonic-gate 		*uid = UID_NOBODY;
4097c478bd9Sstevel@tonic-gate out:
4107c478bd9Sstevel@tonic-gate 	if (resp != mapresp)
4117c478bd9Sstevel@tonic-gate 		munmap(door_args.rbuf, door_args.rsize);
4127c478bd9Sstevel@tonic-gate 	return (error);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate /*
4167c478bd9Sstevel@tonic-gate  * Convert a uid into its utf-8 string representation.
4177c478bd9Sstevel@tonic-gate  */
4187c478bd9Sstevel@tonic-gate int
nfs_idmap_uid_str(uid_t uid,utf8string * u8s)4197c478bd9Sstevel@tonic-gate nfs_idmap_uid_str(uid_t uid,		/* uid to map */
4207c478bd9Sstevel@tonic-gate 		utf8string *u8s)	/* resulting utf-8 string for uid */
4217c478bd9Sstevel@tonic-gate {
4227c478bd9Sstevel@tonic-gate 	struct mapid_arg maparg;
4237c478bd9Sstevel@tonic-gate 	struct mapid_res mapres;
4247c478bd9Sstevel@tonic-gate 	struct mapid_res *mapresp = &mapres;
4257c478bd9Sstevel@tonic-gate 	struct mapid_res *resp = mapresp;
4267c478bd9Sstevel@tonic-gate 	door_arg_t	door_args;
4277c478bd9Sstevel@tonic-gate 	int		doorfd;
4287c478bd9Sstevel@tonic-gate 	int		error = 0;
4297c478bd9Sstevel@tonic-gate 	static int	msg_done = 0;
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	if (uid == UID_NOBODY) {
4327c478bd9Sstevel@tonic-gate 		u8s->utf8string_len = strlen("nobody");
4337c478bd9Sstevel@tonic-gate 		u8s->utf8string_val = nobody_str;
4347c478bd9Sstevel@tonic-gate 		goto u2s_done;
4357c478bd9Sstevel@tonic-gate 	}
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	/*
4387c478bd9Sstevel@tonic-gate 	 * Daemon call...
4397c478bd9Sstevel@tonic-gate 	 */
4407c478bd9Sstevel@tonic-gate 	maparg.cmd = NFSMAPID_UID_STR;
4417c478bd9Sstevel@tonic-gate 	maparg.u_arg.uid = uid;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	door_args.data_ptr = (char *)&maparg;
4447c478bd9Sstevel@tonic-gate 	door_args.data_size = sizeof (struct mapid_arg);
4457c478bd9Sstevel@tonic-gate 	door_args.desc_ptr = NULL;
4467c478bd9Sstevel@tonic-gate 	door_args.desc_num = 0;
4477c478bd9Sstevel@tonic-gate 	door_args.rbuf = (char *)mapresp;
4487c478bd9Sstevel@tonic-gate 	door_args.rsize = sizeof (struct mapid_res);
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	if ((doorfd = nfs_idmap_doorget()) == -1) {
4517c478bd9Sstevel@tonic-gate 		if (!msg_done) {
4527c478bd9Sstevel@tonic-gate 			fprintf(stderr, "nfs_idmap_uid_str: Can't "
453*dd5829d1Sbaban 			    "communicate with mapping daemon nfsmapid\n");
4547c478bd9Sstevel@tonic-gate 			msg_done = 1;
4557c478bd9Sstevel@tonic-gate 		}
4567c478bd9Sstevel@tonic-gate 		error = ECOMM;
4577c478bd9Sstevel@tonic-gate 		goto u2s_done;
4587c478bd9Sstevel@tonic-gate 	}
4597c478bd9Sstevel@tonic-gate 
4607c478bd9Sstevel@tonic-gate 	if (door_call(doorfd, &door_args) == -1) {
4617c478bd9Sstevel@tonic-gate 		perror("door_call failed");
4627c478bd9Sstevel@tonic-gate 		error = EINVAL;
4637c478bd9Sstevel@tonic-gate 		goto u2s_done;
4647c478bd9Sstevel@tonic-gate 	}
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	resp = (struct mapid_res *)door_args.rbuf;
4677c478bd9Sstevel@tonic-gate 	if (resp->status != NFSMAPID_OK) {
4687c478bd9Sstevel@tonic-gate 		error = resp->status;
4697c478bd9Sstevel@tonic-gate 		goto u2s_done;
4707c478bd9Sstevel@tonic-gate 	}
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	if (resp->u_res.len != strlen(resp->str)) {
4737c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Incorrect length %d expected %d\n",
474*dd5829d1Sbaban 		    resp->u_res.len, strlen(resp->str));
4757c478bd9Sstevel@tonic-gate 		error = NFSMAPID_INVALID;
4767c478bd9Sstevel@tonic-gate 		goto u2s_done;
4777c478bd9Sstevel@tonic-gate 	}
4787c478bd9Sstevel@tonic-gate 	u8s->utf8string_len = resp->u_res.len;
4797c478bd9Sstevel@tonic-gate 	bcopy(resp->str, u8s->utf8string_val, u8s->utf8string_len);
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate u2s_done:
4827c478bd9Sstevel@tonic-gate 	if (resp != mapresp)
4837c478bd9Sstevel@tonic-gate 		munmap(door_args.rbuf, door_args.rsize);
4847c478bd9Sstevel@tonic-gate 	return (error);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate /*
4887c478bd9Sstevel@tonic-gate  * Convert a group utf-8 string identifier into its local gid.
4897c478bd9Sstevel@tonic-gate  */
4907c478bd9Sstevel@tonic-gate int
nfs_idmap_str_gid(utf8string * u8s,gid_t * gid)4917c478bd9Sstevel@tonic-gate nfs_idmap_str_gid(utf8string *u8s, gid_t *gid)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate 	struct mapid_arg *mapargp;
4947c478bd9Sstevel@tonic-gate 	struct mapid_res mapres;
4957c478bd9Sstevel@tonic-gate 	struct mapid_res *mapresp = &mapres;
4967c478bd9Sstevel@tonic-gate 	struct mapid_res *resp = mapresp;
4977c478bd9Sstevel@tonic-gate 	door_arg_t	door_args;
4987c478bd9Sstevel@tonic-gate 	int		doorfd;
4997c478bd9Sstevel@tonic-gate 	int		error = 0;
5007c478bd9Sstevel@tonic-gate 	static int	msg_done = 0;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	if (!u8s || !u8s->utf8string_val || !u8s->utf8string_len ||
503*dd5829d1Sbaban 	    (u8s->utf8string_val[0] == '\0')) {
5047c478bd9Sstevel@tonic-gate 		error = EINVAL;
5057c478bd9Sstevel@tonic-gate 		goto s2g_done;
5067c478bd9Sstevel@tonic-gate 	}
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	if (bcmp(u8s->utf8string_val, "nobody", 6) == 0) {
5097c478bd9Sstevel@tonic-gate 		/*
5107c478bd9Sstevel@tonic-gate 		 * If "nobody", just short circuit and bail
5117c478bd9Sstevel@tonic-gate 		 */
5127c478bd9Sstevel@tonic-gate 		*gid = GID_NOBODY;
5137c478bd9Sstevel@tonic-gate 		goto s2g_done;
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	}
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	if ((mapargp = malloc(MAPID_ARG_LEN(u8s->utf8string_len))) == NULL) {
5187c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Unable to malloc %d bytes\n",
519*dd5829d1Sbaban 		    MAPID_ARG_LEN(u8s->utf8string_len));
5207c478bd9Sstevel@tonic-gate 		error = ENOMEM;
5217c478bd9Sstevel@tonic-gate 		goto s2g_done;
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate 	mapargp->cmd = NFSMAPID_STR_GID;
5247c478bd9Sstevel@tonic-gate 	mapargp->u_arg.len = u8s->utf8string_len;
5257c478bd9Sstevel@tonic-gate 	(void) bcopy(u8s->utf8string_val, mapargp->str, mapargp->u_arg.len);
5267c478bd9Sstevel@tonic-gate 	mapargp->str[mapargp->u_arg.len] = '\0';
5277c478bd9Sstevel@tonic-gate 
5287c478bd9Sstevel@tonic-gate 	door_args.data_ptr = (char *)mapargp;
5297c478bd9Sstevel@tonic-gate 	door_args.data_size = MAPID_ARG_LEN(mapargp->u_arg.len);
5307c478bd9Sstevel@tonic-gate 	door_args.desc_ptr = NULL;
5317c478bd9Sstevel@tonic-gate 	door_args.desc_num = 0;
5327c478bd9Sstevel@tonic-gate 	door_args.rbuf = (char *)mapresp;
5337c478bd9Sstevel@tonic-gate 	door_args.rsize = sizeof (struct mapid_res);
5347c478bd9Sstevel@tonic-gate 
5357c478bd9Sstevel@tonic-gate 	/*
5367c478bd9Sstevel@tonic-gate 	 * call to the nfsmapid daemon
5377c478bd9Sstevel@tonic-gate 	 */
5387c478bd9Sstevel@tonic-gate 	if ((doorfd = nfs_idmap_doorget()) == -1) {
5397c478bd9Sstevel@tonic-gate 		if (!msg_done) {
5407c478bd9Sstevel@tonic-gate 			fprintf(stderr, "nfs_idmap_str_uid: Can't communicate"
541*dd5829d1Sbaban 			    " with mapping daemon nfsmapid\n");
5427c478bd9Sstevel@tonic-gate 			msg_done = 1;
5437c478bd9Sstevel@tonic-gate 		}
5447c478bd9Sstevel@tonic-gate 		error = ECOMM;
5457c478bd9Sstevel@tonic-gate 		free(mapargp);
5467c478bd9Sstevel@tonic-gate 		goto s2g_done;
5477c478bd9Sstevel@tonic-gate 	}
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	if (door_call(doorfd, &door_args) == -1) {
5507c478bd9Sstevel@tonic-gate 		perror("door_call failed");
5517c478bd9Sstevel@tonic-gate 		error = EINVAL;
5527c478bd9Sstevel@tonic-gate 		free(mapargp);
5537c478bd9Sstevel@tonic-gate 		goto s2g_done;
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	free(mapargp);
5577c478bd9Sstevel@tonic-gate 
5587c478bd9Sstevel@tonic-gate 	resp = (struct mapid_res *)door_args.rbuf;
5597c478bd9Sstevel@tonic-gate 	switch (resp->status) {
5607c478bd9Sstevel@tonic-gate 	case NFSMAPID_OK:
5617c478bd9Sstevel@tonic-gate 		*gid = resp->u_res.gid;
5627c478bd9Sstevel@tonic-gate 		break;
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	case NFSMAPID_NUMSTR:
5657c478bd9Sstevel@tonic-gate 		*gid = resp->u_res.gid;
5667c478bd9Sstevel@tonic-gate 		error = resp->status;
5677c478bd9Sstevel@tonic-gate 		goto out;
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate 	default:
5707c478bd9Sstevel@tonic-gate 	case NFSMAPID_UNMAPPABLE:
5717c478bd9Sstevel@tonic-gate 	case NFSMAPID_INVALID:
5727c478bd9Sstevel@tonic-gate 	case NFSMAPID_INTERNAL:
5737c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADDOMAIN:
5747c478bd9Sstevel@tonic-gate 	case NFSMAPID_BADID:
5757c478bd9Sstevel@tonic-gate 	case NFSMAPID_NOTFOUND:
5767c478bd9Sstevel@tonic-gate 		error = resp->status;
5777c478bd9Sstevel@tonic-gate 		goto s2g_done;
5787c478bd9Sstevel@tonic-gate 	}
5797c478bd9Sstevel@tonic-gate 
5807c478bd9Sstevel@tonic-gate s2g_done:
5817c478bd9Sstevel@tonic-gate 	if (error)
5827c478bd9Sstevel@tonic-gate 		*gid = GID_NOBODY;
5837c478bd9Sstevel@tonic-gate out:
5847c478bd9Sstevel@tonic-gate 	if (resp != mapresp)
5857c478bd9Sstevel@tonic-gate 		munmap(door_args.rbuf, door_args.rsize);
5867c478bd9Sstevel@tonic-gate 	return (error);
5877c478bd9Sstevel@tonic-gate }
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate /*
5907c478bd9Sstevel@tonic-gate  * Convert a gid into its utf-8 string representation.
5917c478bd9Sstevel@tonic-gate  */
5927c478bd9Sstevel@tonic-gate int
nfs_idmap_gid_str(gid_t gid,utf8string * g8s)5937c478bd9Sstevel@tonic-gate nfs_idmap_gid_str(gid_t gid,		/* gid to map */
5947c478bd9Sstevel@tonic-gate 		utf8string *g8s)	/* resulting utf-8 string for gid */
5957c478bd9Sstevel@tonic-gate {
5967c478bd9Sstevel@tonic-gate 	struct mapid_arg maparg;
5977c478bd9Sstevel@tonic-gate 	struct mapid_res mapres;
5987c478bd9Sstevel@tonic-gate 	struct mapid_res *mapresp = &mapres;
5997c478bd9Sstevel@tonic-gate 	struct mapid_res *resp = mapresp;
6007c478bd9Sstevel@tonic-gate 	door_arg_t	door_args;
6017c478bd9Sstevel@tonic-gate 	int		error = 0;
6027c478bd9Sstevel@tonic-gate 	int		doorfd;
6037c478bd9Sstevel@tonic-gate 	static int	msg_done = 0;
6047c478bd9Sstevel@tonic-gate 
6057c478bd9Sstevel@tonic-gate 	if (gid == GID_NOBODY) {
6067c478bd9Sstevel@tonic-gate 		g8s->utf8string_len = strlen("nobody");
6077c478bd9Sstevel@tonic-gate 		g8s->utf8string_val = nobody_str;
6087c478bd9Sstevel@tonic-gate 		goto g2s_done;
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate 	}
6117c478bd9Sstevel@tonic-gate 
6127c478bd9Sstevel@tonic-gate 	/*
6137c478bd9Sstevel@tonic-gate 	 * Daemon call...
6147c478bd9Sstevel@tonic-gate 	 */
6157c478bd9Sstevel@tonic-gate 	maparg.cmd = NFSMAPID_GID_STR;
6167c478bd9Sstevel@tonic-gate 	maparg.u_arg.gid = gid;
6177c478bd9Sstevel@tonic-gate 
6187c478bd9Sstevel@tonic-gate 	door_args.data_ptr = (char *)&maparg;
6197c478bd9Sstevel@tonic-gate 	door_args.data_size = sizeof (struct mapid_arg);
6207c478bd9Sstevel@tonic-gate 	door_args.desc_ptr = NULL;
6217c478bd9Sstevel@tonic-gate 	door_args.desc_num = 0;
6227c478bd9Sstevel@tonic-gate 	door_args.rbuf = (char *)mapresp;
6237c478bd9Sstevel@tonic-gate 	door_args.rsize = sizeof (struct mapid_res);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	if ((doorfd = nfs_idmap_doorget()) == -1) {
6267c478bd9Sstevel@tonic-gate 		if (!msg_done) {
6277c478bd9Sstevel@tonic-gate 			fprintf(stderr, "nfs_idmap_uid_str: Can't "
628*dd5829d1Sbaban 			    "communicate with mapping daemon nfsmapid\n");
6297c478bd9Sstevel@tonic-gate 			msg_done = 1;
6307c478bd9Sstevel@tonic-gate 		}
6317c478bd9Sstevel@tonic-gate 		error = ECOMM;
6327c478bd9Sstevel@tonic-gate 		goto g2s_done;
6337c478bd9Sstevel@tonic-gate 	}
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate 	if (door_call(doorfd, &door_args) == -1) {
6367c478bd9Sstevel@tonic-gate 		perror("door_call failed");
6377c478bd9Sstevel@tonic-gate 		error = EINVAL;
6387c478bd9Sstevel@tonic-gate 		goto g2s_done;
6397c478bd9Sstevel@tonic-gate 	}
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate 	resp = (struct mapid_res *)door_args.rbuf;
6427c478bd9Sstevel@tonic-gate 	if (resp->status != NFSMAPID_OK) {
6437c478bd9Sstevel@tonic-gate 		error = resp->status;
6447c478bd9Sstevel@tonic-gate 		goto g2s_done;
6457c478bd9Sstevel@tonic-gate 	}
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	if (resp->u_res.len != strlen(resp->str)) {
6487c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "Incorrect length %d expected %d\n",
649*dd5829d1Sbaban 		    resp->u_res.len, strlen(resp->str));
6507c478bd9Sstevel@tonic-gate 		error = NFSMAPID_INVALID;
6517c478bd9Sstevel@tonic-gate 		goto g2s_done;
6527c478bd9Sstevel@tonic-gate 	}
6537c478bd9Sstevel@tonic-gate 	g8s->utf8string_len = resp->u_res.len;
6547c478bd9Sstevel@tonic-gate 	bcopy(resp->str, g8s->utf8string_val, g8s->utf8string_len);
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate g2s_done:
6577c478bd9Sstevel@tonic-gate 	if (resp != mapresp)
6587c478bd9Sstevel@tonic-gate 		munmap(door_args.rbuf, door_args.rsize);
6597c478bd9Sstevel@tonic-gate 	return (error);
6607c478bd9Sstevel@tonic-gate }
661