pkg://yp-clients-2.2-7.src.rpm:31922/yp-clients-2.2.tar.gz
info downloads
yp-clients-2.2/ 40775 273 17 0 6055353463 11326 5 ustar swen man yp-clients-2.2/domainname/ 40775 273 17 0 6055353423 13432 5 ustar swen man yp-clients-2.2/domainname/Makefile 100660 273 17 1047 6052336214 15161 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS=domainname.o
PROG=domainname
all: $(PROG)
domainname: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(BINDIR)
(cd $(BINDIR) && ln -sf domainname nisdomainname) || exit 1;
yp-clients-2.2/domainname/domainname.c 100660 273 17 2416 5711170615 16000 0 ustar swen man /*
* This is my implementation of the domainname command.
* usage: domainname [nisdomain]
* without argument: prints the current domainname
* with argument: sets the domainname (you must be root to do this)
* --Swen (swen@uni-paderborn.de)
*/
/*
* $Log: domainname.c,v $
* Revision 2.2 1995/01/24 12:24:45 swen
* Added RCS keywords.
*
*/
static char rcsid[] = "$Id: domainname.c,v 2.2 1995/01/24 12:24:45 swen Exp $" ;
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define DOMAINNAMELEN 64+1
void
usage(void)
{
puts("usage: domainname [nisdomain]") ;
exit(1) ;
}
int
main(int argc, char *argv[])
{
char *name, *tmp ;
if (argc > 2)
usage();
name = (char *) malloc(DOMAINNAMELEN) ;
if (name == NULL)
{
perror("malloc") ;
exit(1) ;
}
if (argc < 2)
{
if (getdomainname(name, DOMAINNAMELEN) < 0)
{
perror("getdomainname");
free(name);
exit(1);
}
else
puts(name);
}
else
{
name = strcpy(name, argv[1]) ;
tmp = strchr(name, '\n') ;
if (tmp != NULL)
*tmp = '\0' ;
if (setdomainname(name, strlen(name)) < 0)
{
perror("setdomainname");
free(name);
exit(1);
}
}
free(name);
return(0);
}
yp-clients-2.2/Makeconfig 100664 273 17 1111 6052336171 13375 0 ustar swen man #
# Makefile for the YP clients
#
.EXPORT_ALL_VARIABLES:
GNU_MAKE=make
#MAKE=make
I486FLAGS=-m486
USRSBINDIR=${DEBDIR}/usr/sbin
USRBINDIR=${DEBDIR}/usr/bin
BINDIR=${DEBDIR}/bin
#
# Don't change anything below unless you know what you are doing.
#
# Where we are now.
SRCDIR:=$(shell pwd)
WFLAGS=-Wall -ansi -pedantic -Wtraditional -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wnested-externs
MKDIR=mkdir -p
MV =/bin/mv
CC = gcc $(I486FLAGS)
XCFLAGS = -D_GNU_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -Dlinux
MINUS_G=
XTRAFLAGS=$(XCFLAGS)
CPP =$(CC) -E $(INC)
RM =/bin/rm
yp-clients-2.2/Makefile 100664 273 17 1330 6052336173 13054 0 ustar swen man include ./Makeconfig
include ./Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
ifndef DAEMON
DAEMON = -DDAEMON
endif
SUBDIR= ypbind domainname ypwhich ypcat ypmatch yppoll ypset yppasswd
all: subdir
subdir:
for d in $(SUBDIR); do \
($(MAKE) -C $$d $(TARGET)) || exit 1; \
done
clean: FRC
$(RM) -f *.a *.o *~ core
$(MAKE) TARGET=clean subdir
install: subdir
$(MAKE) TARGET=install subdir
# install -o root -g root -m 0644 yp.conf.example ${DEBDIR}/etc/yp.conf
# install -o root -g root -m 0755 -d ${DEBDIR}/usr/doc/net
# install -o root -g root -m 0755 -d ${DEBDIR}/var/yp
# install -o root -g root -m 0644 README ${DEBDIR}/usr/doc/net/yp-clients.txt
# gzip -9f ${DEBDIR}/usr/doc/net/yp-clients.txt
FRC:
yp-clients-2.2/Makerules 100664 273 17 311 5443606722 13250 0 ustar swen man .SUFFIXES:
.SUFFIXES: .S .o .c .s .i
.s.o :
$(CC) $(CFLAGS) -c $<
.S.o :
$(CC) $(CFLAGS) -c $<
.c.o :
$(CC) $(CFLAGS) -c $<
.c.s :
$(CC) $(CFLAGS) -S $<
.c.i :
$(CC) $(CFLAGS) -E $< -o $*.i
yp-clients-2.2/xdr_yp.h 100664 273 17 2403 6005746434 13077 0 ustar swen man /*
* $Log: xdr_yp.h,v $
* Revision 2.2 1995/07/27 17:30:04 swen
* Removed __P() macros. We're using ANSI anyway.
*
* Revision 2.1 1995/01/24 12:24:30 swen
* Added RCS keywords.
*
*/
extern bool_t xdr_domainname (XDR *, char *);
extern bool_t xdr_peername (XDR *, char *);
extern bool_t xdr_datum (XDR *, datum *);
extern bool_t xdr_mapname (XDR *, char *);
extern bool_t xdr_ypreq_key (XDR *, struct ypreq_key *);
extern bool_t xdr_ypreq_nokey (XDR *, struct ypreq_nokey *);
extern bool_t xdr_yp_inaddr (XDR *, struct in_addr *);
extern bool_t xdr_ypbind_binding (XDR *, struct ypbind_binding *);
extern bool_t xdr_ypbind_resptype (XDR *, enum ypbind_resptype *);
extern bool_t xdr_ypbind_resp (XDR *, struct ypbind_resp *);
extern bool_t xdr_ypresp_val (XDR *, struct ypresp_val *);
extern bool_t xdr_ypbind_setdom (XDR *, struct ypbind_setdom *);
extern bool_t xdr_ypresp_key_val (XDR *, struct ypresp_key_val *);
extern bool_t xdr_ypresp_all_seq (XDR *, u_long *);
extern bool_t xdr_ypresp_master (XDR *, struct ypresp_master *);
extern bool_t xdr_ypmaplist_str (XDR *, char *);
extern bool_t xdr_ypmaplist (XDR *, struct ypmaplist *);
extern bool_t xdr_ypresp_maplist (XDR *, struct ypresp_maplist *);
extern bool_t xdr_ypresp_order (XDR *, struct ypresp_order *);
yp-clients-2.2/yp-clients.lsm 100664 273 17 1464 6055353235 14231 0 ustar swen man Begin3
Title: NIS clients for linux
Version: 2.2
Entered-date: 24NOV95
Description: These programs are used to turn your linux station into an NIS
(formerly YP) client. Provided are ypbind, ypcat, ypmatch,
yppoll, yppasswd, ypset and ypwhich. ypbind can use a file
/etc/yp.conf for setting the server, or it can use broadcast.
Keywords: NIS, YP, networking, yellow pages, network information system
Author: deraadt@fsa.ca (Theo de Raadt), swen@uni-paderborn.de
(Swen Thümmler), mrausch@ernie.mi.uni-koeln.de
(Michael Rausch)
Maintained-by: swen@uni-paderborn.de (Swen Thümmler)
Primary-site: ftp.uni-paderborn.de /pub/linux/local/yp
25kB yp-clients-2.2.tar.gz
Copying-policy: BSD, GNU for ypbind
End
yp-clients-2.2/yp.conf.example 100664 273 17 223 6052336020 14314 0 ustar swen man # /etc/yp.conf: configuration file for ypbind. See ypbind(8).
#
# Syntax:
# ypserver <Name_of_ypserver>
# e.g. ypserver server.my.internet.domain
yp-clients-2.2/ypbind/ 40775 273 17 0 6055353426 12612 5 ustar swen man yp-clients-2.2/ypbind/Makefile 100664 273 17 1633 6052336220 14340 0 ustar swen man #include ../Makeconfig
#
#include ../Makerules
CC = gcc -m486 -ansi -pedantic # -fbounds-checking
ifndef WFLAGS
WFLAGS = -Wall -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wnested-externs
endif
ifndef XCFLAGS
XCFLAGS = -D_POSIX_SOURCE -D_BSD_SOURCE
endif
ifndef OPTFLAGS
OPTFLAGS = -O2 -fno-strength-reduce
endif
INC = -I.
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
OBJS = daemon.o errorlog.o lockreg.o \
locktest.o openmax.o readn.o \
slave.o writen.o ypbind.o
PROG = ypbind
all: $(PROG)
ypbind: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRSBINDIR)
install -c -o root -g root -m 0644 $(PROG).man ${DEBDIR}/usr/man/man8/$(PROG).8
clean:
$(RM) -f core *.o *.a *~ $(PROG)
depend:
$(CC) -MM $(CFLAGS) *.c > .depend
#
# include a dependency file if one exists
#
ifeq (.depend,$(wildcard .depend))
include .depend
endif
yp-clients-2.2/ypbind/TODO 100664 273 17 244 6055352175 13357 0 ustar swen man Accept a list of servers for a domain, circulate between entries (or use
fallback entries if a server fails).
Make use of mmap() or SysV-IPC command-line options.
yp-clients-2.2/ypbind/daemon.c 100664 273 17 5013 6005177526 14315 0 ustar swen man /*
* $Log: daemon.c,v $
* Revision 1.1 1995/07/25 14:27:34 swen
* ypbind version 2.0.
*
* Revision 2.3 1995/01/24 12:24:20 swen
* Added RCS keywords.
*
*/
static char rcsid[] = "$Id: daemon.c,v 1.1 1995/07/25 14:27:34 swen Exp $" ;
/*
* Initialize a daemon process.
*/
#include <stdio.h>
#include <signal.h>
#include <sys/param.h>
#include <errno.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include "ourhdr.h"
extern int errno;
/*
* Detach a daemon process from login session context.
*/
void
daemon_start(void)
/* nonzero -> handle SIGCLDs so zombies don't clog */
{
register int childpid, fd;
/*
* If we were started by init (process 1) from the /etc/inittab file
* there's no need to detach.
* This test is unreliable due to an unavoidable ambiguity
* if the process is started by some other process and orphaned
* (i.e., if the parent process terminates before we are started).
*/
if (getppid() == 1)
goto out;
/*
* Ignore the terminal stop signals (BSD).
*/
#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif
/*
* If we were not started in the background, fork and
* let the parent exit. This also guarantees the first child
* is not a process group leader.
*/
if ( (childpid = fork()) < 0)
log_sys("can't fork first child");
else if (childpid > 0)
exit(0); /* parent */
/*
* First child process.
*
* Disassociate from controlling terminal and process group.
* Ensure the process can't reacquire a new controlling terminal.
*/
if (setsid() == -1)
log_sys("setsid");
if ( (childpid = fork()) < 0)
log_sys("can't fork second child");
else if (childpid > 0)
exit(0); /* first child */
/* second child */
out:
/*
* Close any open files descriptors.
*/
for (fd = open_max()-1; fd >= 0; fd--)
close(fd);
errno = 0; /* probably got set to EBADF from a close */
/*
* Move the current directory to root, to make sure we
* aren't on a mounted filesystem.
*/
chdir("/");
/*
* Clear any inherited file mode creation mask.
*/
umask(0);
/*
* stdin, stdout and stderr -> /dev/null
*/
fd = open("/dev/null", O_RDWR);
dup(fd);
dup(fd);
}
yp-clients-2.2/ypbind/daemon.h 100664 273 17 312 6005177531 14273 0 ustar swen man /*
* $Log: daemon.h,v $
* Revision 1.1 1995/07/25 14:27:37 swen
* ypbind version 2.0.
*
* Revision 2.2 1995/01/24 12:24:23 swen
* Added RCS keywords.
*
*/
extern void daemon_start(void);
yp-clients-2.2/ypbind/errorlog.c 100664 273 17 3743 6005177533 14713 0 ustar swen man /* Error routines for programs that can run as a daemon. */
#include <errno.h> /* for definition of errno */
#include <stdarg.h> /* ANSI C header file */
#include <syslog.h>
#include <stdio.h>
#include <string.h>
#include "ourhdr.h"
static void log_doit(int, int, const char *, va_list ap);
extern int debug; /* caller must define and set this:
nonzero if interactive, zero if daemon */
/* Initialize syslog(), if running as daemon. */
void
log_open(const char *ident, int option, int facility)
{
if (debug == 0)
openlog(ident, option, facility);
}
/* Nonfatal error related to a system call.
* Print a message with the system's errno value and return. */
void
log_ret(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
log_doit(1, LOG_ERR, fmt, ap);
va_end(ap);
return;
}
/* Fatal error related to a system call.
* Print a message and terminate. */
void
log_sys(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
log_doit(1, LOG_ERR, fmt, ap);
va_end(ap);
exit(2);
}
/* Nonfatal error unrelated to a system call.
* Print a message and return. */
void
log_msg(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
log_doit(0, LOG_ERR, fmt, ap);
va_end(ap);
return;
}
/* Fatal error unrelated to a system call.
* Print a message and terminate. */
void
log_quit(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
log_doit(0, LOG_ERR, fmt, ap);
va_end(ap);
exit(2);
}
/* Print a message and return to caller.
* Caller specifies "errnoflag" and "priority". */
static void
log_doit(int errnoflag, int priority, const char *fmt, va_list ap)
{
int errno_save;
char buf[2048];
errno_save = errno; /* value caller might want printed */
vsprintf(buf, fmt, ap);
if (errnoflag)
sprintf(buf+strlen(buf), ": %s", strerror(errno_save));
strcat(buf, "\n");
if (debug)
{
fflush(stdout);
fputs(buf, stderr);
fflush(stderr);
}
else
syslog(priority, buf);
return;
}
yp-clients-2.2/ypbind/lockreg.c 100664 273 17 654 6005177536 14467 0 ustar swen man #include <sys/types.h>
#include <fcntl.h>
#include "ourhdr.h"
int
lock_reg(int fd, int cmd, int type, off_t offset, int whence, off_t len)
{
struct flock lock;
lock.l_type = type; /* F_RDLCK, F_WRLCK, F_UNLCK */
lock.l_start = offset; /* byte offset, relative to l_whence */
lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
lock.l_len = len; /* #bytes (0 means to EOF) */
return( fcntl(fd, cmd, &lock) );
}
yp-clients-2.2/ypbind/locktest.c 100664 273 17 1145 6005177540 14700 0 ustar swen man #include <sys/types.h>
#include <fcntl.h>
#include "ourhdr.h"
pid_t
lock_test(int fd, int type, off_t offset, int whence, off_t len)
{
struct flock lock;
lock.l_type = type; /* F_RDLCK or F_WRLCK */
lock.l_start = offset; /* byte offset, relative to l_whence */
lock.l_whence = whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
lock.l_len = len; /* #bytes (0 means to EOF) */
if (fcntl(fd, F_GETLK, &lock) < 0)
log_sys("fcntl error");
if (lock.l_type == F_UNLCK)
return(0); /* false, region is not locked by another proc */
return(lock.l_pid); /* true, return pid of lock owner */
}
yp-clients-2.2/ypbind/openmax.c 100664 273 17 1037 6005177543 14522 0 ustar swen man #include <errno.h>
#include <limits.h>
#include "ourhdr.h"
#ifdef OPEN_MAX
static int openmax = OPEN_MAX;
#else
static int openmax = 0;
#endif
#define OPEN_MAX_GUESS 256 /* if OPEN_MAX is indeterminate */
/* we're not guaranteed this is adequate */
int
open_max(void)
{
if (openmax == 0) { /* first time through */
errno = 0;
if ( (openmax = sysconf(_SC_OPEN_MAX)) < 0) {
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
log_sys("sysconf error for _SC_OPEN_MAX");
}
}
return(openmax);
}
yp-clients-2.2/ypbind/ourhdr.h 100664 273 17 4745 6005177545 14376 0 ustar swen man /*
* This is from "Advanced Programming in the Unix Environment"
* by W.R. Stevens
*/
/* Our own header, to be included *after* all standard system headers */
#ifndef __ourhdr_h
#define __ourhdr_h
#include <sys/types.h> /* required for some of our prototypes */
#include <stdio.h> /* for convenience */
#include <stdlib.h> /* for convenience */
#include <string.h> /* for convenience */
#include <unistd.h> /* for convenience */
#define MAXLINE 4096 /* max line length */
#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
/* default file access permissions for new files */
#define DIR_MODE (FILE_MODE | S_IXUSR | S_IXGRP | S_IXOTH)
/* default permissions for new directories */
typedef void Sigfunc(int); /* for signal handlers */
/* 4.3BSD Reno <signal.h> doesn't define SIG_ERR */
#if defined(SIG_IGN) && !defined(SIG_ERR)
#define SIG_ERR ((Sigfunc *)-1)
#endif
#define min(a,b) ((a) < (b) ? (a) : (b))
#define max(a,b) ((a) > (b) ? (a) : (b))
/* prototypes for our own functions */
char *path_alloc(int *); /* {Prog pathalloc} */
int open_max(void); /* {Prog openmax} */
void clr_fl(int, int); /* {Prog setfl} */
void set_fl(int, int); /* {Prog setfl} */
void pr_exit(int); /* {Prog prexit} */
void pr_mask(const char *); /* {Prog prmask} */
ssize_t readn(int, void *, size_t);/* {Prog readn} */
ssize_t writen(int, const void *, size_t);/* {Prog writen} */
int lock_reg(int, int, int, off_t, int, off_t);
/* {Prog lockreg} */
#define read_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
#define readw_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
#define write_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
#define writew_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
#define un_lock(fd, offset, whence, len) \
lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
pid_t lock_test(int, int, off_t, int, off_t);
/* {Prog locktest} */
#define is_readlock(fd, offset, whence, len) \
lock_test(fd, F_RDLCK, offset, whence, len)
#define is_writelock(fd, offset, whence, len) \
lock_test(fd, F_WRLCK, offset, whence, len)
void log_msg(const char *, ...); /* {App misc_source} */
void log_open(const char *, int, int);
void log_quit(const char *, ...);
void log_ret(const char *, ...);
void log_sys(const char *, ...);
void daemon_start(void);
#endif /* __ourhdr_h */
yp-clients-2.2/ypbind/patchlevel.h 100664 273 17 35 6037450311 15134 0 ustar swen man #define YPBIND_VERSION "2.1"
yp-clients-2.2/ypbind/readn.c 100664 273 17 637 6052333703 14123 0 ustar swen man #include "ourhdr.h"
ssize_t /* Read "n" bytes from a descriptor. */
readn(int fd, void *vptr, size_t n)
{
ssize_t nleft;
size_t nread;
char *ptr;
ptr = vptr;
nleft = n;
while (nleft > 0) {
if ( (nread = read(fd, ptr, nleft)) < 0)
return(nread); /* error, return < 0 */
else if (nread == 0)
break; /* EOF */
nleft -= nread;
ptr += nread;
}
return(n - nleft); /* return >= 0 */
}
yp-clients-2.2/ypbind/slave.c 100664 273 17 46123 6052335644 14212 0 ustar swen man #include <sys/types.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <stdarg.h>
#include <string.h> /* strcmp */
#include <ctype.h>
#include <memory.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h> /* setsid */
#include <fcntl.h>
#include <syslog.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <rpc/pmap_clnt.h> /* for pmap_unset */
#include "ourhdr.h"
#include "ypbind.h"
#if USE_IPC
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#endif
extern int putenv(const char *);
extern SVCXPRT *udptransp;
extern domainname mydomain;
extern int broken_server;
extern int debug;
extern char **Argv;
extern int Argc;
struct binding *ypbindlist;
#if USE_IPC
int semid = -1;
#else
int lockfd;
#endif
domainname askdomain;
volatile int hangup;
pid_t
start_slave(void)
{
struct sigaction sact;
pid_t pid;
pid = fork();
if (pid < 0)
log_sys("fork failed");
if (0 != pid) /* parent */
return pid;
inststr(Argv, Argc, "ypbind (slave)");
sigemptyset(&sact.sa_mask);
sact.sa_handler = toggle_debug;
sact.sa_flags = SA_RESTART;
if (0 != sigaction(SIGUSR1, &sact, NULL))
log_ret("Could not install signal handler for SIGUSR1");
sact.sa_handler = handle_hangup;
if (0 != sigaction(SIGHUP, &sact, NULL))
log_ret("Could not install signal handler for SIGHUP");
for(;;)
{
hangup = 0;
init_binding();
for(;!hangup;)
{
check_binding();
sleep(PING_INTERVAL);
}
}
}
void
init_binding(void)
{
struct binding ypdb;
write_lock_binding();
bzero(ypbindlist, sizeof(struct binding) * _MAXDOMAIN);
#if !MMAP_SHARED_OK
lseek(lockfd, 0, SEEK_SET);
writen(lockfd, ypbindlist, sizeof(struct binding) * _MAXDOMAIN);
#endif
un_lock_write_binding();
memset((void *)&ypdb, 0, sizeof(struct binding));
strncpy(ypdb.domain, mydomain, YPMAXDOMAIN);
ypdb.is_bound = TRUE; /* always bind to our NIS domain */
ypdb.lockfd = -1;
ypdb.client_handle = NULL;
ypdb.is_alive = FALSE;
ypdb.use_broadcast = TRUE; /* default is using broadcast */
update_entry(&ypdb);
parse_config_file(_PATH_YPCONF);
return;
}
void
check_binding(void)
{
struct binding ypdb;
time_t t;
int i;
time(&t);
for (i = 0; i < _MAXDOMAIN; i++)
{
read_lock_binding();
memcpy(&ypdb, &ypbindlist[i], sizeof ypdb);
un_lock_read_binding();
if (ypdb.is_bound)
{
if (ypdb.is_alive && ypdb.next_check > t)
{
if (debug)
log_msg("pinging server %s, port %d",
inet_ntoa(ypdb.server_addr),
ntohs(ypdb.server_port));
ping_server(&ypdb);
}
if (!ypdb.is_alive || ypdb.next_check <= t)
{
if (ypdb.use_broadcast)
{
if (debug)
log_msg("broadcasting for domain %s", ypdb.domain);
broadcast(&ypdb);
}
else
{
if (debug)
log_msg("rebinding to server %s", ypdb.host->h_name);
bindto_server(ypdb.domain, ypdb.host);
}
continue;
}
}
}
}
void
add_server(char *dom, struct sockaddr_in *raddrp, CLIENT *clnt_handlep, struct hostent *host, bool_t use_broadcast)
{
struct binding entry;
#if USE_BINDINGDIR
struct iovec iov[2];
struct ypbind_resp ybr;
pid_t lockpid;
char path[MAXPATHLEN];
int fd, len, status;
#endif
if (NULL == dom || (0 != get_entry(dom, &entry)))
return;
if (!entry.is_bound)
{
strncpy(entry.domain, dom, YPMAXDOMAIN);
entry.lockfd = -1;
entry.client_handle = NULL;
entry.is_bound = TRUE;
}
if (NULL != raddrp)
{
if (!broken_server &&
(ntohs(raddrp->sin_port) >= IPPORT_RESERVED ||
ntohs(raddrp->sin_port) < IPPORT_RESERVED/2))
{
log_msg("Answer from %s on illegal port", inet_ntoa(raddrp->sin_addr));
return;
}
memcpy(&entry.server_addr, &raddrp->sin_addr, sizeof entry.server_addr);
entry.server_port = raddrp->sin_port;
entry.is_alive = TRUE;
}
if (NULL != entry.client_handle)
clnt_destroy(entry.client_handle);
entry.client_handle = clnt_handlep;
if (NULL != host)
entry.host = host;
entry.next_check = time(NULL) + REBIND_INTERVAL;
entry.version = YPVERS;
entry.use_broadcast = use_broadcast;
#if USE_BINDINGDIR
if (NULL != raddrp)
{
if (-1 != entry.lockfd)
close(entry.lockfd);
sprintf(path, "%s/%s.%ld", BINDINGDIR,
entry.domain, entry.version);
if ((fd = open(path, O_CREAT | O_RDWR | O_TRUNC, FILE_MODE )) == -1)
{
if (-1 == mkdir(BINDINGDIR, DIR_MODE))
log_ret("mkdir");
if ((fd = open(path, O_CREAT | O_RDWR | O_TRUNC, FILE_MODE)) == -1)
return;
}
lockpid = lock_test(fd, F_RDLCK, 0, SEEK_SET, 0);
if (0 != lockpid)
log_quit("%s already locked by pid %d", path, lockpid);
status = read_lock(fd, 0, SEEK_SET, 0);
if (0 != status)
log_sys("set lock");
/*
* ok, if BINDINGDIR exists, and we can create the binding file, then
* write to it..
*/
entry.lockfd = fd;
iov[0].iov_base = (caddr_t) &(udptransp->xp_port);
iov[0].iov_len = sizeof udptransp->xp_port;
iov[1].iov_base = (caddr_t) &ybr;
iov[1].iov_len = sizeof ybr;
bzero(&ybr, sizeof ybr);
ybr.ypbind_status = YPBIND_SUCC_VAL;
ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr = raddrp->sin_addr;
ybr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port = raddrp->sin_port;
len = iov[0].iov_len + iov[1].iov_len ;
if (writev(entry.lockfd, iov, 2) != len )
{
log_ret("writev");
close(entry.lockfd);
(void) unlink(path);
entry.lockfd = -1;
}
}
#endif
update_entry(&entry);
return;
}
void
bindto_server(char *ypdomain, struct hostent *host)
{
struct sockaddr_in server_addr;
int sock;
bool_t out;
enum clnt_stat status;
struct timeval timeout;
CLIENT *clnt_handlep = NULL;
int i = 0;
if (debug)
log_msg("bindto_server: domain %s, host %s", ypdomain, host->h_name);
bzero((char *)&server_addr, sizeof server_addr);
server_addr.sin_family = host->h_addrtype;
server_addr.sin_port = htons(0);
sock = RPC_ANYSOCK;
while(NULL != host->h_addr_list[i])
{
memcpy(&server_addr.sin_addr, host->h_addr_list[i],
host->h_length);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
clnt_handlep = clntudp_create(&server_addr, YPPROG, YPVERS,
timeout, &sock);
if (NULL != clnt_handlep)
break;
i++;
}
if (NULL == clnt_handlep)
{
log_msg("clnt_create for server %s failed", host->h_name);
return;
}
timeout.tv_sec = 5;
timeout.tv_usec = 0;
status = clnt_call(clnt_handlep, YPPROC_DOMAIN,
(xdrproc_t) xdr_domainname, ypdomain,
(xdrproc_t) xdr_bool, &out,
timeout);
if (RPC_SUCCESS != status)
{
log_msg(clnt_sperror(clnt_handlep, host->h_name));
clnt_destroy(clnt_handlep);
}
else if (TRUE != out)
{
log_msg("domain %s not served by %s", ypdomain, host->h_name);
clnt_destroy(clnt_handlep);
}
else
add_server(ypdomain, &server_addr, clnt_handlep, host, FALSE);
return;
}
void
ping_server(struct binding *ypdb)
{
int status;
struct timeval timeout;
char *nothing;
if (NULL != ypdb->client_handle)
{
bzero((char *)¬hing, sizeof nothing);
timeout.tv_sec = 2;
timeout.tv_usec = 0;
status = clnt_call(ypdb->client_handle, YPPROC_NULL,
(xdrproc_t) xdr_void, nothing,
(xdrproc_t) xdr_void, ¬hing,
timeout);
if (RPC_SUCCESS != status)
{
log_msg(clnt_sperror(ypdb->client_handle, ypdb->host->h_name));
clnt_destroy(ypdb->client_handle);
ypdb->client_handle = NULL;
ypdb->is_alive = FALSE;
ypdb->next_check = time(NULL);
update_entry(ypdb);
}
}
return;
}
bool_t
eachresult(bool_t *out, struct sockaddr_in *addr)
{
CLIENT *clnt_handlep;
struct timeval timeout;
int sock;
if (*out)
{
if(debug)
{
struct hostent *hostentp;
hostentp = gethostbyaddr((char *) &addr->sin_addr.s_addr,
sizeof(addr->sin_addr.s_addr), AF_INET);
log_msg("Answer from server %s .", hostentp->h_name);
}
sock = RPC_ANYSOCK;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
clnt_handlep = clntudp_create(addr, YPPROG, YPVERS, timeout, &sock);
add_server(askdomain, addr, clnt_handlep, NULL, TRUE);
return 1;
}
else
{
return 0;
}
}
void
broadcast(struct binding *ypdb)
{
bool_t out;
enum clnt_stat status;
#if USE_BINDINGDIR
char path[MAXPATHLEN];
#endif
/* update global variable for eachresult */
askdomain = ypdb->domain;
status = clnt_broadcast(YPPROG, YPVERS, YPPROC_DOMAIN_NONACK,
(xdrproc_t) xdr_domainname, askdomain,
(xdrproc_t) xdr_bool, (void *)&out,
(resultproc_t) eachresult);
if (RPC_SUCCESS != status)
{
#if USE_BINDINGDIR
if ( -1 != ypdb->lockfd)
{
close(ypdb->lockfd);
ypdb->lockfd = -1;
sprintf(path, "%s/%s.%ld", BINDINGDIR,
ypdb->domain, ypdb->version);
unlink(path);
}
#endif
log_msg("broadcast: %s.", clnt_sperrno(status));
}
}
/*
* Routines for parsing the config file ( /etc/yp.conf )
*
*/
void
parse_config_file(const char *path)
/* parse the config file, check bindings */
{
FILE *fp;
char buf[1024];
char *cp, *tmp;
char tmpserver[81], tmpdomain[YPMAXDOMAIN + 1];
int count;
fp = fopen(path, "r");
if (NULL == fp)
return;
if (debug)
log_msg("parsing config file");
while ((cp = fgets(buf, sizeof(buf), fp)) != NULL)
{
tmp = strchr(cp, '#'); /* Kommentare ausblenden */
if (tmp)
*tmp = '\0';
while (isspace(*cp)) /* Leerraum ueberlesen */
cp++;
if (*cp == '\0') /* Leerzeile ignorieren */
continue;
if (debug)
log_msg("Trying entry: %s", cp);
count = sscanf(cp, "domain %64s server %80s", tmpdomain, tmpserver);
if (2 == count)
{
if (debug)
log_msg("parsed domain %s server %s", tmpdomain, tmpserver);
check_config_entry(tmpdomain, tmpserver);
continue;
}
count = sscanf(cp, "domain %s broadcast", tmpdomain);
if (1 == count)
{
if (debug)
log_msg("parsed domain %s broadcast", tmpdomain);
add_server(mydomain, NULL, NULL, NULL, TRUE);
continue;
}
count = sscanf(cp, "ypserver %80s", tmpserver);
if (1 == count)
{
if (debug)
log_msg("parsed ypserver %s", tmpserver);
check_config_entry(mydomain, tmpserver);
continue;
}
}
fclose(fp);
return;
}
void
check_config_entry(char *ypdomain, const char *ypserver)
{
struct hostent *host;
static char *order = NULL;
int result;
/*
* FIXME: gethostbyname may in turn ask ypbind (entry in
* /etc/host.conf)!!!
* so much for shooting yourself in the foot.
* Using RESOLV_SERV_ORDER is a kludge, should use gethostent()
*/
if (!order)
order = strdup("RESOLV_SERV_ORDER=hosts");
result = putenv(order);
if (0 != result)
log_ret("putenv failed");
if (debug)
log_msg("getenv: %s", getenv("RESOLV_SERV_ORDER"));
host = gethostbyname(ypserver);
if (NULL == host)
{
switch (h_errno)
{
case HOST_NOT_FOUND:
log_msg("Unknown host: %s", ypserver);
break;
case TRY_AGAIN:
log_msg("Host name lookup failure");
break;
case NO_DATA:
log_msg("No address associated with name: %s", ypserver);
break;
case NO_RECOVERY:
log_msg("Unknown server error");
break;
default:
log_ret("gethostbyname: Unknown error");
break;
}
}
else
bindto_server(ypdomain, host);
return;
}
void
init_master_slave_communication(void)
{
#if USE_IPC
int shmid;
struct shmid_ds dummy;
ushort empty[2] = {0,0};
if ((semid = semget(IPC_PRIVATE, 2, IPC_CREAT|SHM_R|SHM_W)) < 0)
log_sys("cannot create semaphore");
if ((shmid = shmget(IPC_PRIVATE,
sizeof(struct binding) * _MAXDOMAIN,
IPC_CREAT|SHM_R|SHM_W)) < 0)
log_sys("cannot create shared memory segment");
ypbindlist = (struct binding *)shmat(shmid, NULL, 0);
/* mark it for deletion just in case we are not able to
handle it on our own. handles case of failed attachment
as well */
(void)shmctl(shmid, IPC_RMID, &dummy);
if (!ypbindlist)
log_sys("cannot attach to shared memory segment");
memset(ypbindlist, 0, sizeof(struct binding) * _MAXDOMAIN);
semctl(semid, 0, SETALL, empty);
#else
lockfd = open_lockfile();
#if MMAP_SHARED_OK
ypbindlist = (struct binding *) mmap(0, sizeof(struct binding) * _MAXDOMAIN,
(PROT_READ | PROT_WRITE),
#if MMAP_SHARED_ANON_OK
(MAP_ANON | MAP_SHARED), -1, 0);
#else
MAP_SHARED, lockfd, 0);
#endif /* MMAP_SHARED_ANON_OK */
if ((caddr_t) -1 == (caddr_t) ypbindlist)
log_sys("cannot create shared region");
#else
ypbindlist = (struct binding *) calloc(_MAXDOMAIN, sizeof(struct binding));
if (NULL == ypbindlist)
log_sys("cannot create shared region");
writen(lockfd, ypbindlist, sizeof(struct binding) * _MAXDOMAIN);
#endif /* MMAP_SHARED_OK */
#endif
}
#if USE_IPC
void
terminate_master_slave_communication(void)
{
if(semid != -1)
{
(void)semctl(semid, 0, IPC_RMID, NULL);
semid = -1;
}
}
#define IPC_LOCK_RETRY 5
void
read_lock_binding(void)
{
struct sembuf sops[2];
int i;
sops[0].sem_num = 1; /* check if write semaphore is clear */
sops[0].sem_op = 0;
sops[0].sem_flg = IPC_NOWAIT;
sops[1].sem_num = 0; /* then signal reading */
sops[1].sem_op = 1;
sops[1].sem_flg = SEM_UNDO|IPC_NOWAIT;
for(i=0; i<IPC_LOCK_RETRY; i++)
{
if (!semop(semid, sops, sizeof(sops)/sizeof(struct sembuf)))
break;
sleep(1);
}
if(i==IPC_LOCK_RETRY)
log_sys("cannot create read lock");
}
void
write_lock_binding(void)
{
struct sembuf sops[3];
int i;
sops[0].sem_num = 0; /* check if read semaphore is clear */
sops[0].sem_op = 0;
sops[0].sem_flg = IPC_NOWAIT;
sops[1].sem_num = 1; /* check if write semaphore is clear */
sops[1].sem_op = 0;
sops[1].sem_flg = IPC_NOWAIT;
sops[2].sem_num = 1; /* then signal writing */
sops[2].sem_op = 1;
sops[2].sem_flg = SEM_UNDO|IPC_NOWAIT;
for(i=0; i<IPC_LOCK_RETRY; i++)
{
if (!semop(semid, sops, sizeof(sops)/sizeof(struct sembuf)))
break;
sleep(1);
}
if(i==IPC_LOCK_RETRY)
log_sys("cannot create write lock");
}
void
un_lock_read_binding(void)
{
struct sembuf sops[1];
int i;
sops[0].sem_num = 0; /* clear read semaphore */
sops[0].sem_op = -1;
sops[0].sem_flg = SEM_UNDO|IPC_NOWAIT;
for(i=0; i<IPC_LOCK_RETRY; i++)
{
if (!semop(semid, sops, sizeof(sops)/sizeof(struct sembuf)))
break;
sleep(1);
}
if(i==IPC_LOCK_RETRY)
log_sys("error unlocking");
}
void
un_lock_write_binding(void)
{
struct sembuf sops[1];
int i;
sops[0].sem_num = 1; /* clear write semaphore */
sops[0].sem_op = -1;
sops[0].sem_flg = SEM_UNDO|IPC_NOWAIT;
for(i=0; i<IPC_LOCK_RETRY; i++)
{
if (!semop(semid, sops, sizeof(sops)/sizeof(struct sembuf)))
break;
sleep(1);
}
if(i==IPC_LOCK_RETRY)
log_sys("error unlocking");
}
#else
int
open_lockfile(void)
{
char name[L_tmpnam];
int fd;
if (NULL == tmpnam(name))
log_sys("tmpnam failed");
fd = open(name, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
if (fd < 0)
log_sys("cannot open lockfile");
/* Need to extend the file for mmap + fcntl */
if (0 != ftruncate(fd, sizeof(struct binding) * _MAXDOMAIN))
log_sys("ftruncate");
/*
* remove the file, but keep it open, so we have an invisible
* lockfile. Note: This does not work with NFS-mounted directories
*/
unlink(name);
return fd;
}
void
read_lock_binding(void)
{
int status;
status = lock_reg(lockfd, F_SETLKW, F_RDLCK, 0, SEEK_SET, 0);
if (0 != status)
log_sys("set read lock");
#if !MMAP_SHARED_OK
lseek(lockfd, 0, SEEK_SET);
readn(lockfd, ypbindlist, sizeof(struct binding) * _MAXDOMAIN);
#endif
return;
}
void
write_lock_binding(void)
{
int status;
status = lock_reg(lockfd, F_SETLKW, F_WRLCK, 0, SEEK_SET, 0);
if (0 != status)
log_sys("set write lock");
return;
}
void
un_lock_read_binding(void)
{
un_lock_write_binding();
}
void
un_lock_write_binding(void)
{
int status;
status = lock_reg(lockfd, F_SETLKW, F_UNLCK, 0, SEEK_SET, 0);
if (0 != status)
log_sys("unlock");
return;
}
#endif
int
get_entry(char *dom, struct binding *entry)
{
struct binding *ypdb = NULL;
ypdb = find_entry(dom);
if (NULL == ypdb)
return -1;
read_lock_binding();
memcpy(entry, ypdb, sizeof (struct binding));
un_lock_read_binding();
return 0;
}
void
update_entry(struct binding *entry)
{
/* update entry in ypbindlist. Lock while updating */
struct binding *ypdb = NULL;
ypdb = find_entry(entry->domain);
if (NULL == ypdb)
return;
write_lock_binding();
memcpy(ypdb, entry, sizeof (struct binding));
#if !MMAP_SHARED_OK
lseek(lockfd, 0, SEEK_SET);
writen(lockfd, ypbindlist, sizeof(struct binding) * _MAXDOMAIN);
#endif
un_lock_write_binding();
if (debug)
log_msg("%s entry for domain %s: server %s, port %d",
entry->is_alive ? "updated" : "cleared", entry->domain,
inet_ntoa(entry->server_addr), ntohs(entry->server_port));
return;
}
struct binding *
find_entry(char *dom)
{
int i;
struct binding *ypdb = NULL;
read_lock_binding();
/* Find entry for domain dom */
for (i = 0; i < _MAXDOMAIN; i++)
{
if (ypbindlist[i].is_bound && 0 == strcmp(ypbindlist[i].domain, dom))
{
ypdb = &ypbindlist[i];
break;
}
}
if (NULL == ypdb) /* no entry for domain dom */
{
/* find empty slot */
for (i = 0; i < _MAXDOMAIN; i++)
{
if (FALSE == ypbindlist[i].is_bound)
{
ypdb = &ypbindlist[i];
break;
}
}
}
un_lock_read_binding();
return ypdb;
}
void
handle_hangup(int sig)
{
log_msg("rereading config file");
hangup = 1;
return;
}
yp-clients-2.2/ypbind/writen.c 100664 273 17 623 6052333633 14337 0 ustar swen man #include "ourhdr.h"
ssize_t /* Write "n" bytes to a descriptor. */
writen(int fd, const void *vptr, size_t n)
{
size_t nleft;
ssize_t nwritten;
const char *ptr;
ptr = vptr; /* can't do pointer arithmetic on void* */
nleft = n;
while (nleft > 0) {
if ( (nwritten = write(fd, ptr, nleft)) <= 0)
return(nwritten); /* error */
nleft -= nwritten;
ptr += nwritten;
}
return(n);
}
yp-clients-2.2/ypbind/ypbind.c 100664 273 17 25672 6052335641 14370 0 ustar swen man /*
* $Log: ypbind.c,v $
* Revision 1.4 1995/11/15 10:06:25 swen
* Added SYSV-IPC (from Michael Rausch <mrausch@ernie.mi.uni-koeln.de>)
* Make mmap (not MAP_ANON) work again with latest kernels.
*
* Revision 1.3 1995/10/13 11:51:58 swen
* Added -v flag for version info.
*
* Revision 1.2 1995/10/13 11:24:14 swen
* Added code to restart slave in case of failure. This should make ypbind
* more robust.
*
* Revision 1.1 1995/07/25 14:27:59 swen
* ypbind version 2.0.
*
* Revision 2.9 1995/01/24 12:05:18 swen
* Added RCS keywords.
*
*/
static char rcsid[] = "$Id: ypbind.c,v 1.4 1995/11/15 10:06:25 swen Exp $" ;
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/uio.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <stdarg.h>
#include <string.h> /* strcmp */
#include <ctype.h>
#include <memory.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h> /* setsid */
#include <fcntl.h>
#include <syslog.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <rpc/pmap_clnt.h> /* for pmap_unset */
#include "ourhdr.h"
#include "ypbind.h"
#include "patchlevel.h"
char **Argv = NULL;
int Argc = 0;
extern int use_broadcast;
SVCXPRT *udptransp, *tcptransp;
domainname mydomain;
int ypsetmode = YPSET_NO;
pid_t childpid;
int broken_server;
volatile int debug;
void *
ypbindproc_null_2_svc(struct svc_req *rqstp)
{
static char * result;
bzero((char *)&result, sizeof(result));
return((void *) &result);
}
struct ypbind_resp *
ypbindproc_domain_2_svc(domainname arg1, struct svc_req *rqstp)
{
static struct ypbind_resp result;
struct binding *ypdb;
bzero((char *) &result, sizeof(result));
result.ypbind_status = YPBIND_FAIL_VAL;
ypdb = find_entry(arg1);
read_lock_binding();
if (NULL == ypdb || 0 == ypdb->is_alive)
{
result.ypbind_status = YPBIND_FAIL_VAL;
result.ypbind_respbody.ypbind_error = YPBIND_ERR_NOSERV;
}
else
{
result.ypbind_status = YPBIND_SUCC_VAL;
memcpy(&result.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr.s_addr,
&ypdb->server_addr, sizeof ypdb->server_addr);
result.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port =
ypdb->server_port;
if (debug)
log_msg("YPBINDPROC_DOMAIN_2: server %s, port %d",
inet_ntoa(ypdb->server_addr), ntohs(ypdb->server_port));
}
un_lock_read_binding();
return &result;
}
void *
ypbindproc_setdom_2_svc(struct ypbind_setdom arg1, struct svc_req *rqstp)
{
static char *result;
struct sockaddr_in *fromsin, bindsin;
bzero((char *)&result, sizeof(result));
fromsin = svc_getcaller(rqstp->rq_xprt);
switch (ypsetmode)
{
case YPSET_LOCAL:
if (fromsin->sin_addr.s_addr != htonl(INADDR_LOOPBACK))
return (void *) &result;
break;
case YPSET_ALL:
break;
case YPSET_NO:
default:
return (void *) &result;
}
if (ntohs(fromsin->sin_port) >= IPPORT_RESERVED)
return (void *) &result;
if (YPVERS != arg1.ypsetdom_vers)
return (void *) &result;
bzero((char *) &bindsin, sizeof bindsin);
bindsin.sin_family = AF_INET;
bindsin.sin_addr.s_addr = arg1.ypsetdom_addr.s_addr;
bindsin.sin_port = arg1.ypsetdom_port;
add_server(arg1.ypsetdom_domain, &bindsin, NULL, NULL, 1);
return((void *) &result);
}
void *
_ypbindproc_null_2(void *argp, struct svc_req *rqstp)
{
return (ypbindproc_null_2_svc(rqstp));
}
struct ypbind_resp *
_ypbindproc_domain_2(domainname argp, struct svc_req *rqstp)
{
return (ypbindproc_domain_2_svc(argp, rqstp));
}
void *
_ypbindproc_setdom_2(struct ypbind_setdom *argp, struct svc_req *rqstp)
{
return (ypbindproc_setdom_2_svc(*argp, rqstp));
}
void
ypbindprog_2(struct svc_req *rqstp, register SVCXPRT *transp)
{
union {
char ypbindproc_domain_2_arg[YPMAXDOMAIN];
struct ypbind_setdom ypbindproc_setdom_2_arg;
} argument;
struct authunix_parms *creds;
char *result;
xdrproc_t xdr_argument, xdr_result;
char *(*local)(char *, struct svc_req *);
switch (rqstp->rq_proc)
{
case YPBINDPROC_NULL:
xdr_argument = (xdrproc_t) xdr_void;
xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) _ypbindproc_null_2;
break;
case YPBINDPROC_DOMAIN:
xdr_argument = (xdrproc_t) xdr_domainname;
xdr_result = (xdrproc_t) xdr_ypbind_resp;
local = (char *(*)(char *, struct svc_req *)) _ypbindproc_domain_2;
break;
case YPBINDPROC_SETDOM:
switch (rqstp->rq_cred.oa_flavor)
{
case AUTH_UNIX:
creds = (struct authunix_parms *) rqstp->rq_clntcred;
if (0 != creds->aup_uid)
{
svcerr_auth(transp, AUTH_BADCRED);
return;
}
break;
default:
svcerr_weakauth(transp);
return;
}
xdr_argument = (xdrproc_t) xdr_ypbind_setdom;
xdr_result = (xdrproc_t) xdr_void;
local = (char *(*)(char *, struct svc_req *)) _ypbindproc_setdom_2;
break;
default:
svcerr_noproc(transp);
return;
}
bzero((char *)&argument, sizeof (argument));
if (!svc_getargs(transp, xdr_argument, (caddr_t) &argument))
{
svcerr_decode(transp);
return;
}
result = (*local)((char *)&argument, rqstp);
if (NULL != result && !svc_sendreply(transp, xdr_result, result))
{
svcerr_systemerr(transp);
}
return;
}
int
main(int argc, char *argv[])
{
int i;
struct sigaction sact;
#if USE_BINDINGDIR
char path[MAXPATHLEN];
#endif
Argv = argv;
Argc = argc;
debug = 0;
broken_server = 0;
for (i = 1; i < argc; i++)
{
if (0 == strcmp("-v", argv[i]))
{
fprintf(stderr, "ypbind version %s\n", YPBIND_VERSION);
exit (1);
}
else if (0 == strcmp("-ypset", argv[i]))
ypsetmode = YPSET_ALL;
else if (0 == strcmp("-ypsetme", argv[i]))
ypsetmode = YPSET_LOCAL;
else if (0 == strcmp("-debug", argv[i]))
debug = 1;
else if (0 == strcmp("-broken_server", argv[i]))
broken_server = 1;
}
log_open("ypbind", (LOG_PID | LOG_CONS), LOG_DAEMON);
yp_get_default_domain(&mydomain);
if ('\0' == mydomain[0])
log_quit("domainname not set. Aborting.\n");
if (0 != getuid())
log_quit("ypbind must be run as root");
if (!debug)
daemon_start();
create_pidfile();
if(0 != atexit(terminate))
log_quit("Could not install exit handler");
init_master_slave_communication();
/* no check for return code here */
pmap_unset(YPBINDPROG, YPBINDVERS);
udptransp = svcudp_create(RPC_ANYSOCK);
if (NULL == udptransp)
log_sys("cannot create udp service.\n");
if (!svc_register(udptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_UDP))
log_sys("unable to register (YPBINDPROG, YPBINDVERS, udp).\n");
tcptransp = svctcp_create(RPC_ANYSOCK, 0, 0);
if (NULL == tcptransp)
log_sys("cannot create tcp service.\n");
if (!svc_register(tcptransp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_TCP))
log_sys("unable to register (YPBINDPROG, YPBINDVERS, tcp).\n");
#if USE_BINDINGDIR
sprintf(path, "%s/%s.%ld", BINDINGDIR, mydomain, YPVERS);
unlink(path);
#endif
childpid = start_slave();
inststr(Argv, Argc, "ypbind (master)");
sigemptyset(&sact.sa_mask);
sigaddset(&sact.sa_mask, SIGCHLD);
sact.sa_handler = sighandler;
sact.sa_flags = 0;
if ( 0 != sigaction(SIGTERM, &sact, NULL))
log_ret("Could not install signal handler for SIGTERM.");
if ( 0 != sigaction(SIGINT, &sact, NULL))
log_ret("Could not install signal handler for SIGINT.");
if ( 0 != sigaction(SIGQUIT, &sact, NULL))
log_ret("Could not install signal handler for SIGQUIT.");
if ( 0 != sigaction(SIGSEGV, &sact, NULL))
log_ret("Could not install signal handler for SIGSEGV.");
if ( 0 != sigaction(SIGCHLD, &sact, NULL))
log_ret("Could not install signal handler for SIGCHLD.");
sact.sa_flags |= SA_RESTART;
if ( 0 != sigaction(SIGHUP, &sact, NULL))
log_ret("Could not install signal handler for SIGHUP.");
sact.sa_handler = toggle_debug;
if (0 != sigaction(SIGUSR1, &sact, NULL))
log_ret("Could not install signal handler for SIGUSR1");
svc_run();
log_quit("svc_run returned");
/* NOTREACHED */
return 1;
}
void
toggle_debug(int sig)
{
debug = 1 - debug;
return;
}
void
sighandler(int sig)
{
sigset_t set;
struct sigaction sact;
if (debug)
log_msg("received signal %d", sig);
if (SIGHUP == sig)
{
kill(childpid, sig);
return;
}
if (SIGCHLD == sig)
{
waitpid(childpid, NULL, WNOHANG);
/* colas@sohia.inria.fr: re-spawn a child if died... */
childpid = start_slave();
}
else
{
pmap_unset(YPBINDPROG, YPBINDVERS);
/* reset signal handler, make sure, signals are not blocked for raise */
sact.sa_handler = SIG_DFL;
sigemptyset(&sact.sa_mask);
sact.sa_flags = 0;
sigemptyset(&set);
sigaddset(&set, sig);
sigprocmask(SIG_UNBLOCK, &set, NULL);
if ( 0 != sigaction(sig, &sact, NULL))
log_quit("Could not uninstall signal handler for signal %d.", sig);
kill(childpid, sig);
#if USE_IPC
terminate_master_slave_communication();
#endif
unlink(_PATH_YPPIDFILE);
raise(sig);
exit(0); /* just in case */
}
}
void
terminate(void)
{
unlink(_PATH_YPPIDFILE);
if (0 != childpid)
kill(childpid, SIGTERM);
#if USE_IPC
terminate_master_slave_communication();
#endif
pmap_unset(YPBINDPROG, YPBINDVERS);
}
/* stolen from bdflush */
void
inststr(char *dst[], int argc, const char *src)
{
if (strlen(src) <= strlen(dst[0]))
{
char *ptr;
for (ptr = dst[0]; *ptr; *(ptr++) = '\0');
strcpy(dst[0], src);
}
else
{
/* stolen from the source to perl 4.036 (assigning to $0) */
char *ptr, *ptr2;
int count;
ptr = dst[0] + strlen(dst[0]);
for (count = 1; count < argc; count++)
{
if (dst[count] == ptr + 1)
ptr += strlen(++ptr);
}
if (environ[0] == ptr + 1)
{
for (count = 0; environ[count]; count++)
if (environ[count] == ptr + 1)
ptr += strlen(++ptr);
}
count = 0;
for (ptr2 = dst[0]; ptr2 <= ptr; ptr2++)
{
*ptr2 = '\0';
count++;
}
strncpy(dst[0], src, count);
}
}
void
create_pidfile(void)
{
int fd;
pid_t pid;
char pbuf[10];
fd = open(_PATH_YPPIDFILE, O_CREAT | O_RDWR, FILE_MODE);
if (fd < 0)
log_sys("cannot create pidfile %s", _PATH_YPPIDFILE);
pid = is_writelock(fd, 0, SEEK_SET, 0);
if (0 != pid)
log_quit("ypbind already running (pid %d) - exiting", pid);
if (0 != write_lock(fd, 0, SEEK_SET, 0))
log_sys("cannot lock pidfile");
sprintf(pbuf, "%6d\n", getpid());
writen(fd, pbuf, strlen(pbuf));
return;
}
yp-clients-2.2/ypbind/ypbind.h 100664 273 17 5277 6052335647 14362 0 ustar swen man /*
* $Log: ypbind.h,v $
* Revision 1.2 1995/11/15 10:06:31 swen
* Added SYSV-IPC (from Michael Rausch <mrausch@ernie.mi.uni-koeln.de>)
* Make mmap (not MAP_ANON) work again with latest kernels.
*
* Revision 1.1 1995/07/25 14:28:02 swen
* ypbind version 2.0.
*
* Revision 2.4 1995/01/24 12:24:32 swen
* Added RCS keywords.
*
*/
#ifndef BINDINGDIR
#define BINDINGDIR "/var/yp/binding"
#endif
#define USE_BINDINGDIR 1
#ifndef _PATH_YPCONF
#define _PATH_YPCONF "/etc/yp.conf"
#endif
#define _PATH_YPPIDFILE _PATH_VARRUN"ypbind.pid"
#define _MAXDOMAIN 8
#define REBIND_INTERVAL 1800 /* rebind every 30 minutes */
#define PING_INTERVAL 60 /* check binding every minute */
#define YPSET_NO 0
#define YPSET_LOCAL 1
#define YPSET_ALL 2
#define USE_IPC 1 /* use SysV IPC for sharing the bindings */
#define MMAP_SHARED_OK 0 /* does shared mapping of files work? */
/* (it does in 1.3.12 */
#define MMAP_SHARED_ANON_OK 0 /* can we share anonymous regions? (not yet in 1.3.40) */
#if USE_IPC
#undef MMAP_SHARED_OK
#define MMAP_SHARED_OK 1 /* SysV IPC is handled the same way ... */
#endif
struct binding
{
struct hostent *host;
struct in_addr server_addr;
long int version;
unsigned short int server_port;
char domain[YPMAXDOMAIN];
int lockfd;
CLIENT *client_handle;
bool_t is_bound;
bool_t is_alive;
bool_t use_broadcast;
time_t next_check;
};
typedef char *domainname;
extern void *ypbindproc_null_2_svc(struct svc_req *);
extern struct ypbind_resp *ypbindproc_domain_2_svc(domainname, struct svc_req *);
extern void *ypbindproc_setdom_2_svc(struct ypbind_setdom, struct svc_req *);
extern struct ypservers *ypconf_read(const char *);
extern bool_t xdr_domainname(XDR *, char *);
bool_t eachresult(bool_t *, struct sockaddr_in *);
void parse_config_file(const char *);
void check_config_entry(char *, const char *);
void broadcast(struct binding *);
void add_server(char *, struct sockaddr_in *, CLIENT *, struct hostent *, bool_t);
void sighandler(int);
void toggle_debug(int);
void handle_hangup(int);
void terminate(void);
int get_entry(char *, struct binding *);
void update_entry(struct binding *);
int open_lockfile(void);
struct binding *find_entry(char *dom);
pid_t start_slave (void);
void bindto_server (char *, struct hostent *);
void ping_server(struct binding *);
void write_lock_binding(void);
void read_lock_binding(void);
void un_lock_read_binding(void);
void un_lock_write_binding(void);
void inststr(char **, int, const char *);
void init_binding(void);
void check_binding(void);
void create_pidfile(void);
void init_master_slave_communication(void);
#if USE_IPC
void terminate_master_slave_communication(void);
#endif
yp-clients-2.2/ypbind/ypbind.man 100664 273 17 5463 6055352231 14672 0 ustar swen man .\" -*- nroff -*-
.TH ypbind 8 "November 1995" "ypbind Version 2.2"
.SH NAME
ypbind - NIS binding process
.SH SYNOPSIS
.B
/usr/sbin/ypbind
[
.B \-debug
] [
.B \-broken_server
] [
.B \-ypset
] [
.B \-ypsetme
]
.SH DESCRIPTION
.B ypbind
finds the server for a NIS domain and stores the information about it
in a
.B binding file.
The binding file resides in the directory
.B /var/yp/binding
and is conventionally named
.BR domainname.version .
The only supported version is version 2.
Unless the option
.B \-debug
is used, ypbind detaches itself from the controlling terminal and puts
itself into background.
.B ypbind
uses
.B syslog()
for logging errors and warnings.
At startup or when receiving signal SIGHUP,
.B ypbind
parses the file
.B /etc/yp.conf
and tries to use the entries for its initial binding. Valid entries
are
.B domain
.I nisdomain
.B server
.I hostname
.RS
Use server
.I hostname
for the domain
.IR nisdomain .
.RE
.B domain
.I nisdomain
.B broadcast
.RS
Use broadcast on the local net for domain
.IR nisdomain .
.RE
.B ypserver
.I hostname
.RS
Use server
.I server
for the local domain. The IP-address of
.I server
must be listed in
.BR /etc/hosts .
.RE
If the file does not exist of if there are no valid entries,
.B ypbind
broadcasts on the local net looking for a NIS server for the local
domain.
.B ypbind
is split into two processes. The master process services RPC requests
asking for binding info. The slave process initializes the binding and
checks it periodically. Upon failure, the binding is invalidated and
the process tries again to find a valid server.
.SH OPTIONS
.IP \-ypset
.BR ypset (8)
may be used to change the binding for a domain.
.IP \-ypsetme
.BR ypset (8)
may only be used from the local host to change the
binding for a domain.
.IP \-debug
starts
.B ypbind
in debug mode.
.B ypbind
will not put itself into background, and error messages and debug
output are written to standard error.
.IP \-broken_server
lets
.B ypbind
accept answers from servers running on an illegal port number. This should
usually be avoided, but is required on Solaris 2.4 (there should be a patch
for Solaris which fixes this broken behaviour.)
.SH FILES
.B /etc/yp.conf
- configuration file.
.BI /var/yp/binding/ domainname.version
- binding file containing information about
.IR domain .
.B /var/run/ypbind.pid
- contains the process id of the currently running
.B ypbind
master process.
.B ypbind
sets a write lock to this file to prevent multiple copies of itself
from running.
.SH BUGS
.B ypbind
will only use the last entry for a domain from
.BR /etc/yp.conf ,
binding to multiple servers for a single domain is
not yet supported.
.SH AUTHOR
.B ypbind
was written by Swen Thuemmler <swen@uni-paderborn.de>. Michael Rausch
<mrausch@ernie.mi.uni-koeln.de> added support for SysV-IPC. Numerous
bugfixes from other contributors.
yp-clients-2.2/ypcat/ 40775 273 17 0 6055353426 12445 5 ustar swen man yp-clients-2.2/ypcat/Makefile 100664 273 17 735 6052336225 14162 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS=ypcat.o
PROG=ypcat
all: $(PROG)
ypcat: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRBINDIR)
yp-clients-2.2/ypcat/ypcat.c 100664 273 17 10323 6005200347 14031 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: ypcat.c,v $
* Revision 2.6 1995/07/25 14:34:15 swen
* Use hosts.byname instead of hosts.byaddr by default.
* Print keys without regarding inkeylen, since this sometimes includes the
* trailing \0 and sometimes not.
*
* Revision 2.5 1995/01/24 12:24:53 swen
* Added RCS keywords.
*
*/
#ifndef LINT
static char rcsid[] = "$Id: ypcat.c,v 2.6 1995/07/25 14:34:15 swen Exp $";
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <ctype.h>
#include <getopt.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
struct ypalias {
const char *alias;
const char *name;
} ypaliases[] = {
{ "passwd", "passwd.byname" },
{ "group", "group.byname" },
{ "networks", "networks.byaddr" },
{ "hosts", "hosts.byname" },
{ "protocols", "protocols.bynumber" },
{ "services", "services.byname" },
{ "aliases", "mail.aliases" },
{ "ethers", "ethers.byname" },
};
int key;
int usage(void);
int printit(int, char *, int, char *, int, char *);
int
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\typcat [-k] [-d domainname] [-t] mapname\n");
fprintf(stderr, "\typcat -x\n");
exit(1);
}
int
printit(int instatus,
char *inkey, int inkeylen,
char *inval, int invallen,
char *indata)
{
if(instatus != YP_TRUE)
return instatus;
if(key)
printf("%.*s ", inkeylen, inkey);
printf("%.*s\n", invallen, inval);
return 0;
}
int
main(int argc, char **argv)
{
char *domainname;
struct ypall_callback ypcb;
const char *inmap;
int notrans;
int c, r, i;
notrans = key = 0;
yp_get_default_domain(&domainname);
while( (c=getopt(argc, argv, "xd:kt")) != -1)
switch(c)
{
case 'x':
for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
printf("Use \"%s\" for \"%s\"\n",
ypaliases[i].alias,
ypaliases[i].name);
exit(0);
case 'd':
domainname = optarg;
break;
case 't':
notrans++;
break;
case 'k':
key++;
break;
default:
usage();
}
if(optind + 1 != argc )
{
usage();
}
inmap = argv[optind];
for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
{
if( strcmp(inmap, ypaliases[i].alias) == 0)
{
inmap = ypaliases[i].name;
}
}
ypcb.foreach = printit;
ypcb.data = NULL;
r = yp_all(domainname, inmap, &ypcb);
switch(r)
{
case 0:
break;
case YPERR_YPBIND:
fprintf(stderr, "ypcat: not running ypbind\n");
exit(1);
default:
fprintf(stderr, "No such map %s. Reason: %s\n",
inmap, yperr_string(r));
exit(1);
}
return 0;
}
yp-clients-2.2/ypmatch/ 40775 273 17 0 6055353427 12773 5 ustar swen man yp-clients-2.2/ypmatch/Makefile 100664 273 17 745 6052336231 14505 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS =ypmatch.o
PROG=ypmatch
all: $(PROG)
ypmatch: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRBINDIR)
yp-clients-2.2/ypmatch/ypmatch.c 100664 273 17 10601 6005200473 14702 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: ypmatch.c,v $
* Revision 2.6 1995/07/25 14:35:39 swen
* Use hosts.byname instead of hosts.byaddr by default.
*
* Revision 2.5 1995/01/24 12:24:57 swen
* Added RCS keywords.
*
*/
#ifndef LINT
static char rcsid[] = "$Id: ypmatch.c,v 2.6 1995/07/25 14:35:39 swen Exp $";
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <ctype.h>
#include <getopt.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
struct ypalias {
const char *alias;
const char *name;
} ypaliases[] = {
{ "passwd", "passwd.byname" },
{ "group", "group.byname" },
{ "networks", "networks.byaddr" },
{ "hosts", "hosts.byname" },
{ "protocols", "protocols.bynumber" },
{ "services", "services.byname" },
{ "aliases", "mail.aliases" },
{ "ethers", "ethers.byname" },
};
void usage(void);
void
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\typmatch [-d domain] [-t] [-k] key [key ...] mname\n");
fprintf(stderr, "\typmatch -x\n");
fprintf(stderr, "where\n");
fprintf(stderr, "\tmname may be either a mapname or a nickname for a map\n");
fprintf(stderr, "\t-t inhibits map nickname translation\n");
fprintf(stderr, "\t-k prints keys as well as values.\n");
fprintf(stderr, "\t-x dumps the map nickname translation table.\n");
exit(1);
}
int
main(int argc, char **argv)
{
char *domainname;
char *inkey, *outbuf;
const char *inmap;
int outbuflen, key, notrans;
int c, r, i;
int found = 0;
notrans = key = 0;
yp_get_default_domain(&domainname);
while( (c=getopt(argc, argv, "xd:kt")) != -1)
switch(c)
{
case 'x':
for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
printf("Use \"%s\" for \"%s\"\n",
ypaliases[i].alias,
ypaliases[i].name);
exit(0);
case 'd':
domainname = optarg;
break;
case 't':
notrans++;
break;
case 'k':
key++;
break;
default:
usage();
}
if( (argc-optind) < 2 )
usage();
inmap = argv[argc-1];
for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
{
if( strcmp(inmap, ypaliases[i].alias) == 0)
inmap = ypaliases[i].name;
}
for(; optind < argc-1; optind++)
{
inkey = argv[optind];
r = yp_match(domainname, inmap,
inkey, strlen(inkey),
&outbuf, &outbuflen);
switch(r)
{
case 0:
if(key)
printf("%s ", inkey);
printf("%*.*s\n", outbuflen, outbuflen, outbuf);
found = 1;
break;
case YPERR_YPBIND:
fprintf(stderr, "yp_match: not running ypbind\n");
exit(1);
default:
fprintf(stderr, "Can't match key %s in map %s. Reason: %s\n",
inkey, inmap, yperr_string(r));
break;
}
}
exit(!found);
}
yp-clients-2.2/yppasswd/ 40775 273 17 0 6055353430 13172 5 ustar swen man yp-clients-2.2/yppasswd/ChangeLog 100664 273 17 370 5575024252 15024 0 ustar swen man Tue Jun 7 09:55:57 1994 Swen Thuemmler (swen@gingganz)
* Fixed serious bug, which killed the yppasswdd on our
server. Used xdr_passwd where it should use xdr_yppasswd. Thanks
to Frank Kemmer <s_kemmer@ira.uka.de> for pointing this out.
yp-clients-2.2/yppasswd/Makefile 100664 273 17 1001 6052336235 14720 0 ustar swen man include ../Makeconfig
include ../Makerules
# LIBS=-lshadow
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS =yppasswd.o xdr_yppasswd.o
PROG=yppasswd
all: $(PROG)
yppasswd: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRBINDIR)
yp-clients-2.2/yppasswd/xdr_yppasswd.c 100664 273 17 4517 6005437272 16173 0 ustar swen man /*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#include "yppasswd.h"
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user or with the express written consent of
* Sun Microsystems, Inc.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* Copyright (c) 1986, 1990 by Sun Microsystems, Inc.
*/
/* from @(#)yppasswd.x 1.3 91/03/11 TIRPC 1.0 */
bool_t
xdr_passwd(XDR *xdrs, struct xpasswd *objp)
{
if (!xdr_string(xdrs, &objp->pw_name, ~0))
{
return (FALSE);
}
if (!xdr_string(xdrs, &objp->pw_passwd, ~0))
{
return (FALSE);
}
if (!xdr_int(xdrs, &objp->pw_uid))
{
return (FALSE);
}
if (!xdr_int(xdrs, &objp->pw_gid))
{
return (FALSE);
}
if (!xdr_string(xdrs, &objp->pw_gecos, ~0))
{
return (FALSE);
}
if (!xdr_string(xdrs, &objp->pw_dir, ~0))
{
return (FALSE);
}
if (!xdr_string(xdrs, &objp->pw_shell, ~0))
{
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_yppasswd(XDR *xdrs, struct yppasswd *objp)
{
if (!xdr_string(xdrs, &objp->oldpass, ~0))
{
return (FALSE);
}
if (!xdr_passwd(xdrs, &objp->newpw))
{
return (FALSE);
}
return (TRUE);
}
yp-clients-2.2/yppasswd/yppasswd.c 100664 273 17 12654 6005437274 15341 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: yppasswd.c,v $
* Revision 2.5 1995/07/26 13:10:20 swen
* Added xdr-routines missing from the NYS-library.
*
* Revision 2.4 1995/01/24 12:25:02 swen
* Added RCS keywords.
*
*/
static char rcsid[] = "$Id: yppasswd.c,v 2.5 1995/07/26 13:10:20 swen Exp $" ;
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include <netdb.h>
#include <pwd.h>
#include <time.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include "yppasswd.h"
uid_t uid;
static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
void to64(char *, long int, int);
char *getnewpasswd(struct passwd *, char **);
void
to64(char *s, long int v, int n)
{
while (--n >= 0)
{
*s++ = itoa64[v&0x3f];
v >>= 6;
}
}
char *
getnewpasswd(register struct passwd *pw, char **oldp)
{
char *buf;
char salt[9], *p=NULL;
int tries = 0;
buf = (char *) malloc(30);
printf("Changing NIS password for %s.\n", pw->pw_name);
if(oldp)
*oldp = NULL;
if(pw->pw_passwd) {
p = getpass("Old password:");
if( strcmp(crypt(p, pw->pw_passwd), pw->pw_passwd))
{
fprintf(stderr, "Sorry.\n");
return NULL;
}
}
if(oldp)
*oldp = strdup(p);
buf[0] = '\0';
while(1) {
p = getpass("New password:");
if(*p == '\0')
{
printf("Password unchanged.\n");
return NULL;
}
if (strlen(p) <= 5 && (uid != 0 || ++tries < 2))
{
printf("Please enter a longer password.\n");
continue;
}
strcpy(buf, p);
p = getpass("Retype new password:");
if( strcmp(buf, p) == 0)
{
break;
}
else
{
printf("Mismatch - password unchanged.\n");
return NULL;
}
}
/* grab a random printable character that isn't a colon */
srandom((int)time((time_t *)NULL));
to64(&salt[0], random(), 2);
return strdup(crypt(buf, salt));
}
int
main(int argc, char **argv)
{
struct yppasswd yppasswd;
struct passwd *pw;
char *domainname, *master;
int r, rpcport, status;
char *s;
uid = getuid();
r = yp_get_default_domain(&domainname);
if(r)
{
fprintf(stderr, "yppasswd: can't get local NIS domain. Reason: %s\n",
yperr_string(r));
exit(1);
}
r = yp_master(domainname, "passwd.byname", &master);
if(r)
{
fprintf(stderr, "yppasswd: can't find the master ypserver. Reason: %s\n",
yperr_string(r));
exit(1);
}
rpcport = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP);
if(rpcport==0)
{
fprintf(stderr, "yppasswd: yppasswdd not running on master\n");
fprintf(stderr, "Can't change password.\n");
exit(1);
}
if(rpcport >= IPPORT_RESERVED)
{
fprintf(stderr, "yppasswd: yppasswd daemon running on illegal port.\n");
exit(1);
}
if (!(pw = getpwuid(uid)))
{
fprintf(stderr, "yppasswd: unknown user (uid=%d).\n", uid);
exit(1);
}
if (uid != pw->pw_uid)
{
fprintf(stderr, "yppasswd: cannot change passwd.\n");
exit(1);
}
printf("Changing password for %s on %s.\n", pw->pw_name, master);
s = getnewpasswd(pw, &yppasswd.oldpass);
if(s == NULL)
exit(1);
yppasswd.newpw.pw_passwd = s;
yppasswd.newpw.pw_name = pw->pw_name;
yppasswd.newpw.pw_uid = pw->pw_uid;
yppasswd.newpw.pw_gid = pw->pw_gid;
yppasswd.newpw.pw_gecos = pw->pw_gecos;
yppasswd.newpw.pw_dir = pw->pw_dir;
yppasswd.newpw.pw_shell = pw->pw_shell;
r = callrpc(master, YPPASSWDPROG, YPPASSWDVERS, YPPASSWDPROC_UPDATE,
(xdrproc_t)xdr_yppasswd, (void *)&yppasswd,
(xdrproc_t)xdr_int, (void *)&status);
if (r)
{
clnt_perrno(r);
printf("\nCouldn't change NIS password.\n");
}
else
{
printf("The NIS password has been changed on %s.\n", master);
}
exit(0);
}
yp-clients-2.2/yppasswd/yppasswd.h 100664 273 17 5634 6005437276 15330 0 ustar swen man /*
* Please do not edit this file.
* It was generated using rpcgen.
*/
#ifndef _YPPASSWD_H_RPCGEN
#define _YPPASSWD_H_RPCGEN
#include <rpc/rpc.h>
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user or with the express written consent of
* Sun Microsystems, Inc.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* Copyright (c) 1986, 1990 by Sun Microsystems, Inc.
*/
/* from @(#)yppasswd.x 1.3 91/03/11 TIRPC 1.0 */
#ifndef _rpcsvc_yppasswd_h
#define _rpcsvc_yppasswd_h
struct xpasswd {
char *pw_name;
char *pw_passwd;
int pw_uid;
int pw_gid;
char *pw_gecos;
char *pw_dir;
char *pw_shell;
};
#ifdef __cplusplus
extern "C" bool_t xdr_passwd(XDR *, xpasswd*);
#elif __STDC__
extern bool_t xdr_passwd(XDR *, struct xpasswd*);
#else /* Old Style C */
bool_t xdr_passwd();
#endif /* Old Style C */
struct yppasswd {
char *oldpass;
struct xpasswd newpw;
};
#ifdef __cplusplus
extern "C" bool_t xdr_yppasswd(XDR *, yppasswd*);
#elif __STDC__
extern bool_t xdr_yppasswd(XDR *, struct yppasswd*);
#else /* Old Style C */
bool_t xdr_yppasswd();
#endif /* Old Style C */
#endif /* !_rpcsvc_yppasswd_h */
#define YPPASSWDPROG ((u_long)100009)
#define YPPASSWDVERS ((u_long)1)
#ifdef __cplusplus
#define YPPASSWDPROC_UPDATE ((u_long)1)
extern "C" int * yppasswdproc_update_1(yppasswd , CLIENT *);
extern "C" int * yppasswdproc_update_1_svc(yppasswd , struct svc_req *);
#elif __STDC__
#define YPPASSWDPROC_UPDATE ((u_long)1)
extern int * yppasswdproc_update_1(struct yppasswd , CLIENT *);
extern int * yppasswdproc_update_1_svc(struct yppasswd , struct svc_req *);
#else /* Old Style C */
#define YPPASSWDPROC_UPDATE ((u_long)1)
extern int * yppasswdproc_update_1();
extern int * yppasswdproc_update_1_svc();
#endif /* Old Style C */
#endif /* !_YPPASSWD_H_RPCGEN */
yp-clients-2.2/yppoll/ 40775 273 17 0 6055353431 12640 5 ustar swen man yp-clients-2.2/yppoll/Makefile 100664 273 17 743 6052336242 14357 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS =yppoll.o
PROG=yppoll
all: $(PROG)
yppoll: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRSBINDIR)
yp-clients-2.2/yppoll/yppoll.c 100664 273 17 6024 5711170646 14425 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* Copyright (c) 1992/3 John Brezak
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: yppoll.c,v $
* Revision 1.4 1995/01/24 12:25:10 swen
* Added RCS keywords.
*
*/
#ifndef lint
static char rcsid[] = "$Id: yppoll.c,v 1.4 1995/01/24 12:25:10 swen Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <time.h>
#include <getopt.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
void
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\typpoll [-h host] [-d domainname] mapname\n");
exit(1);
}
int
main(int argc, char **argv)
{
char *domainname;
const char *hostname = "localhost";
char *inmap, *master;
int order;
int c, r;
yp_get_default_domain(&domainname);
while( (c=getopt(argc, argv, "h:d:?")) != -1)
switch(c)
{
case 'd':
domainname = optarg;
break;
case 'h':
hostname = optarg;
break;
case '?':
usage();
/*NOTREACHED*/
}
if(optind + 1 != argc )
usage();
inmap = argv[optind];
r = yp_order(domainname, inmap, &order);
if (r != 0)
{
fprintf(stderr, "No such map %s. Reason: %s\n", inmap, yperr_string(r));
exit(1);
}
printf("Map %s has order number %d. %s",
inmap, order, ctime((time_t *)&order));
r = yp_master(domainname, inmap, &master);
if (r != 0)
{
fprintf(stderr, "No such map %s. Reason: %s\n", inmap, yperr_string(r));
exit(1);
}
printf("The master server is %s.\n", master);
exit(0);
}
yp-clients-2.2/ypset/ 40775 273 17 0 6055353432 12466 5 ustar swen man yp-clients-2.2/ypset/Makefile 100664 273 17 740 6052336246 14205 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS =ypset.o
PROG=ypset
all: $(PROG)
ypset: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRSBINDIR)
yp-clients-2.2/ypset/ypset.c 100664 273 17 11164 5711170652 14115 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: ypset.c,v $
* Revision 2.4 1995/01/24 12:25:14 swen
* Added RCS keywords.
*
*/
#ifndef LINT
static char rcsid[] = "ypset.c,v 1.3 1993/06/12 00:02:37 deraadt Exp";
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <getopt.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <arpa/inet.h>
#include "xdr_yp.h"
void usage(void);
int bind_tohost(struct sockaddr_in *, char *, char *);
void
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\typset [-h host ] [-d domain] server\n");
exit(1);
}
int
bind_tohost(struct sockaddr_in *saddr, char *dom, char *server)
{
struct ypbind_setdom ypsd;
struct timeval tv;
struct hostent *hp;
CLIENT *client;
int sock, port;
int r;
unsigned long server_addr;
port=htons(getrpcport(server, YPPROG, YPPROC_NULL, IPPROTO_UDP));
if(0 == port)
{
fprintf(stderr, "%s not running ypserv.\n", server);
exit(1);
}
bzero(&ypsd, sizeof ypsd);
hp = gethostbyname (server);
if(NULL != hp)
{
/* is this the most compatible way?? */
bcopy (hp->h_addr_list[0], &ypsd.ypsetdom_addr,
sizeof (ypsd.ypsetdom_addr));
}
else if((long)(server_addr = inet_addr (server)) == -1)
{
fprintf(stderr, "can't find address for %s\n", server);
exit(1);
}
else
bcopy (&server_addr, &ypsd.ypsetdom_addr, sizeof (server_addr));
strncpy(ypsd.ypsetdom_domain, dom, sizeof ypsd.ypsetdom_domain);
ypsd.ypsetdom_port = port;
ypsd.ypsetdom_vers = YPVERS;
tv.tv_sec = 15;
tv.tv_usec = 0;
sock = RPC_ANYSOCK;
client = clntudp_create(saddr, YPBINDPROG, YPBINDVERS, tv, &sock);
if (client==NULL)
{
fprintf(stderr, "can't yp_bind: Reason: %s\n", yperr_string(YPERR_YPBIND));
return YPERR_YPBIND;
}
client->cl_auth = authunix_create_default();
r = clnt_call(client, YPBINDPROC_SETDOM,
xdr_ypbind_setdom, &ypsd,
xdr_void, NULL,
tv);
if(r)
{
fprintf(stderr, "Sorry, cannot ypset for domain %s on host.\n", dom);
clnt_destroy(client);
return YPERR_YPBIND;
}
clnt_destroy(client);
return 0;
}
int
main(int argc, char **argv)
{
struct sockaddr_in saddr;
struct hostent *hent;
char *domainname;
int c;
yp_get_default_domain(&domainname);
bzero(&saddr, sizeof saddr);
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(0x7f000001);
while( (c=getopt(argc, argv, "h:d:")) != -1)
switch(c)
{
case 'd':
domainname = optarg;
break;
case 'h':
if( (saddr.sin_addr.s_addr=inet_addr(optarg)) == -1)
{
hent = gethostbyname(optarg);
if(hent==NULL)
{
fprintf(stderr, "ypset: host %s unknown\n", optarg);
exit(1);
}
bcopy(&hent->h_addr_list[0], &saddr.sin_addr, sizeof saddr.sin_addr);
}
break;
default:
usage();
}
if(optind + 1 != argc )
usage();
if (bind_tohost(&saddr, domainname, argv[optind]))
exit(1);
exit(0);
}
yp-clients-2.2/ypwhich/ 40775 273 17 0 6055353433 12776 5 ustar swen man yp-clients-2.2/ypwhich/Makefile 100664 273 17 756 6052336252 14520 0 ustar swen man include ../Makeconfig
include ../Makerules
LIBS=
ifndef OPTFLAGS
OPTFLAGS= -O2
endif
CFLAGS = $(WFLAGS) $(OPTFLAGS) $(INC) $(XCFLAGS)
INC= -I. -I..
OBJS =ypwhich.o xdrfix.o
PROG=ypwhich
all: $(PROG)
ypwhich: $(OBJS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
clean:
$(RM) -f core *.o *.a *~ tmp_make foo $(PROG)
-for i in *.c;do \
if [ -f $$i ]; then \
$(RM) -f `basename $$i .c`.s; \
fi; \
done
install: $(PROG)
install -c -o root -g root -m 0755 -s $(PROG) $(USRBINDIR)
yp-clients-2.2/ypwhich/xdrfix.c 100664 273 17 1532 6005434722 14540 0 ustar swen man #include <rpcsvc/yp_prot.h>
#include <string.h>
bool_t
xdr_ypmaplist_str (XDR *xdrs, char *objp)
{
if (!xdr_mapname(xdrs, &objp))
{
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_ypmaplist(XDR *xdrs, struct ypmaplist *objp)
{
if (!xdr_ypmaplist_str(xdrs, objp->ypml_name))
{
return (FALSE);
}
if (!xdr_pointer(xdrs,
(char **)&objp->ypml_next,
sizeof(struct ypmaplist),
(xdrproc_t)xdr_ypmaplist))
{
return (FALSE);
}
return (TRUE);
}
bool_t
xdr_ypresp_maplist(XDR *xdrs, struct ypresp_maplist *objp)
{
if (!xdr_u_long(xdrs, &objp->status))
{
return (FALSE);
}
if (!xdr_pointer(xdrs, (char **)&objp->list,
sizeof(struct ypmaplist), (xdrproc_t)xdr_ypmaplist))
{
return (FALSE);
}
return (TRUE);
}
yp-clients-2.2/ypwhich/ypwhich.c 100664 273 17 20140 6005434723 14724 0 ustar swen man /*
* Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* $Log: ypwhich.c,v $
* Revision 2.6 1995/07/26 12:49:23 swen
* Rewritten to not rely on yp_maplist() to make it work with the NYS library.
* Added fix for broken xdr-routines in the NYS library.
*
* Revision 2.5 1995/01/24 12:25:19 swen
* Added RCS keywords.
*
*/
#ifndef LINT
static char rcsid[] = "$Id: ypwhich.c,v 2.6 1995/07/26 12:49:23 swen Exp $";
#endif
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <getopt.h>
#include <ctype.h>
#include <netdb.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#include <arpa/inet.h>
#include "xdr_yp.h"
extern int yp_maplist(char *, struct ypmaplist **);
struct ypalias {
const char *alias;
const char *name;
} ypaliases[] = {
{ "passwd", "passwd.byname" },
{ "group", "group.byname" },
{ "networks", "networks.byaddr" },
{ "hosts", "hosts.byaddr" },
{ "protocols", "protocols.bynumber" },
{ "services", "services.byname" },
{ "aliases", "mail.aliases" },
{ "ethers", "ethers.byname" },
};
struct sockaddr_in *ss_addr = NULL;
void usage(void);
int bind_host(char *, struct sockaddr_in *, int);
void
usage(void)
{
fprintf(stderr, "Usage:\n");
fprintf(stderr, "\typwhich [-d domain] [[-t] -m [mname] | host]\n");
fprintf(stderr, "\typwhich -x\n");
exit(1);
}
/*
* Like yp_bind except can query a specific host
*/
int
bind_host(char *dom, struct sockaddr_in *saddr, int doprint)
{
struct hostent *hent = NULL;
struct ypbind_resp ypbr;
struct timeval tv;
CLIENT *client;
int sock, r;
sock = RPC_ANYSOCK;
tv.tv_sec = 15;
tv.tv_usec = 0;
client = clntudp_create(saddr, YPBINDPROG, YPBINDVERS, tv, &sock);
if(NULL == client)
{
fprintf(stderr, "can't clntudp_create: %s\n", yperr_string(YPERR_YPBIND));
return YPERR_YPBIND;
}
tv.tv_sec = 5;
tv.tv_usec = 0;
r = clnt_call(client, YPBINDPROC_DOMAIN,
(xdrproc_t)xdr_domainname, dom,
(xdrproc_t)xdr_ypbind_resp, &ypbr,
tv);
if( r != RPC_SUCCESS)
{
fprintf(stderr, "can't clnt_call: %s\n", yperr_string(YPERR_YPBIND));
clnt_destroy(client);
return YPERR_YPBIND;
}
else
{
if (ypbr.ypbind_status != YPBIND_SUCC_VAL)
{
fprintf(stderr, "can't yp_bind: Reason: %s\n",
yperr_string(ypbr.ypbind_status));
clnt_destroy(client);
return r;
}
}
clnt_destroy(client);
if (!ss_addr)
ss_addr = (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in));
ss_addr->sin_family = AF_INET;
ss_addr->sin_port = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_port;
ss_addr->sin_addr = ypbr.ypbind_respbody.ypbind_bindinfo.ypbind_binding_addr;
/*printf("%08x\n", ss_addr);*/
if (doprint)
{
hent = gethostbyaddr((char *)&ss_addr->sin_addr.s_addr,
sizeof(ss_addr->sin_addr.s_addr), AF_INET);
if (hent)
printf("%s\n", hent->h_name);
else
printf("%s\n", inet_ntoa(ss_addr->sin_addr));
}
return 0;
}
int
main(int argc, char **argv)
{
char *domainname, *master;
const char *map;
struct ypresp_maplist ypml;
struct ypmaplist *y;
struct hostent *hent;
struct sockaddr_in saddr;
struct timeval tv;
CLIENT *client;
int notrans, mode, getmap, sock;
int c, r, i;
yp_get_default_domain(&domainname);
map = NULL;
getmap = notrans = mode = 0;
while( (c=getopt(argc, argv, "xd:mt")) != -1)
switch(c)
{
case 'x':
for(i=0; i<sizeof ypaliases/sizeof ypaliases[0]; i++)
printf("Use \"%s\" for \"%s\"\n",
ypaliases[i].alias, ypaliases[i].name);
exit(0);
case 'd':
domainname = optarg;
break;
case 't':
notrans++;
break;
case 'm':
mode++;
break;
default:
usage();
}
if(0 == mode)
{
switch(argc-optind)
{
case 0:
bzero(&saddr, sizeof saddr);
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if(bind_host(domainname, &saddr, 1))
exit(1);
break;
case 1:
bzero(&saddr, sizeof saddr);
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr=inet_addr(argv[optind]);
if(-1 == saddr.sin_addr.s_addr)
{
hent = gethostbyname(argv[optind]);
if(NULL == hent)
{
fprintf(stderr, "ypwhich: host %s unknown\n",
argv[optind]);
exit(1);
}
bcopy((char *)hent->h_addr_list[0],
(char *)&saddr.sin_addr, sizeof saddr.sin_addr);
}
if(bind_host(domainname, &saddr, 1))
exit(1);
break;
default:
usage();
}
exit(0);
}
if( argc-optind > 1)
usage();
if(argv[optind])
{
map = argv[optind];
for(i=0; (!notrans) && i<sizeof ypaliases/sizeof ypaliases[0]; i++)
if( strcmp(map, ypaliases[i].alias) == 0)
map = ypaliases[i].name;
r = yp_master(domainname, map, &master);
switch(r)
{
case 0:
printf("%s\n", master);
free(master);
break;
case YPERR_YPBIND:
fprintf(stderr, "ypwhich: not running ypbind\n");
exit(1);
default:
fprintf(stderr, "Can't find master for map %s. Reason: %s\n",
map, yperr_string(r));
exit(1);
}
exit(0);
}
bzero(&saddr, sizeof saddr);
saddr.sin_family = AF_INET;
saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
if (!ss_addr)
bind_host(domainname, &saddr, 0);
sock = RPC_ANYSOCK;
tv.tv_sec = 15;
tv.tv_usec = 0;
client = clntudp_create (ss_addr, YPPROG, YPVERS, tv, &sock);
if(NULL == client)
{
fprintf(stderr, "can't clntudp_create: %s\n", yperr_string(YPERR_YPBIND));
exit (1);
}
bzero((char *)&ypml, sizeof ypml);
tv.tv_sec = 5;
tv.tv_usec = 0;
r = clnt_call(client, YPPROC_MAPLIST,
(xdrproc_t)xdr_domainname, domainname,
(xdrproc_t)xdr_ypresp_maplist, &ypml,
tv);
if (RPC_SUCCESS != r)
{
fprintf(stderr, "ypwhich: Can't get maplist for domain %s\n", domainname);
exit (1);
}
for(y = ypml.list; NULL != y; )
{
struct ypmaplist *tmp;
tmp = y;
r = yp_master(domainname, y->ypml_name, &master);
switch(r)
{
case 0:
printf("%s %s\n", y->ypml_name, master);
free(master);
break;
default:
fprintf(stderr,
"YP: can't find the master of %s: Reason: %s\n",
y->ypml_name, yperr_string(r));
break;
}
y = y->ypml_next;
free(tmp);
}
exit(0);
}
yp-clients-2.2/README 100644 273 17 10343 6055353456 12324 0 ustar swen man This implementation of NIS for linux is based on the YP stuff for
NetBSD from Theo Deraadt and an independend port of H.J. Lu.
This implementation only provides NIS _clients_. You must already have
a NIS server running somewhere. You can find one for linux on
ftp://ftp.lysator.liu.se/pub/NYS. Please read the NIS-HOWTO, too.
How to set up your system as a NIS client:
1. Set your NIS domain with domainname at boottime.
Example:
if [ -r /etc/defaultdomain ] ; then
domainname `cat /etc/defaultdomain`
fi
You should create the file /etc/defaultdomain with the command
echo -n your_domain_name > /etc/defaultdomain
Old versions of the domainname program could not deal with a \n at the
end of /etc/defaultdomain and made it part of the domainname. This is
fixed in this version.
Please do _not_ confuse the NIS domainname (set with the domainname
command, which uses setdomainname()) with the DNS domain name (set in
/etc/resolv.conf). Some distributions falsely assume these are the
same. This is wrong. Make shure the NIS domainname is the name of a
domain served by your NIS server.
2. Find a NIS server.
Here you have 2 possibilities. If your NIS server is in your local
net, you can simply start ypbind. It will use broadcast to find a
server. You can check for a NIS server with the command
rpcinfo -b 100004 2
With this release, you can enter the name of your NIS server
to the file /etc/yp.conf. If /etc/yp.conf exists when ypbind is
started, ypbind will search it for lines formed like
ypserver <Name_of_ypserver>
ypbind then tests if the given servers are up and serve the NIS
domain. If one of the servers responds, it will use it for all further
NIS requests, else it will fallback to broadcast. This gives you the
possibility to use a server behind a gateway.
3. Start ypbind
The recommended way of starting ypbind is as follows:
if [ -d /var/yp ] ; then
/usr/sbin/ypbind ; echo ypbind
fi
Be sure to set the domainname before calling ypbind and to append
+:*:0:0:::
to /etc/passwd, and
+:*:0:
to /etc/group (this is for libc-4.5.26. Since this library is buggy
w.r.t. NIS, please use libc-4.6.27).
ATTENTION! Do not use this entry for libc 4.6.30 and above, it will prevent
everyone from login, since the pw_passwd entry will get overwritten with the
star. Use a line with a single + instead.
--- BEGIN NOTES for libc-4.6.27 ---
If you are using libc-4.6.27 or above, you
can just add a + to /etc/passwd or /etc/group to make all your NIS
accounts available on your machine. It is possible to include oder
exclude single users, too: just add +username or -username to
/etc/passwd. You can even overwrite the passwd, username, directory
and shell fields of the NIS entry, for example the entry:
+swen::::NIS Hacker::/bin/tcsh
would change the full name of swen to "NIS Hacker" and the shell to
/bin/tcsh, but would leave the homedirectory to the value in the NIS
entry.
NOTE: For libc-4.6.30 and above this will work for the general entry
+::::::
too, so don't use
+:*:::::
since it will overwrite the pw_passwd field on all NIS entries and
prevent login.
libc-4.6.27 supports netgroup entries in /etc/passwd and /etc/group.
So if you have a netgroup power_users, you can allow the members of
this netgroup access to your machine with the line
+@power_users
in /etc/passwd.
Note, that the rcmd() routine supports netgroup entries in
~/.rhosts. So if you have a netgroup named hosts, you can have remote
access to your linux machine with the line
+@hosts
in ~/.rhosts (this is more secure than a single +, since this would
allow access with your loginname from any machine in the world, and
it is simpler than putting in every single hostname you want to
rlogin from).
--- END NOTES for libc-4.6.27 ---
Don't forget to create the directory /var/yp. Make sure the portmapper
is running and the NIS domainname is set before ypbind gets started.
You can use NIS for your host map by adding "nis" to the order line of
/etc/host.conf.
Example:
order hosts nis bind
multi on
This will look into /etc/hosts first, then ask nis and then the domain
name server.
Feel free to correct any errors in the programs or documentation
(including spelling and grammar!)
Comments, corrections, enhancements, patches, praise, postcards, money
etc. to swen@uni-paderborn.de, flames to /dev/null.