ypserv_resolv.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <syslog.h>
#include <signal.h>
#include <string.h>
#include <sys/resource.h>
#include <errno.h>
#ifdef TDRPC
#else
#include <sys/systeminfo.h>
#include <netconfig.h>
#include <netdir.h>
#endif
#include "ypserv_resolv_common.h"
#define YPDNSVERS 2L
#ifdef TDRPC
#define RESOLV_EXEC_PATH "/usr/etc/rpc.nisd_resolv"
#define RESOLV_EXEC_ERR "can't exec /usr/etc/rpc.nisd_resolv: %s\n"
#else
#define RESOLV_EXEC_PATH "/usr/sbin/rpc.nisd_resolv"
#define RESOLV_EXEC_ERR "can't exec /usr/sbin/rpc.nisd_resolv: %s\n"
#endif
extern bool silent;
int verbose;
extern int resolv_pid;
{
char *tp;
#ifdef TDRPC
struct sockaddr_in addr;
int sock;
#else
char name[257];
void *h;
#endif
if (! *fwding)
return;
#ifdef TDRPC
#else
/* try the specified netid (default ticots), then any loopback */
return;
}
#endif
/*
* Startup the resolv server: use transient prognum if prognum
* isn't set. Using transient means we create mapping then
* pass child the fd to use for service.
*/
#ifndef TDRPC
endnetconfig(h);
#endif
return;
}
case -1: /* error */
#ifndef TDRPC
endnetconfig(h);
#endif
return;
case 0: /* child */
/*
* if using transient we must maintain fd across
*
* if using transient we'll just do svc_tli_create
* in child on our bound fd.
*/
"-F", /* forground */
NULL);
exit(1);
default: /* parent */
/* close fd, free xprt, but leave mapping */
if (xprt)
/* let it crank up before we create client */
sleep(4);
}
#ifdef TDRPC
sock = RPC_ANYSOCK;
} else {
}
return;
}
#else
endnetconfig(h);
return;
}
endnetconfig(h);
return;
}
endnetconfig(h);
#endif
/* ping for comfort */
clnt_destroy (*client);
return;
}
if (verbose)
}
{
int fd;
#ifdef TDRPC
int proto;
#else
#endif
/* If prognum specified, use it instead of transient hassel. */
if (*prognum) {
return (TRUE);
}
/*
* Transient hassel:
* - parent must create mapping since someone else could
* steal the transient prognum before child created it
* - pass the child the fd to use for service
* - close the fd (after exec), free xprt, leave mapping intact
*/
#ifdef TDRPC
proto = IPPROTO_UDP;
} else {
proto = IPPROTO_TCP;
}
return (FALSE);
start++;
#else
/* tp_type is legit: users choice or a loopback netid */
return (FALSE);
return (FALSE);
}
start++;
#endif
return (TRUE);
}
#ifndef TDRPC
{
return (FALSE);
return (TRUE);
}
if (save) {
return (TRUE);
} else {
return (FALSE);
}
}
#endif
{
struct ypfwdreq_key4 fwd_req4;
struct ypfwdreq_key6 fwd_req6;
#ifdef TDRPC
struct sockaddr_in *addrp;
#else
char *uaddr;
char *cp;
int i;
struct sockaddr_in *sin4;
struct sockaddr_in6 *sin6;
#endif
if (! *fwding)
return (FALSE);
/* default status is YP_NOKEY */
return (FALSE);
}
#ifdef TDRPC
#else
/*
* In order to tell if we have an IPv4 or IPv6 caller address,
* we must know that nb->buf is a (sockaddr_in *) or a
* (sockaddr_in6 *). Hence, we might as well dispense with the
* conversion to uaddr and parsing of same that this section
* of the code previously involved itself in.
*/
if (nb != 0)
} else {
return (FALSE);
}
#endif
/* Restart resolver if it died. (possible overkill) */
"Restarting resolv server: old one (pid %d) died.\n", *pid);
clnt_destroy (*client);
if (!*fwding) {
"can't restart resolver: ending resolv service.\n");
return (FALSE);
}
}
/* may need to up timeout */
} else {
}
return (TRUE);
else { /* Over kill error recovery */
/* make one attempt to restart service before turning off */
"Restarting resolv server: old one not responding.\n");
clnt_destroy (*client);
if (!*fwding) {
"can't restart resolver: ending resolv service.\n");
return (FALSE);
}
} else {
}
return (TRUE);
else {
/* no more restarts */
clnt_destroy (*client);
"restarted resolver not responding: ending resolv service.\n");
return (FALSE);
}
}
}