svc_simple.c revision 9acbbeaf2a1ffe5c14b244867d427714fab43c5c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley
* 4.3 BSD under license from the Regents of the University of
* California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Simplified front end to rpc.
*/
/*
* This interface creates a virtual listener for all the services
* started thru rpc_reg(). It listens on the same endpoint for
* all the services and then executes the corresponding service
* for the given prognum and procnum.
*/
#include "mt.h"
#include "rpc_mt.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
extern int use_portmapper;
static struct proglst {
char *(*p_progname)();
char *p_netid;
char *p_xdrbuf;
int p_recvsz;
} *proglst;
static void universal();
static const char rpc_reg_err[] = "%s: %s";
static const char rpc_reg_msg[] = "rpc_reg: ";
static const char __reg_err1[] = "can't find appropriate transport";
static const char __reg_err3[] = "unsupported transport size";
static const char __no_mem_str[] = "out of memory";
/*
* For simplified, easy to use kind of rpc interfaces.
* nettype indicates the type of transport on which the service will be
* listening. Used for conservation of the system resource. Only one
* handle is created for all the services (actually one of each netid)
* and same xdrbuf is used for same netid. The size of the arguments
* is also limited by the recvsize for that transport, even if it is
* a COTS transport. This may be wrong, but for cases like these, they
* should not use the simplified interfaces like this.
*/
int
{
void *handle;
extern mutex_t proglst_lock;
(const char *) "can't reassign procedure number %d",
NULLPROC);
return (-1);
}
return (-1);
}
/* VARIABLES PROTECTED BY proglst_lock: proglst */
(void) mutex_lock(&proglst_lock);
int madenow;
char *xdrbuf;
char *netid;
break;
}
continue;
char errorstr[100];
rpc_reg_msg, "t_getinfo failed",
errorstr);
continue;
}
continue;
}
break;
}
}
/*
* Check if this (program, version, netid) had already been
* registered. The check may save a few RPC calls to rpcbind
*/
break;
/*
* Note that if we're using a portmapper
* instead of rpcbind then we can't do an
* unregister operation here.
*
* The reason is that the portmapper unset
* operation removes all the entries for a
* transport protocol.
*
* The caller of this routine needs to ensure
* that __pmap_unset() has been called for all
* to support before they start registering
*/
if (!use_portmapper)
} else {
/* so that svc_reg does not call rpcb_set() */
}
"%s couldn't register prog %d vers %d for %s",
if (madenow) {
}
continue;
}
if (madenow) {
}
break;
}
}
(void) mutex_unlock(&proglst_lock);
(const char *) "%s cant find suitable transport for %s",
return (-1);
}
return (0);
}
/*
* The universal handler for the services registered using registerrpc.
* It handles both the connectionless and the connection oriented cases.
*/
static void
{
char *outdata;
char *xdrbuf;
extern mutex_t proglst_lock;
/*
* enforce "procnum 0 is echo" convention
*/
(const char *) "svc_sendreply failed");
}
return;
}
(void) mutex_lock(&proglst_lock);
/* decode arguments into a CLEAN buffer */
/* Zero the arguments: reqd ! */
/*
* Assuming that sizeof (xdrbuf) would be enough
* for the arguments; if not then the program
* may bomb. BEWARE!
*/
(void) mutex_unlock(&proglst_lock);
return;
}
/* there was an error */
(void) mutex_unlock(&proglst_lock);
return;
}
"rpc: rpc_reg trouble replying to prog %d vers %d",
(void) mutex_unlock(&proglst_lock);
return;
}
/* free the decoded arguments */
(void) mutex_unlock(&proglst_lock);
return;
}
}
(void) mutex_unlock(&proglst_lock);
/* This should never happen */
"rpc: rpc_reg: never registered prog %d vers %d",
}