1 /* $NetBSD: pw_yp.c,v 1.22 2009/04/11 12:10:02 lukem Exp $ */
4 * Copyright (c) 1988 The Regents of the University of California.
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.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
34 static char sccsid
[] = "@(#)pw_yp.c 1.0 2/2/93";
36 __RCSID("$NetBSD: pw_yp.c,v 1.22 2009/04/11 12:10:02 lukem Exp $");
53 #include <rpcsvc/yp_prot.h>
54 #include <rpcsvc/ypclnt.h>
56 #define passwd yp_passwd_rec
57 #include <rpcsvc/yppasswd.h>
65 * Check if rpc.yppasswdd is running on the master YP server.
66 * XXX this duplicates some code, but is much less complex
67 * than the alternative.
78 if (!domain
&& yp_get_default_domain(&domain
) != 0)
82 * Find the host for the passwd map; it should be running
86 if (yp_master(domain
, "passwd.byname", &master
) != 0) {
93 * Ask the portmapper for the port of the daemon.
95 if ((rpcport
= getrpcport(master
, YPPASSWDPROG
, YPPASSWDPROC_UPDATE
,
100 * Successful contact with rpc.yppasswdd.
106 pw_yp(struct passwd
*pw
, uid_t ypuid
)
109 int r
, rpcport
, status
;
110 struct yppasswd yppw
;
117 if (!domain
&& (r
= yp_get_default_domain(&domain
)))
118 errx(1, "can't get local YP domain. Reason: %s",
122 * Find the host for the passwd map; it should be running
126 if ((r
= yp_master(domain
, "passwd.byname", &master
)) != 0) {
129 warnx("can't find the master YP server. Reason: %s",
135 * Ask the portmapper for the port of the daemon.
137 if ((rpcport
= getrpcport(master
, YPPASSWDPROG
, YPPASSWDPROC_UPDATE
,
138 IPPROTO_UDP
)) == 0) {
139 warnx("master YP server not running yppasswd daemon.\n\t%s\n",
140 "Can't change password.");
145 * Be sure the port is privileged
147 if (rpcport
>= IPPORT_RESERVED
) {
148 warnx("yppasswd daemon is on an invalid port.");
152 /* prompt for old password */
153 memset(&yppw
, 0, sizeof yppw
);
154 yppw
.oldpass
= getpass("Old password:");
160 /* tell rpc.yppasswdd */
161 yppw
.newpw
.pw_name
= strdup(pw
->pw_name
);
162 if (!yppw
.newpw
.pw_name
) {
166 yppw
.newpw
.pw_passwd
= strdup(pw
->pw_passwd
);
167 if (!yppw
.newpw
.pw_passwd
) {
171 yppw
.newpw
.pw_uid
= pw
->pw_uid
;
172 yppw
.newpw
.pw_gid
= pw
->pw_gid
;
173 yppw
.newpw
.pw_gecos
= strdup(pw
->pw_gecos
);
174 if (!yppw
.newpw
.pw_gecos
) {
178 yppw
.newpw
.pw_dir
= strdup(pw
->pw_dir
);
179 if (!yppw
.newpw
.pw_dir
) {
183 yppw
.newpw
.pw_shell
= strdup(pw
->pw_shell
);
184 if (!yppw
.newpw
.pw_shell
) {
189 client
= clnt_create(master
, YPPASSWDPROG
, YPPASSWDVERS
, "udp");
190 if (client
== NULL
) {
191 warnx("cannot contact yppasswdd on %s: Reason: %s",
192 master
, yperr_string(YPERR_YPBIND
));
195 client
->cl_auth
= authunix_create_default();
198 r
= clnt_call(client
, YPPASSWDPROC_UPDATE
,
199 xdr_yppasswd
, &yppw
, xdr_int
, &status
, tv
);
201 warnx("rpc to yppasswdd failed.");
204 printf("Couldn't change YP password.\n");
206 printf("%s %s, %s\n",
207 "The YP password information has been changed on",
208 master
, "the master YP passwd server.");
213 yppw_error(const char *name
, int yperr
, int eval
)
223 errx(eval
, "YP passwd information unchanged");
231 (void)printf("re-edit the password file? [y]: ");
232 (void)fflush(stdout
);
234 if (c
!= EOF
&& c
!= '\n')
235 while (getchar() != '\n');
237 yppw_error(NULL
, 0, 0);