nisinit.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 (c) 1991-1999 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This module contains the nis initialization code. It is designed to
* initialize a client or server. The server can be a master server or
* a slave server (replicate). NOTE: This file defines what the "psuedo"
* tables look like when defined by the server. This means that this
* module and the nis_db.c module must track each other. This module
* gets linked to nis_db.o and the database library.
*
* This is version 3 of this file, most of it has been taken over
* by nismkdir and the service itself.
* This is version 2 of this file, version 1 was a major hack this
* is more structured but still pretty hackish.
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <netdir.h>
#include <netconfig.h>
#include <nsswitch.h>
#include "nis_svc.h"
#include "nis_proc.h"
#define COLDSTART "/var/nis/NIS_COLD_START"
extern int errno;
extern int optind; /* getopt counter */
extern char *optarg; /* getopt pointer */
char valid_dir_obj = 0;
char *local_dir;
char *secure_dir;
/*
* get_server()
*
* This function constructs a local server description of the current
* server and returns it as a nis_server structure. This is then added
* to the list of servers who serve this directory.
*/
char *host;
{
#define INC_SIZE 512
int myaddr_size = INC_SIZE;
static nis_server myself;
char hname[256];
int num_ep = 0, i;
void *nch;
struct nd_hostserv hs;
struct nd_addrlist *addrs;
exit(1);
}
nch = setnetconfig();
if (num_ep == myaddr_size) {
myaddr_size += INC_SIZE;
(void *)myaddr,
myaddr_size * sizeof (endpoint));
"Error: out of memory\n");
exit(1);
}
}
}
}
}
if (! num_ep) {
"\nError: Unable to construct an address from name '%s'\n",
exit(1);
}
return (&myself);
}
/*
* This function initializes a directory object. It is used when
* creating the object for master servers, and for creating a
* prototype coldstart file which is then used to build the
* real coldstart file. It returns false if it couldn't get
* a nis_server structure for the passed hostname. If this
* name is a null pointer it builds the directory object for
* the local host and cannot fail.
*/
void
char *host; /* Optional host */
{
}
static
int
{
int stat;
return (0);
if (! stat) {
"\nError: Couldn't decode returned object.\n");
return (0);
}
return (0);
}
valid_dir_obj = 1;
return (1);
}
/*
* The bc_init_data() function is called by the callback function of
* the RPC broadcast function.
*/
caddr_t x;
{
return (decode_dir(res));
}
static
int
char *dir;
{
if (!__readColdStartFile(&dobj))
return (1);
return (0);
}
return (1);
}
void
usage(s)
char *s;
{
"usage: \t%s [-k key_domain] -c -H host|-B|-C coldstart\n", s);
exit(1);
}
void
int argc;
char *argv[];
{
int c; /* Option character */
struct stat s;
char buf[1024];
char *directory = nis_local_directory(),
*hostname = nis_local_host(),
int ss;
char *tmpp;
struct __nsw_switchconfig *conf;
enum __nsw_parse_err perr;
int print_warn = 0;
int heerr;
/*
* Make sure that files created by stdio don't
* have extra permission. We allow group and world
* read because the files and directories we create
* need to be world readable.
*/
(void) umask(022);
if (geteuid() != 0) {
exit(1);
}
/*
* By default Solaris2.0/SunOS 5.0 is setup as an NIS (YP) client.
* In order to use NIS+, publickeys must be gotten from NIS+ if
* NIS+ is running in secure mode.
*/
"Warning: There is no publickey entry in %s.\n",
"The default publickey policy is \"publickey: nis\".\n");
print_warn = 1;
struct __nsw_lookup *look;
"Warning: The publickey entry in %s is \"publickey: ",
}
print_warn = 1;
}
if (print_warn == 1) {
"In order to use NIS+, it should be \"publickey: nisplus\".\n");
"For more information, see secure_rpc(3N), publickey(3N), & nisaddcred(1).\n");
}
switch (c) {
case 'k':
secure_dir = optarg;
break;
case 'r' :
break;
case 'c':
op = MAKE_CLIENT;
break;
case 'p' :
optarg++;
switch (*optarg) {
case 'Y' :
break;
case 'D' :
break;
case 'N' :
break;
default :
"unrecognized name service type, use one of:\n");
" Y = Sun YP\n D = Domain Name Service\n");
" N = Sun NIS+\n");
}
op = MAKE_PARENT;
break;
case 'C' :
src = SRC_CSTART;
break;
case 'H' :
break;
case 'B' :
break;
#ifdef NIS_MCAST_SUPPORT
case 'M' :
break;
#endif
case '?' :
default :
break;
}
}
}
/* Only making the parent requires extra data (host name) */
"Error: Extra input at the end of the command.\n");
"Error: Make parent (-p) requires parent domain and at least one host.\n");
}
}
perror("mkdir");
buf);
exit(1);
}
} else if (ss == -1) {
perror("stat");
exit(1);
}
/*
* exist with the correct permissions.
*/
switch (op) {
case MAKE_ROOT:
case MAKE_PARENT:
if (op == MAKE_PARENT) {
"Error: Parent object cannot be created before creating a root object.\n");
exit(1);
}
perror("mkdir");
"\"%s\"\n", buf);
exit(1);
}
} else if (ss == -1) {
perror("stat");
exit(1);
} else {
"Warning: Bad permissions (%o) on the %s directory.\n",
}
/* Some data is already in this directory */
"Warning: Old data exists under "
"the \"%s\" directory.\n\n", buf);
else {
/* make sure that the root_object is there */
"Error: Parent object cannot be created before creating a root object.\n");
exit(1);
} else if (ss == -1) {
perror("stat");
"Error: Unable to stat \"%s\"\n",
exit(1);
}
}
}
}
"This machine is in the \"%s\" NIS+ domain.\n", local_dir);
switch (op) {
case MAKE_ROOT :
printf("Setting up root server ...\n");
/*
* Step 0. See if we have the info we need.
*/
/*
* Step 1. Create Directory object
* Since we are the master server, the d_obj should
* not pre-exist.
*/
/* Make this object readable by nobody */
NIS_DESTROY_ACC) << 8);
if (! status) {
"\nError: Unable to write root object.\n");
exit(1);
}
/* Write cold start file */
__nis_CacheRestart(); /* in case cachemgr running */
/* Create the serving list file */
"\nERROR: could not open file \"%s\" for storing directories served.\n",
buf);
exit(1);
}
break;
case MAKE_PARENT :
printf("Setting up parent object ...\n");
/*
* Step 1. Create Directory object
* Since we are the master server, the d_obj should
* not pre-exist.
*/
for (i = 0; i < nhosts; i++) {
AI_DEFAULT, &heerr);
if (! he) {
"\nError: Couldn't locate address information for \"%s\".\n",
exit(1);
}
addr =
if (IN6_IS_ADDR_V4MAPPED(&addr)) {
} else {
}
case NIS:
case SUNYP:
break;
case DNS:
break;
}
else
}
if (! status) {
"\nError: Unable to write parent object.\n");
exit(1);
}
break;
case MAKE_CLIENT :
printf("Setting up NIS+ client ...\n");
if (secure_dir == NULL) {
if (!check_coldstart(local_dir)) {
"\nError: system domain name doesn't match that stored in \"%s\"\n",
" use the -k option to specify the domain where root's");
" key is stored.\n");
exit(1);
}
} else {
"\nError: system domain name must be the same as or lower than the\n");
" domain in which root's key is stored.\n");
exit(1);
}
}
switch (src) {
case SRC_NONE :
"\nError: Missing source for client setup.\n");
break;
case SRC_HNAME :
break;
case SRC_CSTART :
if (sfd == -1) {
"\nError: Can't open file \"%s\" "
"for reading.\n", coldstart);
exit(1);
}
if (dfd == -1) {
"\nError: Can't open file \"%s\" "
"for writing.\n", COLDSTART);
exit(1);
}
break;
case SRC_BCAST :
xdr_fd_args, (char *)&fdarg,
xdr_fd_result, (char *)&fdres,
NULL);
(dummy == RPC_SUCCESS) &&
else {
"\nError: No servers responding, use -H option \n");
exit(1);
}
break;
case SRC_MCAST :
break;
default :
break;
}
/*
* At this point there should be something of a
* not then we're hosed.
*
* We switch to a local cache so that there is
* no conflict if nis_cachemgr is still running
* with a copy of an old domain name.
*/
"\nError: Could not create a valid NIS+ coldstart file\n");
exit(1);
}
printf("All done.\n");
exit(0);
default :
printf("\n");
}
printf("All done.\n");
exit(0);
}