ypserv.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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This contains the mainline code for the YP server. Data
* structures which are process-global are also in this module.
*/
/* this is so that ypserv will compile under 5.5 */
#define _SVID_GETTOD
extern int gettimeofday(struct timeval *);
#include "ypsym.h"
#include <fcntl.h>
#include <netconfig.h>
#include <netdir.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <stdarg.h>
#include <signal.h>
#include "shim.h"
#include "yptol.h"
#include <syslog.h>
static char register_failed[] = "ypserv: Unable to register service for ";
/*
* client_setup_failure will be TRUE, if setup of the
* connection to rpc.nisd_resolv failed
*/
bool client_setup_failure = FALSE;
/* N2L options */
bool init_containers = FALSE;
/* For DNS forwarding command line option (-d) */
bool dnsforward = FALSE;
int resolv_pid = 0;
char *resolv_tp = "ticots";
#ifdef MINUS_C_OPTION
/* For cluster support (-c) */
#endif
static char logfile[] = "/var/yp/ypserv.log";
static void ypexit(void);
static void cleanup_resolv(int);
/*
* This is the main line code for the yp server.
*/
int
{
if (geteuid() != 0) {
exit(1);
}
/* Set up shop */
/* If requested set up the N2L maps. May take a while */
if (init_dit)
" See syslog and LDAP server logs for details.\n");
exit(1);
}
if (init_maps)
if (FAILURE == dump_dit_to_maps()) {
" See syslog and LDAP server logs for details.\n");
exit(1);
}
/*
* If we were asked to init the maps now exit. User will then use
* ypstart to restart ypserv and all the other NIS daemons.
*/
printf("Map setup complete. Please now restart NIS daemons "
"with ypstart.\n");
exit(0);
}
svc_run();
/*
* This is stupid, but the compiler likes to warn us about the
* absence of returns from main()
*/
return (0);
}
typedef struct {
char *netid;
int fd;
int olddispatch; /* Register on protocol version 1 ? */
int class; /* Other services that must succeed */
int ok; /* Registered successfully ? */
} ypservice_t;
ypservice_t service[] = {
{ "udp", -1, 1, 4, 0, 0 },
{ "tcp", -1, 1, 4, 0, 0 },
{ "udp6", -1, 0, 6, 0, 0 },
{ "tcp6", -1, 0, 6, 0, 0 }
};
int service_classes[MAXSERVICES];
/*
* Does startup processing for the yp server.
*/
static void
{
int pid;
int stat, t;
int connmaxrec = RPC_MAXDATASIZE;
int i, j, services = 0;
/*
* Init yptol flags. Will get redone by init_lock_system() but we need
* to know if we should parse yptol cmd line options.
*/
if (silent) {
if (pid == -1) {
logprintf("ypserv: ypinit fork failure.\n");
ypexit();
}
if (pid != 0) {
exit(0);
}
}
if (!init_lock_system(FALSE)) {
ypexit();
}
get_secure_nets(argv[0]);
if (silent) {
closelog();
closefrom(3);
}
if (yptol_mode) {
if (stat == 1) {
logprintf("NIS to LDAP mapping inactive.\n");
} else if (stat != 0) {
logprintf("Aborting after NIS to LDAP mapping "
"error.\n");
exit(-1);
}
}
if (silent) {
} else {
}
setpgrp();
}
#ifdef SYSVCONFIG
#else
#endif
/*
* Setting disposition to SIG_IGN will not create zombies when child
* processes terminate.
*/
/*
* Set non-blocking mode and maximum record size for
* connection oriented RPC transports.
*/
logprintf("unable to set maximum RPC record size");
}
for (i = 0; i < sizeof (service)/sizeof (ypservice_t); i++) {
service_classes[i] = -1;
logprintf("getnetconfigent(\"%s\") failed\n",
continue;
}
0) {
continue;
}
NULL) < 0) {
logprintf("could not set reserved port for %s\n",
continue;
}
logprintf("svc_tli_create failed for %s\n",
continue;
}
nconf)) {
continue;
}
logprintf("old %s %s\n",
continue;
}
services++;
}
/*
* Check if we managed to register enough services to continue.
* It's OK if we managed to register all IPv4 services but no
* IPv6, or the other way around, but not if we (say) registered
* IPv4 UDP but not TCP.
*/
if (services > 0) {
for (j = 0; j < MAXSERVICES; j++) {
if (service_classes[j] >= 0) {
/*
* Must have all services of this class
* registered.
*/
for (i = 0; i < MAXSERVICES; i++) {
service_classes[j]) {
"unable to register all services for class %d\n",
ypexit();
}
}
}
}
} else {
logprintf("unable to register any services\n");
ypexit();
}
/* Now we setup circuit_n or yp_all() and yp_update() will not work */
ypexit();
}
if (dnsforward) {
&resolv_client, resolv_tp, 0);
if (resolv_client == NULL)
}
}
void
cleanup_resolv(int sig)
{
if (resolv_pid)
}
/*
* This picks up any command line args passed from the process invocation.
*/
static void
{
if ((*argv)[0] == '-') {
switch ((*argv)[1]) {
#ifdef MINUS_C_OPTION
case 'c':
break;
#endif
case 'd':
"No /etc/resolv.conf file, -d option ignored\n");
} else {
dnsforward = TRUE;
}
break;
case 'I':
/* ... and also do -i stuff */
case 'i':
if (yptol_mode) {
} else {
"if not in NIS to LDAP mode. Exiting\n",
(*argv)[1]);
exit(-1);
}
/* Handle -ir */
break;
case 'r':
if (yptol_mode) {
} else {
"if not in NIS to LDAP mode. "
"Exiting\n");
exit(-1);
}
break;
case 'v':
break;
}
}
}
/* If setting up don't run silent or demonize */
}
/*
* This dispatches to server action routines based on the input procedure
* number. ypdispatch is called from the RPC function svc_run.
*/
static void
{
#ifdef SYSVCONFIG
/* prepare to answer questions about system v filesystem aliases */
sysvconfig();
#endif
sigemptyset(&set);
case YPPROC_NULL:
logprintf("ypserv: Can't reply to rpc call.\n");
break;
case YPPROC_DOMAIN:
break;
case YPPROC_DOMAIN_NONACK:
break;
case YPPROC_MATCH:
break;
case YPPROC_FIRST:
break;
case YPPROC_NEXT:
break;
case YPPROC_XFR:
break;
case YPPROC_NEWXFR:
break;
case YPPROC_CLEAR:
logprintf("ypserv: Can't reply to rpc call.\n");
break;
case YPPROC_ALL:
break;
case YPPROC_MASTER:
break;
case YPPROC_ORDER:
break;
case YPPROC_MAPLIST:
break;
default:
break;
}
}
static void
{
sigemptyset(&set);
case YPOLDPROC_NULL:
logprintf("ypserv: Can't replay to rpc call.\n");
break;
case YPOLDPROC_DOMAIN:
break;
case YPOLDPROC_DOMAIN_NONACK:
break;
case YPOLDPROC_MATCH:
break;
case YPOLDPROC_FIRST:
break;
case YPOLDPROC_NEXT:
break;
case YPOLDPROC_POLL:
break;
case YPOLDPROC_PUSH:
break;
case YPOLDPROC_PULL:
break;
case YPOLDPROC_GET:
default:
break;
}
}
/*
* This flushes output to stderr, then aborts the server process to leave a
* core dump.
*/
static void
ypexit(void)
{
abort();
}
/*
* This constructs a logging record.
*/
void
{
struct timeval t;
if (silent) {
gettimeofday(&t);
}
}