126213Swpaul/*
226213Swpaul * Copyright (c) 1995, 1996
326213Swpaul *	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
426213Swpaul *
526213Swpaul * Redistribution and use in source and binary forms, with or without
626213Swpaul * modification, are permitted provided that the following conditions
726213Swpaul * are met:
826213Swpaul * 1. Redistributions of source code must retain the above copyright
926213Swpaul *    notice, this list of conditions and the following disclaimer.
1026213Swpaul * 2. Redistributions in binary form must reproduce the above copyright
1126213Swpaul *    notice, this list of conditions and the following disclaimer in the
1226213Swpaul *    documentation and/or other materials provided with the distribution.
1326213Swpaul * 3. All advertising materials mentioning features or use of this software
1426213Swpaul *    must display the following acknowledgement:
1526213Swpaul *	This product includes software developed by Bill Paul.
1626213Swpaul * 4. Neither the name of the author nor the names of any co-contributors
1726213Swpaul *    may be used to endorse or promote products derived from this software
1826213Swpaul *    without specific prior written permission.
1926213Swpaul *
2026213Swpaul * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
2126213Swpaul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2226213Swpaul * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2326213Swpaul * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR CONTRIBUTORS BE LIABLE
2426213Swpaul * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2526213Swpaul * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2626213Swpaul * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2726213Swpaul * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2826213Swpaul * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2926213Swpaul * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3026213Swpaul * SUCH DAMAGE.
3126213Swpaul */
3226213Swpaul
3384220Sdillon#include <sys/cdefs.h>
3484220Sdillon__FBSDID("$FreeBSD$");
3584220Sdillon
3626213Swpaul#include <stdlib.h>
3726213Swpaul#include <rpc/rpc.h>
3826213Swpaul#include <rpcsvc/yp_prot.h>
3926213Swpaul#include <rpcsvc/ypclnt.h>
4026213Swpaul#include <rpcsvc/yppasswd.h>
4126213Swpaul#include <netinet/in.h>
4226213Swpaul
4326213Swpaul/*
4426213Swpaul * XXX <rpcsvc/yppasswd.h> does a typedef that makes 'yppasswd'
4526213Swpaul * a type of struct yppasswd. This leads to a namespace collision:
4626213Swpaul * gcc will not let you have a type called yppasswd and a function
4726213Swpaul * called yppasswd(). In order to get around this, we call the
4826213Swpaul * actual function _yppasswd() and put a macro called yppasswd()
4926213Swpaul * in yppasswd.h which calls the underlying function, thereby
5026213Swpaul * fooling gcc.
5126213Swpaul */
5226213Swpaul
5390298Sdesint
5490298Sdes_yppasswd(char *oldpass, struct x_passwd *newpw)
5526213Swpaul{
5626213Swpaul	char *server;
5726213Swpaul	char *domain;
5826213Swpaul	int rval, result;
5926213Swpaul	struct yppasswd yppasswd;
6026213Swpaul
6126213Swpaul	yppasswd.newpw = *newpw;
6226213Swpaul	yppasswd.oldpass = oldpass;
6326213Swpaul
6426213Swpaul	if (yp_get_default_domain(&domain))
6526213Swpaul		return (-1);
6626213Swpaul
6726213Swpaul	if (yp_master(domain, "passwd.byname", &server))
6826213Swpaul		return(-1);
6926213Swpaul
7026213Swpaul	rval = getrpcport(server, YPPASSWDPROG,
7126213Swpaul				YPPASSWDPROC_UPDATE, IPPROTO_UDP);
7226213Swpaul
7326213Swpaul	if (rval == 0 || rval >= IPPORT_RESERVED) {
7426213Swpaul		free(server);
7526213Swpaul		return(-1);
7626213Swpaul	}
7726213Swpaul
7826213Swpaul	rval = callrpc(server, YPPASSWDPROG, YPPASSWDVERS, YPPASSWDPROC_UPDATE,
79121529Speter		       (xdrproc_t)xdr_yppasswd, (char *)&yppasswd,
80121529Speter		       (xdrproc_t)xdr_int, (char *)&result);
8126213Swpaul
8226213Swpaul	free(server);
8326213Swpaul	if (rval || result)
8426213Swpaul		return(-1);
8526213Swpaul	else
8626213Swpaul		return(0);
8726213Swpaul}
88