Port to TI/RPC and/or IPV6.

Submitted by: Jean-Luc Richier <Jean-Luc.Richier@imag.fr>
This commit is contained in:
Alfred Perlstein 2002-07-15 18:51:57 +00:00
parent 122b088a2a
commit af37179b5f
7 changed files with 131 additions and 123 deletions

View File

@ -32,9 +32,9 @@ static const char rcsid[] =
#include <ufs/ufs/quota.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/rquota.h>
#include <arpa/inet.h>
#include <netdb.h>
void rquota_service(struct svc_req *request, SVCXPRT *transp);
void sendquota(struct svc_req *request, SVCXPRT *transp);
@ -60,7 +60,7 @@ int from_inetd = 1;
void
cleanup(int sig)
{
(void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
(void) rpcb_unset(RQUOTAPROG, RQUOTAVERS, NULL);
exit(0);
}
@ -68,22 +68,19 @@ int
main(int argc, char *argv[])
{
SVCXPRT *transp;
int sock = 0;
int proto = 0;
struct sockaddr_in from;
int ok;
struct sockaddr_storage from;
int fromlen;
fromlen = sizeof(from);
if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
from_inetd = 0;
sock = RPC_ANYSOCK;
proto = IPPROTO_UDP;
}
if (!from_inetd) {
daemon(0, 0);
(void) pmap_unset(RQUOTAPROG, RQUOTAVERS);
(void) rpcb_unset(RQUOTAPROG, RQUOTAVERS, NULL);
(void) signal(SIGINT, cleanup);
(void) signal(SIGTERM, cleanup);
@ -93,13 +90,19 @@ main(int argc, char *argv[])
openlog("rpc.rquotad", LOG_CONS|LOG_PID, LOG_DAEMON);
/* create and register the service */
transp = svcudp_create(sock);
if (transp == NULL) {
syslog(LOG_ERR, "couldn't create udp service");
exit(1);
}
if (!svc_register(transp, RQUOTAPROG, RQUOTAVERS, rquota_service, proto)) {
syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, %s)", proto?"udp":"(inetd)");
if (from_inetd) {
transp = svc_tli_create(0, NULL, NULL, 0, 0);
if (transp == NULL) {
syslog(LOG_ERR, "couldn't create udp service.");
exit(1);
}
ok = svc_reg(transp, RQUOTAPROG, RQUOTAVERS,
rquota_service, NULL);
} else
ok = svc_create(rquota_service,
RQUOTAPROG, RQUOTAVERS, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RQUOTAPROG, RQUOTAVERS, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
@ -184,14 +187,15 @@ sendquota(struct svc_req *request, SVCXPRT *transp)
void
printerr_reply(SVCXPRT *transp) /* when a reply to a request failed */
{
char *name;
struct sockaddr_in *caller;
char name[INET6_ADDRSTRLEN];
struct sockaddr *caller;
int save_errno;
save_errno = errno;
caller = svc_getcaller(transp);
name = (char *)inet_ntoa(caller->sin_addr);
caller = (struct sockaddr *)svc_getrpccaller(transp)->buf;
getnameinfo(caller, caller->sa_len, name, sizeof (name),
NULL, 0, NI_NUMERICHOST);
errno = save_errno;
if (errno == 0)
syslog(LOG_ERR, "couldn't send reply to %s", name);

View File

@ -40,7 +40,6 @@ static const char rcsid[] =
#include <rpc/rpc.h>
#include <signal.h>
#include <syslog.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/rstat.h>
extern void rstat_service(struct svc_req *, SVCXPRT *);
@ -51,9 +50,9 @@ int closedown = 20; /* how long to wait before going dormant */
void
cleanup(int sig __unused)
{
(void) pmap_unset(RSTATPROG, RSTATVERS_TIME);
(void) pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
(void) pmap_unset(RSTATPROG, RSTATVERS_ORIG);
(void) rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL);
(void) rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL);
(void) rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL);
exit(0);
}
@ -61,9 +60,8 @@ int
main(int argc, char *argv[])
{
SVCXPRT *transp;
int sock = 0;
int proto = 0;
struct sockaddr_in from;
int ok;
struct sockaddr_storage from;
int fromlen;
if (argc == 2)
@ -77,16 +75,14 @@ main(int argc, char *argv[])
fromlen = sizeof(from);
if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
from_inetd = 0;
sock = RPC_ANYSOCK;
proto = IPPROTO_UDP;
}
if (!from_inetd) {
daemon(0, 0);
(void)pmap_unset(RSTATPROG, RSTATVERS_TIME);
(void)pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
(void)pmap_unset(RSTATPROG, RSTATVERS_ORIG);
(void)rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL);
(void)rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL);
(void)rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL);
(void) signal(SIGINT, cleanup);
(void) signal(SIGTERM, cleanup);
@ -95,22 +91,40 @@ main(int argc, char *argv[])
openlog("rpc.rstatd", LOG_CONS|LOG_PID, LOG_DAEMON);
transp = svcudp_create(sock);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service");
exit(1);
if (from_inetd) {
transp = svc_tli_create(0, NULL, NULL, 0, 0);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service.");
exit(1);
}
ok = svc_reg(transp, RSTATPROG, RSTATVERS_TIME,
rstat_service, NULL);
} else
ok = svc_create(rstat_service,
RSTATPROG, RSTATVERS_TIME, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
if (!svc_register(transp, RSTATPROG, RSTATVERS_TIME, rstat_service, proto)) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", proto?"udp":"(inetd)");
exit(1);
if (from_inetd)
ok = svc_reg(transp, RSTATPROG, RSTATVERS_SWTCH,
rstat_service, NULL);
else
ok = svc_create(rstat_service,
RSTATPROG, RSTATVERS_SWTCH, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
if (!svc_register(transp, RSTATPROG, RSTATVERS_SWTCH, rstat_service, proto)) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", proto?"udp":"(inetd)");
exit(1);
}
if (!svc_register(transp, RSTATPROG, RSTATVERS_ORIG, rstat_service, proto)) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", proto?"udp":"(inetd)");
exit(1);
if (from_inetd)
ok = svc_reg(transp, RSTATPROG, RSTATVERS_ORIG,
rstat_service, NULL);
else
ok = svc_create(rstat_service,
RSTATPROG, RSTATVERS_ORIG, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
svc_run();

View File

@ -38,7 +38,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <sys/socket.h>
#include <signal.h>
#include <syslog.h>
#define utmp rutmp
@ -52,8 +52,8 @@ int from_inetd = 1;
void
cleanup(int sig __unused)
{
(void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE);
(void) pmap_unset(RUSERSPROG, RUSERSVERS_ORIG);
(void) rpcb_unset(RUSERSPROG, RUSERSVERS_IDLE, NULL);
(void) rpcb_unset(RUSERSPROG, RUSERSVERS_ORIG, NULL);
exit(0);
}
@ -61,9 +61,8 @@ int
main(int argc, char *argv[])
{
SVCXPRT *transp;
int sock = 0;
int proto = 0;
struct sockaddr_in from;
int ok;
struct sockaddr_storage from;
int fromlen;
/*
@ -72,15 +71,13 @@ main(int argc, char *argv[])
fromlen = sizeof(from);
if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
from_inetd = 0;
sock = RPC_ANYSOCK;
proto = IPPROTO_UDP;
}
if (!from_inetd) {
daemon(0, 0);
(void) pmap_unset(RUSERSPROG, RUSERSVERS_IDLE);
(void) pmap_unset(RUSERSPROG, RUSERSVERS_ORIG);
(void) rpcb_unset(RUSERSPROG, RUSERSVERS_IDLE, NULL);
(void) rpcb_unset(RUSERSPROG, RUSERSVERS_ORIG, NULL);
(void) signal(SIGINT, cleanup);
(void) signal(SIGTERM, cleanup);
@ -89,18 +86,29 @@ main(int argc, char *argv[])
openlog("rpc.rusersd", LOG_CONS|LOG_PID, LOG_DAEMON);
transp = svcudp_create(sock);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service");
if (from_inetd) {
transp = svc_tli_create(0, NULL, NULL, 0, 0);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service.");
exit(1);
}
ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_IDLE,
rusers_service, NULL);
} else
ok = svc_create(rusers_service,
RUSERSPROG, RUSERSVERS_IDLE, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
if (!svc_register(transp, RUSERSPROG, RUSERSVERS_IDLE, rusers_service, proto)) {
syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_IDLE, %s)", proto?"udp":"(inetd)");
exit(1);
}
if (!svc_register(transp, RUSERSPROG, RUSERSVERS_ORIG, rusers_service, proto)) {
syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", proto?"udp":"(inetd)");
if (from_inetd)
ok = svc_reg(transp, RUSERSPROG, RUSERSVERS_ORIG,
rusers_service, NULL);
else
ok = svc_create(rusers_service,
RUSERSPROG, RUSERSVERS_ORIG, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (RUSERSPROG, RUSERSVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}

View File

@ -41,7 +41,6 @@ static const char rcsid[] =
#include <syslog.h>
#include <arpa/inet.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/rwall.h>
#include <sys/socket.h>
#include <sys/types.h>
@ -66,10 +65,8 @@ int
main(int argc, char *argv[])
{
SVCXPRT *transp;
int s, salen;
struct sockaddr_in sa;
int sock = 0;
int proto = 0;
int ok, salen;
struct sockaddr_storage sa;
if (argc == 2 && !strcmp(argv[1], "-n"))
nodaemon = 1;
@ -90,42 +87,33 @@ main(int argc, char *argv[])
salen = sizeof(sa);
if (getsockname(0, (struct sockaddr *)&sa, &salen) < 0) {
from_inetd = 0;
sock = RPC_ANYSOCK;
proto = IPPROTO_UDP;
}
if (!from_inetd) {
if (!nodaemon)
possess();
(void)pmap_unset(WALLPROG, WALLVERS);
if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
err(1, "socket");
bzero(&sa, sizeof sa);
if (bind(s, (struct sockaddr *)&sa, sizeof sa) < 0)
err(1, "bind");
salen = sizeof sa;
if (getsockname(s, (struct sockaddr *)&sa, &salen))
err(1, "getsockname");
pmap_set(WALLPROG, WALLVERS, IPPROTO_UDP, ntohs(sa.sin_port));
if (dup2(s, 0) < 0)
err(1, "dup2");
(void)pmap_unset(WALLPROG, WALLVERS);
(void)rpcb_unset(WALLPROG, WALLVERS, NULL);
}
(void)signal(SIGCHLD, killkids);
openlog("rpc.rwalld", LOG_CONS|LOG_PID, LOG_DAEMON);
transp = svcudp_create(sock);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service");
exit(1);
}
if (!svc_register(transp, WALLPROG, WALLVERS, wallprog_1, proto)) {
syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", proto?"udp":"(inetd)");
/* create and register the service */
if (from_inetd) {
transp = svc_tli_create(0, NULL, NULL, 0, 0);
if (transp == NULL) {
syslog(LOG_ERR, "couldn't create udp service.");
exit(1);
}
ok = svc_reg(transp, WALLPROG, WALLVERS,
wallprog_1, NULL);
} else
ok = svc_create(wallprog_1,
WALLPROG, WALLVERS, "udp");
if (!ok) {
syslog(LOG_ERR, "unable to register (WALLPROG, WALLVERS, %s)", (!from_inetd)?"udp":"(inetd)");
exit(1);
}
svc_run();

View File

@ -34,7 +34,6 @@ static const char rcsid[] =
#endif /* not lint */
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/spray.h>
#include <signal.h>
#include <stdio.h>
@ -63,7 +62,7 @@ static int from_inetd = 1;
void
cleanup(int sig __unused)
{
(void) pmap_unset(SPRAYPROG, SPRAYVERS);
(void) rpcb_unset(SPRAYPROG, SPRAYVERS, NULL);
exit(0);
}
@ -77,9 +76,8 @@ int
main(int argc, char *argv[])
{
SVCXPRT *transp;
int sock = 0;
int proto = 0;
struct sockaddr_in from;
int ok;
struct sockaddr_storage from;
int fromlen;
/*
@ -88,14 +86,12 @@ main(int argc, char *argv[])
fromlen = sizeof(from);
if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) {
from_inetd = 0;
sock = RPC_ANYSOCK;
proto = IPPROTO_UDP;
}
if (!from_inetd) {
daemon(0, 0);
(void) pmap_unset(SPRAYPROG, SPRAYVERS);
(void) rpcb_unset(SPRAYPROG, SPRAYVERS, NULL);
(void) signal(SIGINT, cleanup);
(void) signal(SIGTERM, cleanup);
@ -107,15 +103,21 @@ main(int argc, char *argv[])
openlog("rpc.sprayd", LOG_CONS|LOG_PID, LOG_DAEMON);
transp = svcudp_create(sock);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service");
return 1;
}
if (!svc_register(transp, SPRAYPROG, SPRAYVERS, spray_service, proto)) {
if (from_inetd) {
transp = svc_tli_create(0, NULL, NULL, 0, 0);
if (transp == NULL) {
syslog(LOG_ERR, "cannot create udp service.");
exit(1);
}
ok = svc_reg(transp, SPRAYPROG, SPRAYVERS,
spray_service, NULL);
} else
ok = svc_create(spray_service,
SPRAYPROG, SPRAYVERS, "udp");
if (!ok) {
syslog(LOG_ERR,
"unable to register (SPRAYPROG, SPRAYVERS, %s)",
proto ? "udp" : "(inetd)");
(!from_inetd)?"udp":"(inetd)");
return 1;
}

View File

@ -764,10 +764,10 @@ root_auth(trans, rqstp)
struct svc_req *rqstp;
{
uid_t uid;
struct sockaddr_in *remote;
struct sockaddr *remote;
remote = svc_getcaller(trans);
if (remote->sin_family == AF_INET) {
remote = svc_getrpccaller(trans)->buf;
if (remote->sa_family != AF_UNIX) {
if (debugging)
fprintf(stderr, "client didn't use AF_UNIX\n");
return (0);

View File

@ -44,7 +44,6 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <string.h>
#include <syslog.h>
#include <sys/types.h>
@ -71,19 +70,12 @@ main(int argc, char **argv)
debug = 1;
}
(void)pmap_unset(SM_PROG, SM_VERS);
(void)rpcb_unset(SM_PROG, SM_VERS, NULL);
transp = svcudp_create(RPC_ANYSOCK);
if (transp == NULL)
if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "udp"))
errx(1, "cannot create udp service");
if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_UDP))
errx(1, "unable to register (SM_PROG, SM_VERS, udp)");
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (transp == NULL)
if (!svc_create(sm_prog_1, SM_PROG, SM_VERS, "tcp"))
errx(1, "cannot create tcp service");
if (!svc_register(transp, SM_PROG, SM_VERS, sm_prog_1, IPPROTO_TCP))
errx(1, "unable to register (SM_PROG, SM_VERS, tcp)");
init_file("/var/db/statd.status");
/* Note that it is NOT sensible to run this program from inetd - the */