/*-
* Copyright (c) 2009, Sun Microsystems, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of Sun Microsystems, Inc. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1984 - 1991 by Sun Microsystems, Inc.
*/
/*
* Called for all the version 2 inquiries.
*/
void
pmap_service(struct svc_req *rqstp, SVCXPRT *xprt)
{
rpcbs_procinfo(RPCBVERS_2_STAT, rqstp->rq_proc);
switch (rqstp->rq_proc) {
case PMAPPROC_NULL:
/*
* Null proc call
*/
#ifdef RPCBIND_DEBUG
if (debugging)
fprintf(stderr, "PMAPPROC_NULL\n");
#endif
check_access(xprt, rqstp->rq_proc, NULL, PMAPVERS);
if ((!svc_sendreply(xprt, (xdrproc_t) xdr_void, NULL)) &&
debugging) {
if (doabort) {
rpcbind_abort();
}
}
break;
case PMAPPROC_SET:
/*
* Set a program, version to port mapping
*/
pmapproc_change(rqstp, xprt, rqstp->rq_proc);
break;
case PMAPPROC_UNSET:
/*
* Remove a program, version to port mapping.
*/
pmapproc_change(rqstp, xprt, rqstp->rq_proc);
break;
case PMAPPROC_GETPORT:
/*
* Lookup the mapping for a program, version and return its
* port number.
*/
pmapproc_getport(rqstp, xprt);
break;
case PMAPPROC_DUMP:
/*
* Return the current set of mapped program, version
*/
#ifdef RPCBIND_DEBUG
if (debugging)
fprintf(stderr, "PMAPPROC_DUMP\n");
#endif
pmapproc_dump(rqstp, xprt);
break;
case PMAPPROC_CALLIT:
/*
* Calls a procedure on the local machine. If the requested
* procedure is not registered this procedure does not return
* error information!!
* This procedure is only supported on rpc/udp and calls via
* rpc/udp. It passes null authentication parameters.
*/
rpcbproc_callit_com(rqstp, xprt, PMAPPROC_CALLIT, PMAPVERS);
break;
default:
svcerr_noproc(xprt);
break;
}
}
/*
* returns the item with the given program, version number. If that version
* number is not found, it returns the item with that program number, so that
* the port number is now returned to the caller. The caller when makes a
* call to this program, version number, the call will fail and it will
* return with PROGVERS_MISMATCH. The user can then determine the highest
* and the lowest version number for this program using clnt_geterr() and
* use those program version numbers.
*/
static struct pmaplist *
find_service_pmap(rpcprog_t prog, rpcvers_t vers, rpcprot_t prot)
{
register struct pmaplist *hit = NULL;
register struct pmaplist *pml;
for (pml = list_pml; pml != NULL; pml = pml->pml_next) {
if ((pml->pml_map.pm_prog != prog) ||
(pml->pml_map.pm_prot != prot))
continue;
hit = pml;
if (pml->pml_map.pm_vers == vers)
break;
}
return (hit);
}
/*
* Can't use getpwnam here. We might end up calling ourselves
* and looping.
*/
if (sc == NULL)
rpcbreg.r_owner = __UNCONST(rpcbind_unknown);
else if (sc->sc_uid == 0)
rpcbreg.r_owner = __UNCONST(rpcbind_superuser);
else {
/* r_owner will be strdup-ed later */
snprintf(uidbuf, sizeof uidbuf, "%d", sc->sc_uid);
rpcbreg.r_owner = uidbuf;
}