mirror of
https://github.com/opnsense/src.git
synced 2026-04-21 06:07:31 -04:00
Rework error reporting/logging: although the SunOS documentation says
that ypxfr is supposed to log messages to /var/yp/ypxfr.log if it exists, using syslog() makes more sense, especially since ypserv does the same thing already. Try to use stderr by default, and use syslog() if stderr is not a tty. Also update the man page to reflect this change.
This commit is contained in:
parent
c0106644ad
commit
4b2f613d23
7 changed files with 140 additions and 44 deletions
|
|
@ -1,8 +1,8 @@
|
|||
# $Id: Makefile,v 1.1 1995/01/31 09:28:38 wpaul Exp $
|
||||
# $Id: Makefile,v 1.2 1995/02/06 22:15:20 wpaul Exp $
|
||||
|
||||
PROG= ypxfr
|
||||
MAN8= ypxfr.8
|
||||
|
||||
SRCS= ypxfr.c ypclnt.c yp_clnt.c yp_xdr.c
|
||||
SRCS= ypxfr.c ypclnt.c yp_clnt.c yp_xdr.c log.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
|
|
|||
84
gnu/libexec/ypxfr/log.c
Normal file
84
gnu/libexec/ypxfr/log.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 1995
|
||||
* Bill Paul <wpaul@ctr.columbia.edu>. 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Bill Paul.
|
||||
* 4. Neither the name of the author nor the names of any co-contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* error logging/reporting facilities
|
||||
* stolen from /usr/libexec/mail.local via ypserv
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <syslog.h>
|
||||
|
||||
extern int logflag;
|
||||
extern char *progname;
|
||||
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
#include <varargs.h>
|
||||
#endif
|
||||
|
||||
void verr(fmt, ap)
|
||||
const char *fmt;
|
||||
_BSD_VA_LIST_ ap;
|
||||
|
||||
{
|
||||
if (logflag)
|
||||
vsyslog(LOG_NOTICE, fmt, ap);
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"%s: ",progname);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
#ifdef __STDC__
|
||||
Perror(const char *fmt, ...)
|
||||
#else
|
||||
Perror(fmt, va_list)
|
||||
const char *fmt;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list ap;
|
||||
#ifdef __STDC__
|
||||
va_start(ap, fmt);
|
||||
#else
|
||||
va_start(ap);
|
||||
#endif
|
||||
verr(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include "yp.h"
|
||||
#ifndef lint
|
||||
|
|
@ -9,6 +10,7 @@ static char rcsid[] = "yp.x,v 1.1 1994/08/04 19:01:55 wollman Exp";
|
|||
static void ypprog_2();
|
||||
static void yppush_xfrrespprog_1();
|
||||
static void ypbindprog_2();
|
||||
extern void Perror __P((const char *, ...));
|
||||
|
||||
main()
|
||||
{
|
||||
|
|
@ -20,41 +22,41 @@ main()
|
|||
|
||||
transp = svcudp_create(RPC_ANYSOCK);
|
||||
if (transp == NULL) {
|
||||
(void)fprintf(stderr, "cannot create udp service.\n");
|
||||
Perror("cannot create udp service.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_UDP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPPROG, YPVERS, udp).\n");
|
||||
Perror("unable to register (YPPROG, YPVERS, udp).\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_UDP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, udp).\n");
|
||||
Perror("unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, udp).\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_UDP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, udp).\n");
|
||||
Perror("unable to register (YPBINDPROG, YPBINDVERS, udp).\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
transp = svctcp_create(RPC_ANYSOCK, 0, 0);
|
||||
if (transp == NULL) {
|
||||
(void)fprintf(stderr, "cannot create tcp service.\n");
|
||||
Perror("cannot create tcp service.\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPPROG, YPVERS, ypprog_2, IPPROTO_TCP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPPROG, YPVERS, tcp).\n");
|
||||
Perror("unable to register (YPPROG, YPVERS, tcp).\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, yppush_xfrrespprog_1, IPPROTO_TCP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, tcp).\n");
|
||||
Perror("unable to register (YPPUSH_XFRRESPPROG, YPPUSH_XFRRESPVERS, tcp).\n");
|
||||
exit(1);
|
||||
}
|
||||
if (!svc_register(transp, YPBINDPROG, YPBINDVERS, ypbindprog_2, IPPROTO_TCP)) {
|
||||
(void)fprintf(stderr, "unable to register (YPBINDPROG, YPBINDVERS, tcp).\n");
|
||||
Perror("unable to register (YPBINDPROG, YPBINDVERS, tcp).\n");
|
||||
exit(1);
|
||||
}
|
||||
svc_run();
|
||||
(void)fprintf(stderr, "svc_run returned\n");
|
||||
Perror("svc_run returned\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +168,7 @@ ypprog_2(rqstp, transp)
|
|||
svcerr_systemerr(transp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, &argument)) {
|
||||
(void)fprintf(stderr, "unable to free arguments\n");
|
||||
Perror("unable to free arguments\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +213,7 @@ yppush_xfrrespprog_1(rqstp, transp)
|
|||
svcerr_systemerr(transp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, &argument)) {
|
||||
(void)fprintf(stderr, "unable to free arguments\n");
|
||||
Perror("unable to free arguments\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
@ -263,7 +265,7 @@ ypbindprog_2(rqstp, transp)
|
|||
svcerr_systemerr(transp);
|
||||
}
|
||||
if (!svc_freeargs(transp, xdr_argument, &argument)) {
|
||||
(void)fprintf(stderr, "unable to free arguments\n");
|
||||
Perror("unable to free arguments\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
static char rcsid[] = "yp.x,v 1.1 1994/08/04 19:01:55 wollman Exp";
|
||||
#endif /* not lint */
|
||||
|
||||
extern void Perror __P((const char *, ...));
|
||||
|
||||
struct {
|
||||
union {
|
||||
int (*encoder)(char *, int, char **, int *, char **, int *);
|
||||
|
|
@ -197,7 +199,7 @@ __xdr_ypresp_all(XDR *xdrs, ypresp_all *objp)
|
|||
return (FALSE);
|
||||
}
|
||||
if (!__xdr_ypresp_key_val(xdrs, &objp->ypresp_all_u.val)) {
|
||||
printf("__xdr_ypresp_key_val failed\n");
|
||||
Perror("__xdr_ypresp_key_val failed\n");
|
||||
return (FALSE);
|
||||
}
|
||||
if (objp->ypresp_all_u.val.stat!=YP_TRUE) {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu)
|
||||
|
||||
$Id: ypclnt.c,v 1.1 1995/01/31 09:28:45 wpaul Exp $
|
||||
$Id: ypclnt.c,v 1.2 1995/02/06 23:35:48 wpaul Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -43,7 +43,8 @@ struct dom_binding {
|
|||
|
||||
static struct sockaddr_in ServerAddress;
|
||||
static CLIENT *UdpClient=NULL, *TcpClient=NULL;
|
||||
|
||||
extern void Perror __P((const char *, ...));
|
||||
|
||||
#ifdef YPBROADCAST
|
||||
static bool_t
|
||||
eachresult( caddr_t resultsp, struct sockaddr_in *raddr)
|
||||
|
|
@ -84,16 +85,16 @@ __do_ypbind(domainname d)
|
|||
case YPBIND_FAIL_VAL:
|
||||
switch(r.ypbind_resp_u.ypbind_error) {
|
||||
case YPBIND_ERR_ERR:
|
||||
fprintf(stderr, "YPBINDPROC_DOMAIN: Internal error\n");
|
||||
Perror("YPBINDPROC_DOMAIN: Internal error\n");
|
||||
break;
|
||||
case YPBIND_ERR_NOSERV:
|
||||
fprintf(stderr, "YPBINDPROC_DOMAIN: No bound server for passed domain\n");
|
||||
Perror("YPBINDPROC_DOMAIN: No bound server for passed domain\n");
|
||||
break;
|
||||
case YPBIND_ERR_RESC:
|
||||
fprintf(stderr, "YPBINDPROC_DOMAIN: System resource allocation failure\n");
|
||||
Perror("YPBINDPROC_DOMAIN: System resource allocation failure\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "YPBINDPROC_DOMAIN: Unknown error\n");
|
||||
Perror("YPBINDPROC_DOMAIN: Unknown error\n");
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $Id: ypxfr.8,v 1.1 1995/02/06 22:15:21 wpaul Exp $
|
||||
.\" $Id: ypxfr.8,v 1.2 1995/03/30 04:14:45 wpaul Exp $
|
||||
.\"
|
||||
.Dd February 5, 1995
|
||||
.Dt YPXFR 8
|
||||
|
|
@ -119,10 +119,11 @@ When
|
|||
.Nm ypxfr
|
||||
is invoked without a controlling terminal, e.g. from inside
|
||||
.Xr ypserv 8 ,
|
||||
it logs all its output to
|
||||
.Pa /var/yp/ypxfr.log .
|
||||
it logs all its output using the
|
||||
.Xr syslog 3
|
||||
facility.
|
||||
.Sh OPTIONS
|
||||
The following options are supported by
|
||||
The following options and flags are supported by
|
||||
.Nm ypxfr :
|
||||
.Bl -tag -width flag
|
||||
.It Fl f
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
Modified for use with FreeBSD 2.x by Bill Paul (wpaul@ctr.columbia.edu)
|
||||
|
||||
$Id: ypxfr.c,v 1.3 1995/03/30 04:14:46 wpaul Exp $
|
||||
$Id: ypxfr.c,v 1.2 1995/02/06 23:35:49 wpaul Exp $
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
|
@ -70,6 +70,11 @@ struct dom_binding {
|
|||
*/
|
||||
extern int _yp_bind(struct sockaddr_in *, char *);
|
||||
extern int _yp_clear( char *);
|
||||
extern void Perror __P((const char *, ...));
|
||||
int logflag = 0;
|
||||
char *progname;
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
|
@ -115,7 +120,7 @@ ypxfr_foreach(int status, char *key, int keylen, char *val, int vallen,
|
|||
return 0;
|
||||
if (status!=YP_TRUE) {
|
||||
int s=ypprot_err(status);
|
||||
fprintf(stderr, "%s\n", yperr_string(s));
|
||||
Perror("%s\n",yperr_string(s));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -194,8 +199,8 @@ ypxfr(char *mapName) {
|
|||
sprintf(dbName, "%s%s/%s", _PATH_YP, TargetDomain, mapName);
|
||||
if ((db = dbopen(dbName,O_RDWR|O_EXCL, PERM_SECURE,
|
||||
DB_HASH, &openinfo)) == NULL) {
|
||||
perror("dbopen");
|
||||
fprintf(stderr, "%s: cannot open - ignored.\n", dbName);
|
||||
Perror("dbopen: %s\n", strerror(errno));
|
||||
Perror("%s: cannot open - ignored.\n", dbName);
|
||||
localOrderNum=0;
|
||||
} else {
|
||||
inKey.data="YP_LAST_MODIFIED"; inKey.size=strlen(inKey.data);
|
||||
|
|
@ -219,7 +224,7 @@ ypxfr(char *mapName) {
|
|||
sprintf(dbName, "%s%s/%s~", _PATH_YP, TargetDomain, mapName);
|
||||
if ((db = dbopen(dbName,O_RDWR|O_EXCL|O_CREAT, PERM_SECURE, DB_HASH,
|
||||
&openinfo)) == NULL) {
|
||||
fprintf(stderr, "%s: Cannot open\n", dbName);
|
||||
Perror("%s: Cannot open\n", dbName);
|
||||
return YPXFR_DBM;
|
||||
}
|
||||
|
||||
|
|
@ -238,6 +243,13 @@ ypxfr(char *mapName) {
|
|||
|
||||
callback.foreach = ypxfr_foreach;
|
||||
callback.data = NULL;
|
||||
|
||||
/*
|
||||
* We have to use our own private version of yp_all() here since
|
||||
* the yp_all() in libc doesn't allow us to specify the server that
|
||||
* we want to talk to: it's imperative that we transfer data from
|
||||
* the NIS master server and no one else.
|
||||
*/
|
||||
y=__yp_all(SourceDomain, mapName, &callback);
|
||||
|
||||
(void)(db->close)(db);
|
||||
|
|
@ -259,7 +271,7 @@ ypxfr(char *mapName) {
|
|||
void usage(progname)
|
||||
char *progname;
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-f] [-c] [-d target domain] \
|
||||
fprintf(stderr,"usage: %s [-f] [-c] [-d target domain] \
|
||||
[-h source host]\n [-s source domain] \
|
||||
[-C taskid program-number ipaddr port] mapname\n", progname);
|
||||
}
|
||||
|
|
@ -267,18 +279,12 @@ char *progname;
|
|||
void
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
if (!isatty(0)) {
|
||||
int fd;
|
||||
char logfile[MAXPATHLEN];
|
||||
sprintf (logfile, "%sypxfr.log", _PATH_YP);
|
||||
if ((fd = open(logfile, O_CREAT|O_WRONLY|O_APPEND, 0644))) {
|
||||
close(0);
|
||||
dup(fd);
|
||||
close(1);
|
||||
dup(fd);
|
||||
close(2);
|
||||
dup(fd);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
if (!isatty(2)) {
|
||||
openlog(argv[0], LOG_PID, LOG_DAEMON);
|
||||
logflag = 1;
|
||||
}
|
||||
|
||||
if (argc < 2)
|
||||
|
|
@ -330,7 +336,7 @@ main (int argc, char **argv)
|
|||
for (; *argv; argv++) {
|
||||
enum ypxfrstat y;
|
||||
if ((y=ypxfr(*argv))!=YPXFR_SUCC) {
|
||||
fprintf(stderr, "%s\n", ypxfr_err_string(y));
|
||||
Perror("%s\n", ypxfr_err_string(y));
|
||||
}
|
||||
if (TaskId) {
|
||||
struct sockaddr_in addr;
|
||||
|
|
|
|||
Loading…
Reference in a new issue