1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-23 11:18:54 +00:00
freebsd/gnu/usr.bin/yppush/ypclnt.c
Bill Paul 9f6a77c541 Obtained from: The NYS project
This is a ported/modified version of the yppush program from the
yps-0.21 package from the NYS project. This program is used to propagate
updated NIS maps from an NIS master to an NIS slave. It's normally invoked
by /var/yp/Makefile.

This version of yppush has been modified in the following ways:

- Cleared up several Linux/BSD incompatibilities, largely involving
  header files.

- converted from GDBM to DB with extreme predjudice. (well, not really...)

- removed lots of ugly debugging code that really didn't do anyone any good.

- Fixed a couple of inaccurate/badly formatted error messages.

- Renamed some functions to avoid collisions with certain YP routines
  hidden inside libc.

- Small signal handling kludge: Linux has different struct sigaction
  that us.

- Incorporated some functions from the yps-0.21 library that yppush was
  dependent on.

Like ypxfr, this works, but could use come cleaning up.
1995-01-31 09:47:11 +00:00

129 lines
3.2 KiB
C

/*
YPS-0.2, NIS-Server for Linux
Copyright (C) 1994 Tobias Reber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Modified for use with FreeBSd 2.x by Bill Paul (wpaul@ctr.columbia.edu)
$Id$
*/
/*
* $Author: root $
* $Log: ypclnt.c,v $
* Revision 2.0 1994/01/06 16:58:48 root
* Version 2.0
*
* Revision 0.17 1994/01/02 22:48:22 root
* Added strict prototypes
*
* Revision 0.16 1994/01/02 20:09:39 root
* Added GPL notice
*
* Revision 0.15 1993/12/30 22:34:57 root
* *** empty log message ***
*
* Revision 0.14 1993/12/19 12:42:32 root
* *** empty log message ***
*
* Revision 0.13 1993/06/12 09:39:30 root
* Align with include-4.4
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <rpc/rpc.h>
#include <rpc/pmap_clnt.h>
#include <rpcsvc/yp.h>
/*
* ypclnt.h does not have a definition for struct dom_binding,
* although it is used there. It is defined in yp_prot.h, but
* we cannot use it here.
*/
struct dom_binding {
void * m;
};
#include <rpcsvc/ypclnt.h>
#if 0
#define SOCKSERVER 0x7f000001
#endif
static struct sockaddr_in ServerAddress;
static CLIENT *UdpClient=NULL, *TcpClient=NULL;
void
_yp_unbind(char *DomainName)
{
if (UdpClient) clnt_destroy(UdpClient);
UdpClient=NULL;
if (TcpClient) clnt_destroy(TcpClient);
TcpClient=NULL;
}
int
_yp_bind(struct sockaddr_in *ServerAddress, char *DomainName)
{
struct sockaddr_in UdpServerAddress, TcpServerAddress;
int UdpSockp, TcpSockp;
static struct timeval Wait = { 5, 0 };
if (UdpClient || TcpClient) yp_unbind(DomainName);
bcopy(ServerAddress, &UdpServerAddress, sizeof(*ServerAddress));
UdpServerAddress.sin_port=0;
UdpSockp=(RPC_ANYSOCK);
bcopy(ServerAddress, &TcpServerAddress, sizeof(*ServerAddress));
TcpServerAddress.sin_port=0;
TcpSockp=(RPC_ANYSOCK);
if ((UdpClient=clntudp_create(&UdpServerAddress, YPPROG, YPVERS,
Wait, &UdpSockp))==NULL) {
clnt_pcreateerror("UdpClient");
return(YPERR_RPC);
}
if ((TcpClient=clnttcp_create(&TcpServerAddress, YPPROG, YPVERS,
&TcpSockp, 0, 0))==NULL) {
clnt_pcreateerror("TcpClient");
return(YPERR_RPC);
}
return(0);
}
int
_yp_clear(char *DomainName)
{
void *resp;
int Status;
do {
if (UdpClient==NULL)
if ((Status=yp_bind(DomainName))) return(Status);
if ((resp=ypproc_clear_2(NULL, UdpClient))==NULL) {
clnt_perror(UdpClient, "_yp_clear");
_yp_unbind(DomainName);
}
} while(resp==NULL);
return 0;
}