1 /* $NetBSD: yppasswdd_mkpw.c,v 1.16 2008/02/24 21:10:02 dholland Exp $ */
4 * Copyright (c) 1996 Jason R. Thorpe <thorpej@NetBSD.org>
7 * Copyright (c) 1994 Mats O Jansson <moj@stacken.kth.se>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * 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
32 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: yppasswdd_mkpw.c,v 1.16 2008/02/24 21:10:02 dholland Exp $");
37 #include <sys/types.h>
38 #include <sys/param.h>
41 #include <sys/resource.h>
58 #include <rpcsvc/yppasswd.h>
62 int handling_request
; /* simple mutex */
65 make_passwd(yppasswd
*argp
, struct svc_req
*rqstp
, SVCXPRT
*transp
)
69 char mpwd
[MAXPATHLEN
];
70 char buf
[8192]; /* from libutil */
75 #define REPLY(val) do { \
77 if (!svc_sendreply(transp, xdr_int, (caddr_t)&res)) \
78 svcerr_systemerr(transp); \
81 #define RETURN(val) do { \
83 handling_request = 0; \
87 if (handling_request
) {
88 warnx("already handling request; try again later");
94 (void)strlcpy(mpwd
, pw_getprefix(), sizeof(mpwd
));
95 (void)strlcat(mpwd
, _PATH_MASTERPASSWD
, sizeof(mpwd
));
96 fpw
= fopen(mpwd
, "r");
101 for(lineno
= 1; ; lineno
++) {
102 if (fgets(buf
, sizeof(buf
), fpw
) == NULL
) {
104 warnx("%s: %s not found", mpwd
,
105 argp
->newpw
.pw_name
);
107 warnx("%s: %s", mpwd
, strerror(errno
));
111 if ((p
= strchr(buf
, '\n')) == NULL
) {
112 warnx("line %d too long", lineno
);
116 /* get rid of trailing \n */
118 if (pw_scan(buf
, &pw
, NULL
) == 0)
120 if (strncmp(argp
->newpw
.pw_name
, pw
.pw_name
, MAXLOGNAME
) == 0)
125 strcmp(crypt(argp
->oldpass
, pw
.pw_passwd
), pw
.pw_passwd
) != 0)
131 warnx("the passwd file is busy.");
134 pfd
= open(mpwd
, O_RDONLY
, 0);
142 * Get the new password. Reset passwd change time to zero; when
143 * classes are implemented, go and get the "offset" value for this
144 * class and reset the timer.
147 pw
.pw_passwd
= argp
->newpw
.pw_passwd
;
151 pw
.pw_gecos
= argp
->newpw
.pw_gecos
;
153 pw
.pw_shell
= argp
->newpw
.pw_shell
;
155 pw_copy(pfd
, tfd
, &pw
, NULL
);
157 if (pw_mkdb(pw
.pw_name
, 0) < 0) {
158 warnx("pw_mkdb failed");
163 /* XXX RESTORE SIGNAL STATE? XXX */
165 /* Notify caller we succeeded. */
168 /* Update the YP maps. */
169 if (chdir("/var/yp"))
170 err(EXIT_FAILURE
, "/var/yp");
172 (void) system(make_arg
);
174 handling_request
= 0;