nfsmapid_test.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Test nfsmapid. This program is not shipped on the binary release.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stropts.h>
#include <strings.h>
#include <signal.h>
#include <fcntl.h>
#include <locale.h>
#include <unistd.h>
#include <netconfig.h>
#include <door.h>
#include <rpcsvc/nfs4_prot.h>
#include <nfs/nfsid_map.h>
static char nobody_str[] = "nobody";
static void
usage()
{
"\nUsage:\tstr2uid string\n"
"\tstr2gid string\n"
"\tuid2str uid\n"
"\tgid2str gid\n"
"\techo string\n"
"\texit|quit\n"));
}
{
int len;
/* read the next line. If cntl-d, return with zero char count */
return (0);
return (len);
}
static int
{
const char nil = '\0';
char *chptr;
int chr_cnt;
int arg_cnt = 0;
int ch_was_space = 1;
int ch_is_space;
/* Count the arguments in the input_line string */
*argc = 1;
if (ch_is_space && !ch_was_space) {
(*argc)++;
}
}
if (ch_was_space) {
(*argc)--;
} /* minus trailing spaces */
/* Now that we know how many args calloc the argv array */
chptr = (char *)(&input_line[0]);
if (ch_is_space) {
} else if (ch_was_space) { /* begining of word? */
}
}
return (chr_cnt);
}
char *
{
switch (stat) {
case NFSMAPID_OK:
return ("NFSMAPID_OK");
case NFSMAPID_NUMSTR:
return ("NFSMAPID_NUMSTR");
case NFSMAPID_UNMAPPABLE:
return ("NFSMAPID_UNMAPPABLE");
case NFSMAPID_INVALID:
return ("NFSMAPID_INVALID");
case NFSMAPID_INTERNAL:
return ("NFSMAPID_INTERNAL");
case NFSMAPID_BADDOMAIN:
return ("NFSMAPID_BADDOMAIN");
case NFSMAPID_BADID:
return ("NFSMAPID_BADID");
case NFSMAPID_NOTFOUND:
return ("NFSMAPID_NOTFOUND");
case EINVAL:
return ("EINVAL");
case ECOMM:
return ("ECOMM");
case ENOMEM:
return ("ENOMEM");
default:
return ("...");
}
}
int
{
char **argv, **argv_array;
char *cmd;
int i, bufsize = 512;
char str_buf[512];
int stat;
argv = 0;
return (1);
}
/*
* remember argv_array address, which is memory calloc'd by
* parse_input_line, so it can be free'd at the end of the loop.
*/
argv_array = argv;
if (argc < 1) {
usage();
return (0);
}
if (argc < 2) {
usage();
return (0);
}
if (argc < 2) {
usage();
return (0);
}
if (argc < 2) {
usage();
return (0);
}
if (argc < 2) {
usage();
return (0);
}
for (i = 1; i < argc; i++)
printf("\n");
return (1);
} else
usage();
/* free argv array */
return (0);
}
int
{
char buf[512];
#ifndef TEXT_DOMAIN
#define TEXT_DOMAIN ""
#endif
(void) textdomain(TEXT_DOMAIN);
usage();
/*
* Loop, repeatedly calling parse_input_line() to get the
* next line and parse it into argc and argv. Act on the
* arguements found on the line.
*/
do {
if (len)
} while (!ret);
return (0);
}
#define NFSMAPID_DOOR "/var/run/nfsmapid_door"
/*
* Gen the door handle for connecting to the nfsmapid process.
* Keep the door cached. This call may be made quite often.
*/
int
{
static int doorfd = -1;
if (doorfd != -1)
return (doorfd);
exit(1);
}
return (doorfd);
}
/*
* Convert a user utf-8 string identifier into its local uid.
*/
int
{
int doorfd;
int error = 0;
static int msg_done = 0;
goto s2u_done;
}
/*
* If "nobody", just short circuit and bail
*/
*uid = UID_NOBODY;
goto s2u_done;
}
goto s2u_done;
}
/*
* call to the nfsmapid daemon
*/
if (!msg_done) {
" with mapping daemon nfsmapid\n");
msg_done = 1;
}
goto s2u_done;
}
perror("door_call failed");
goto s2u_done;
}
case NFSMAPID_OK:
break;
case NFSMAPID_NUMSTR:
goto out;
default:
case NFSMAPID_UNMAPPABLE:
case NFSMAPID_INVALID:
case NFSMAPID_INTERNAL:
case NFSMAPID_BADDOMAIN:
case NFSMAPID_BADID:
case NFSMAPID_NOTFOUND:
goto s2u_done;
}
if (error)
*uid = UID_NOBODY;
out:
return (error);
}
/*
* Convert a uid into its utf-8 string representation.
*/
int
{
int doorfd;
int error = 0;
static int msg_done = 0;
if (uid == UID_NOBODY) {
goto u2s_done;
}
/*
* Daemon call...
*/
if (!msg_done) {
"communicate with mapping daemon nfsmapid\n");
msg_done = 1;
}
goto u2s_done;
}
perror("door_call failed");
goto u2s_done;
}
goto u2s_done;
}
goto u2s_done;
}
return (error);
}
/*
* Convert a group utf-8 string identifier into its local gid.
*/
int
{
int doorfd;
int error = 0;
static int msg_done = 0;
goto s2g_done;
}
/*
* If "nobody", just short circuit and bail
*/
*gid = GID_NOBODY;
goto s2g_done;
}
goto s2g_done;
}
/*
* call to the nfsmapid daemon
*/
if (!msg_done) {
" with mapping daemon nfsmapid\n");
msg_done = 1;
}
goto s2g_done;
}
perror("door_call failed");
goto s2g_done;
}
case NFSMAPID_OK:
break;
case NFSMAPID_NUMSTR:
goto out;
default:
case NFSMAPID_UNMAPPABLE:
case NFSMAPID_INVALID:
case NFSMAPID_INTERNAL:
case NFSMAPID_BADDOMAIN:
case NFSMAPID_BADID:
case NFSMAPID_NOTFOUND:
goto s2g_done;
}
if (error)
*gid = GID_NOBODY;
out:
return (error);
}
/*
* Convert a gid into its utf-8 string representation.
*/
int
{
int error = 0;
int doorfd;
static int msg_done = 0;
if (gid == GID_NOBODY) {
goto g2s_done;
}
/*
* Daemon call...
*/
if (!msg_done) {
"communicate with mapping daemon nfsmapid\n");
msg_done = 1;
}
goto g2s_done;
}
perror("door_call failed");
goto g2s_done;
}
goto g2s_done;
}
goto g2s_done;
}
return (error);
}