nismkdir.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) 1988-1995,2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* NIS+ directory and server create utility
*
*/
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <netdir.h>
#include <netconfig.h>
#include <rpc/key_prot.h>
#include <rpcsvc/nis_dhext.h>
#define MAX_REPLICA 64
char *defstr = 0;
int errcode = 0;
extern int optind;
extern char *optarg;
extern nis_object nis_default_obj;
void
make_directory(char *name)
{
nis_error s;
/*
* Break name into leaf and domain components.
*/
if ((p = nis_leaf_of(name)) == 0) {
exit(1);
}
/*
* Get the parent directory object.
*/
exit(1);
}
if (!nis_defaults_init(defstr))
exit(1);
/*
* Turn the parent directory object into the
* sub-directory object. If we cared about memory
* leaks, we would save pointers to the fields that
* are being overwritten, and restore them and free
* the parent object when we are done.
*/
exit(1);
}
/*
* Make the directory and add it to the namespace.
*/
exit(1);
} else {
if (s != NIS_SUCCESS) {
(void) nis_remove(name, 0);
nis_perror(s, "can't make directory");
exit(1);
}
}
/*
* do not free res because it contains pointers to structures
* it did not allocate.
*/
}
static int
int to_be_master) /* will it be a master? */
{
/* Try to lookup directory to serve... */
/* If it doesn't exist, we can't have a (replica) server for it! */
return (0);
}
/* It exists, but is it a directory object? */
return (0);
}
}
/* Try to lookup domain of host who wants to be a server... */
/* Can't get host domain, servers busy or domain name bogus... */
return (0);
}
/* It exists, but is it a directory object? */
return (0);
}
case SAME_NAME:
return (0);
}
if (status != NIS_SUCCESS) {
"nismkdir: can't contact root server for \"%s\""
return (0);
}
/* If the server-to-be is in the root domain, it can serve. */
return (1);
} else {
"nismkdir: host '%s' must be in a domain above '%s'\n",
host, dir_to_serve);
return (0);
}
case LOWER_NAME:
/* directory is below domain of host in question... okay */
return (1);
case HIGHER_NAME:
case NOT_SEQUENTIAL:
"nismkdir: host '%s' must be in a domain above '%s'\n",
host, dir_to_serve);
return (0);
case BAD_NAME:
default:
"nismkdir: cannot parse either or both of '%s' and '%s'\n",
return (0);
}
}
void
{
nis_error s;
int nserv, i;
/*
* Does the directory already exist?
*/
exit(1);
}
exit(1);
}
"\"%s\" is already master for \"%s\"!\n",
exit(1);
}
/*
* Verify server able to serve intended domain.
*/
exit(1);
/*
* Add master to list of servers and demote current
* master to the role of a slave.
*/
for (i = 1; i < nserv; i++)
if (nis_dir_cmp(
break;
if (i < nserv) {
sserv =
} else {
0) {
"can't add master");
exit(1);
}
for (i = 0; i < nserv; i++)
serv[i+1] =
}
exit(1);
}
/*
* do not free res because it contains pointers to
* structures it did not allocate.
*/
} else {
if (!nis_defaults_init(defstr))
exit(1);
/*
* Construct the directory object.
*/
exit(1);
}
/*
* Make the directory and add it to the namespace.
*/
exit(1);
} else {
if (s != NIS_SUCCESS) {
(void) nis_remove(name, 0);
nis_perror(s, "can't make directory");
exit(1);
}
}
}
}
void
{
int nserv, i;
/*
* Get the directory object.
*/
exit(1);
}
exit(1);
}
exit(1);
}
for (i = 0; i < nserv; i++)
if (nis_dir_cmp(
break;
if (i < nserv) {
exit(1);
}
/*
* Verify server able to serve intended domain
*/
exit(1);
/*
* Add slave to the list of servers.
*/
exit(1);
}
for (i = 0; i < nserv; i++)
exit(1);
}
/*
* do not free res because it contains pointers to structures
* it did not allocate.
*/
}
void
usage()
{
"usage: nismkdir [-D defaults] [-m hostname] [-s hostname] dirname\n");
exit(1);
}
void
int argc;
char *argv[];
{
int c;
int i;
char *host;
char *name;
int update_master = 0;
char *replicas[MAX_REPLICA];
int nreplicas = 0;
switch (c) {
case 'D':
break;
case 'm':
if (update_master) {
"only one master can be specified\n");
exit(1);
}
update_master = 1;
break;
case 's':
if (nreplicas >= MAX_REPLICA) {
exit(1);
}
break;
default:
usage();
}
}
usage();
exit(1);
}
/*
* If no master or replica flag, just create directory.
* The directory will have the same replication as its parent
* directory.
*/
if (! update_master && nreplicas == 0)
else {
if (update_master)
for (i = 0; i < nreplicas; i++)
}
exit(0);
}