nisrmdir.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 1988-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* nis+ dir remove utility
*/
#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <signal.h>
#include <netdir.h>
#include <netconfig.h>
#include <rpcsvc/nis_dhext.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#define ROOT_OBJ "root.object"
extern nis_name __nis_local_root();
char fname[NIS_MAXNAMELEN];
int nserv;
int errcode = 0;
static
int
{
return (1);
return (0);
}
void
{
int ns, i;
/*
* put any servers that weren't removed (non-nil name) back into the
* directory.
*/
if (ns == i)
ns++;
else
}
}
if (ns) {
}
exit(1);
}
int sservi;
void
{
/*
* put the slave back in the directory.
*/
}
exit(1);
}
/*
* remove_directory is a special rmdir that takes care of the root case.
* This is needed only for the -s option when the host or directory object
* specified in the removal no longer exists. Otherwise,
* the nis_remove operation on the directory object would result in
* the replicas receiving pings to remove the root object in the root case.
*/
{
if (s != NIS_SUCCESS) {
if (verbose)
return (s);
}
/* root replica: send ping to remove root object. */
}
return (s);
}
#define OP_RMDIR 0
#define OP_RMSLAVE 2
void
usage()
{
exit(1);
}
int argc;
char *argv[];
{
int c;
char ask_remove = 0, force_remove = 0;
char *host = 0;
char *name;
nis_error s;
int bad_name;
switch (c) {
case 'i':
ask_remove = 1;
break;
case 'f':
force_remove = 1;
break;
case 's':
op = OP_RMSLAVE;
break;
default:
usage();
}
}
usage();
else
expand = 0;
/*
* Get the directory object.
*/
if (force_remove) {
/*
* If specifying host, maybe trying to clean up
* directory that has already been removed.
*/
exit(1);
}
if (expand == 0)
sizeof (fname)) >=
sizeof (fname));
else
sizeof (fname),
"%s.%s", name,
nis_local_directory()) >=
sizeof (fname));
if (bad_name) {
exit(1);
}
}
exit(0);
}
exit(1);
}
if (bad_name) {
exit(1);
}
exit(1);
}
if (ask_remove || expand) {
*buf = '\0';
exit(0);
}
switch (op) {
case OP_RMDIR:
/*
* remove directory object
*/
}
}
if (force_remove)
exit(0);
exit(1);
}
/*
* fork a child and *try* to do nis_rmdirs. this may take
* a while since we may try to talk to servers that aren't
* up/responding.
*/
if (force_remove)
switch (fork()) {
case 0:
for (i = nserv-1; i >= 0; i--)
default:
exit(0);
}
/*
* remove slave directories
*/
if (s != NIS_SUCCESS) {
nur++;
"cannot remove replica \"%s\": %s.\n",
} else
}
if (nur)
/*
* if all slave directories were removed, remove master
*/
if (s != NIS_SUCCESS) {
}
exit(0);
case OP_RMSLAVE:
/*
* find the slave.
*/
if (found >= 0) {
"\"%s\" is not unique, please use full host name.\n",
host);
exit(1);
}
found = i;
}
}
/*
* Host no longer listed as a replica. Try anyhow; perhaps
* user trying to clean up.
*/
if (found == -1) {
if (!force_remove) {
"Host \"%s\" is not listed as a replica for \"%s\".\n",
"Use the -fs option to attempt rmdir anyhow.\n");
exit(1);
}
exit(1);
}
exit(0);
}
/* Host named is master */
if (found == 0) {
if (force_remove)
exit(0);
exit(1);
}
/*
* remove slave from the directory object.
*/
}
if (force_remove)
exit(0);
exit(1);
}
/*
* fork a child and *try* to do nis_rmdir. this may take
* a while since we may try to talk to servers that aren't
* up/responding.
*/
if (force_remove)
switch (fork()) {
case 0:
default:
exit(0);
}
/*
* remove the actual directory.
*/
if (s != NIS_SUCCESS) {
exit(1);
}
exit(0);
}
}