1 /* $NetBSD: rpc.yppasswdd.c,v 1.12 2009/04/19 04:01:06 lukem Exp $ */
4 * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
31 __RCSID("$NetBSD: rpc.yppasswdd.c,v 1.12 2009/04/19 04:01:06 lukem Exp $");
34 #include <sys/types.h>
48 #include <rpc/pmap_clnt.h>
49 #include <rpcsvc/yppasswd.h>
53 int noshell
, nogecos
, nopw
;
54 char make_arg
[_POSIX2_LINE_MAX
] = "make";
56 int main(int, char *[]);
57 void yppasswddprog_1(struct svc_req
*, SVCXPRT
*);
61 main(int argc
, char *argv
[])
66 int maxrec
= RPC_MAXDATASIZE
;
68 for (i
= 1; i
< argc
; i
++) {
72 if (strcmp("d", arg
) == 0)
76 if (pw_setprefix(argv
[i
]) < 0)
77 err(EXIT_FAILURE
,NULL
);
79 else if (strcmp("noshell", arg
) == 0)
81 else if (strcmp("nogecos", arg
) == 0)
83 else if (strcmp("nopw", arg
) == 0)
85 else if (strcmp("m", arg
) == 0) {
88 len
= strlen(make_arg
);
91 for (; i
< argc
; i
++) {
94 arglen
= strlen(argv
[i
]);
95 if ((len
+ arglen
) > (int)(sizeof(make_arg
) - 2))
96 errx(EXIT_FAILURE
, strerror(E2BIG
));
97 make_arg
[len
++] = ' ';
98 (void)strcpy(&make_arg
[len
], argv
[i
]);
106 err(EXIT_FAILURE
, "can't detach");
109 rpc_control(RPC_SVC_CONNMAXREC_SET
, &maxrec
);
111 (void)pmap_unset(YPPASSWDPROG
, YPPASSWDVERS
);
113 transp
= svcudp_create(RPC_ANYSOCK
);
115 errx(EXIT_FAILURE
, "cannot create UDP service");
117 if (!svc_register(transp
, YPPASSWDPROG
, YPPASSWDVERS
, yppasswddprog_1
,
120 "unable to register YPPASSWDPROG/YPPASSWDVERS/UDP");
122 transp
= svctcp_create(RPC_ANYSOCK
, RPC_MAXDATASIZE
, RPC_MAXDATASIZE
);
124 errx(EXIT_FAILURE
, "cannot create TCP service");
126 if (!svc_register(transp
, YPPASSWDPROG
, YPPASSWDVERS
, yppasswddprog_1
,
129 "unable to register YPPASSWDPROG/YPPASSWDVERS/TCP");
132 errx(EXIT_FAILURE
, "svc_run returned");
137 yppasswddprog_1(struct svc_req
*rqstp
, SVCXPRT
*transp
)
140 yppasswd yppasswdproc_update_1_arg
;
143 switch (rqstp
->rq_proc
) {
145 (void)svc_sendreply(transp
, xdr_void
, (char *) NULL
);
148 case YPPASSWDPROC_UPDATE
:
150 * We'd like this to look like a regular RPC
151 * stub, but we have to send the reply in the
152 * handler in order to avoid both signal race
153 * conditions locally and timeouts on the
156 (void)memset(&argument
, 0, sizeof(argument
));
157 if (!svc_getargs(transp
, xdr_yppasswd
, (caddr_t
) & argument
)) {
158 svcerr_decode(transp
);
161 make_passwd((yppasswd
*)&argument
, rqstp
, transp
);
162 if (!svc_freeargs(transp
, xdr_yppasswd
, (caddr_t
) &argument
))
163 errx(EXIT_FAILURE
, "unable to free arguments");
167 svcerr_noproc(transp
);
174 fprintf(stderr
, "usage: %s [-d directory] [-noshell] [-nogecos] "
175 "[-nopw] [-m arg1 [arg2 ...]]\n", getprogname());