rpc.yppasswdd.c revision 1.3 1 /* $NetBSD: rpc.yppasswdd.c,v 1.3 1999/06/06 02:44:52 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1994 Mats O Jansson <moj (at) stacken.kth.se>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Mats O Jansson
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <sys/types.h>
35 #include <sys/wait.h>
36 #include <err.h>
37 #include <limits.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <signal.h>
42 #include <unistd.h>
43 #include <util.h>
44
45 #include <rpc/rpc.h>
46 #include <rpc/pmap_clnt.h>
47 #include <rpcsvc/yppasswd.h>
48
49 extern char *__progname; /* from crt0.s */
50
51 int noshell, nogecos, nopw, domake;
52 char make_arg[_POSIX2_LINE_MAX] = "make";
53
54 extern void make_passwd __P((yppasswd *, struct svc_req *, SVCXPRT *));
55
56 int main __P((int, char *[]));
57 void yppasswddprog_1 __P((struct svc_req *, SVCXPRT *));
58 void usage __P((void));
59
60 int
61 main(argc, argv)
62 int argc;
63 char *argv[];
64 {
65 SVCXPRT *transp;
66 int i;
67
68 for (i = 1; i < argc; i++) {
69 if (argv[i][0] == '-') {
70 if (strcmp("-noshell", argv[i]) == 0)
71 noshell = 1;
72 else if (strcmp("-nogecos", argv[i]) == 0)
73 nogecos = 1;
74 else if (strcmp("-nopw", argv[i]) == 0)
75 nopw = 1;
76 else if (strcmp("-m", argv[i]) == 0) {
77 domake = 1;
78 for (; i < argc; i++) {
79 strcat(make_arg, " ");
80 strcat(make_arg, argv[i]);
81 }
82 } else
83 usage();
84 } else
85 usage();
86 }
87
88 if (daemon(0, 0))
89 err(1, "can't detach");
90 pidfile(NULL);
91
92 (void) pmap_unset(YPPASSWDPROG, YPPASSWDVERS);
93
94 transp = svcudp_create(RPC_ANYSOCK);
95 if (transp == NULL)
96 errx(1, "cannot create UDP service");
97
98 if (!svc_register(transp, YPPASSWDPROG, YPPASSWDVERS, yppasswddprog_1,
99 IPPROTO_UDP))
100 errx(1, "unable to register YPPASSWDPROG/YPPASSWDVERS/UDP");
101
102 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
103 if (transp == NULL)
104 errx(1, "cannot create TCP service");
105
106 if (!svc_register(transp, YPPASSWDPROG, YPPASSWDVERS, yppasswddprog_1,
107 IPPROTO_TCP))
108 errx(1, "unable to register YPPASSWDPROG/YPPASSWDVERS/TCP");
109
110 svc_run();
111 errx(1, "svc_run returned");
112 }
113
114 void
115 yppasswddprog_1(rqstp, transp)
116 struct svc_req *rqstp;
117 SVCXPRT *transp;
118 {
119 union {
120 yppasswd yppasswdproc_update_1_arg;
121 } argument;
122
123 switch (rqstp->rq_proc) {
124 case NULLPROC:
125 (void) svc_sendreply(transp, xdr_void, (char *) NULL);
126 return;
127
128 case YPPASSWDPROC_UPDATE:
129 /*
130 * We'd like this to look like a regular RPC
131 * stub, but we have to send the reply in the
132 * handler in order to avoid both signal race
133 * conditions locally and timeouts on the
134 * client.
135 */
136 (void) memset(&argument, 0, sizeof(argument));
137 if (!svc_getargs(transp, xdr_yppasswd, (caddr_t) & argument)) {
138 svcerr_decode(transp);
139 return;
140 }
141 make_passwd((yppasswd *)&argument, rqstp, transp);
142 if (!svc_freeargs(transp, xdr_yppasswd, (caddr_t) &argument))
143 errx(1, "unable to free arguments");
144 return;
145 }
146
147 svcerr_noproc(transp);
148 }
149
150 void
151 usage()
152 {
153
154 fprintf(stderr, "usage: %s [-noshell] [-nogecos] [-nopw] "
155 "[-m arg1 arg2 ...]\n", __progname);
156 exit(1);
157 }
158