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