nistbladm.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-2000 Sun Microsystems Inc
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* nis+ table admin utility
*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
extern int optind;
extern char *optarg;
extern nis_object nis_default_obj;
extern char *nisname_index();
char *DEFAULT_PATH = "";
char *DEFAULT_SEP = " ";
#define OP_CREATE 1
#define OP_UPDATE 2
#define OP_DESTROY 3
#define OP_ADD 4
#define OP_MODIFY 5
#define OP_REMOVE 6
/* change defines */
#define CHG_PATH 1
#define CHG_SEP 2
#define CHG_ACCESS 4
#define CHG_TYPE 5
struct buf {
char *s;
int len;
int alloc;
};
static
void
{
b->len = 0;
if (b->s == NULL) {
exit(1);
}
}
static
void
{
if (b->s == NULL) {
exit(1);
}
}
b->s[b->len] = c;
b->len += 1;
}
static
void
{
while (*src)
}
/*
* This function is used to copy a "colname=value" string into another
* string that will be passed to nis_get_request. Any unquoted ","
* or "]" characters are quoted so that they won't be interpreted as
* the end of the indexed name.
*/
static
void
{
/*
* Process each character in src. If it is a quote, copy
* characters until reaching the terminating quote. If it
* is a ',' or a ']', then quote it into dest. All other
* characters are copied "as is".
*/
while (*src) {
if (*src == '"') {
if (*src)
buf_add(b, '"');
buf_add(b, '"');
} else {
}
}
}
static
void
{
int i;
for (i = 0; i < n && *s; i++) {
buf_add(b, *s++);
}
}
static
char *
{
char *p;
if (p == NULL) {
exit(1);
}
p[b->len] = 0;
return (p);
}
void
usage()
{
"usage:\tnistbladm [-D defaults] -c [-p path] [-s sep] type\n");
"\tnistbladm -u [-p path] [-s sep] [-t type] [colname=access ...] tablename\n");
"\tnistbladm [-D defaults] -a|A colname=val ... tablename\n");
exit(1);
}
int argc;
char *argv[];
{
int c;
int len;
char *defstr = 0;
int op = 0;
unsigned flags = 0;
char *name;
int ta_maxcol, i, j;
char *p, *p1;
char *mpred;
char *spred;
char *sname;
char *tname;
nis_error s;
int nrights = 0;
char **colname;
char **rights;
switch (c) {
case 'D':
break;
case 'c':
if (op)
usage();
break;
case 'u':
if (op)
usage();
break;
case 'd':
if (op)
usage();
op = OP_DESTROY;
break;
case 'A':
flags |= ADD_OVERWRITE;
case 'a':
if (op)
usage();
break;
case 'e':
flags |= MOD_EXCLUSIVE;
case 'm':
case 'E':
if (op)
usage();
break;
case 'R':
flags |= REM_MULTIPLE;
case 'r':
if (op)
usage();
break;
case 'p':
break;
case 's':
"separator must be a single character\n");
exit(1);
}
break;
case 't':
break;
default:
usage();
}
}
if (!op)
usage();
if (!nis_defaults_init(defstr))
exit(1);
switch (op) {
case OP_CREATE:
usage();
/*
* Most standard tables are created by nissetup, so they
* get the correct number of columns. However, automount_map
* tables are an exception, and are often added by the admin.
* Thus we check that they have exactly two columns, in order
* to avoid confusing applications like automountd.
*/
"automount_map type nis+ tables must have exactly "
"two columns.\n");
exit(1);
}
== 0) {
exit(1);
}
for (i = 0; i < ta_maxcol; i++) {
if ((p = strchr(p, '=')) == 0)
usage();
*(p++) = 0;
if (*p) {
if (p1)
*(p1++) = 0;
} else
p1 = 0;
usage();
usage();
}
exit(1);
}
exit(1);
}
exit(0);
case OP_UPDATE:
usage();
exit(1);
}
for (i = 0; i < nrights; i++) {
if (p == 0) {
"Missing access rights for "
exit(1);
}
*p++ = 0;
exit(1);
}
optind++;
}
}
if (*name == '[')
usage();
break;
case OP_DESTROY:
usage();
break;
case OP_ADD:
case OP_REMOVE:
usage();
if (*p == '[') {
if (name == 0)
usage();
name++;
if (*name == ',')
name++;
usage();
name = p;
} else {
buf_cat_quote(&spred_buf, p);
}
if (*name == '[')
usage();
}
break;
case OP_MODIFY:
usage();
}
if (*p != '[')
usage();
if (name == 0)
usage();
name++;
if (*name == ',')
name++;
break;
}
/*
* Get the table object.
*/
exit(1);
}
exit(1);
}
exit(1);
}
switch (op) {
case OP_UPDATE:
/* Now we morph the table object, first start with orig */
/* Change its type if desired */
if (ta_type)
/* Change the separator if desired */
if (ta_sep != DEFAULT_SEP)
/* Change the path if desired */
if (ta_path != DEFAULT_PATH)
/* Allocate some column descriptors */
if (tcol == 0) {
exit(1);
}
/* Set the new table to have these malloc'd columns */
/* check the table schema */
for (i = 0; i < nrights; ++i) {
for (j = 0; j < ta_maxcol; ++j)
break;
if (j == ta_maxcol) {
"Invalid table schema: \"%s\" is an invalid "
"column.\n", colname[i]);
exit(1);
}
}
for (j = 0; j < ta_maxcol; j++) {
/* Copy the old column into the new column */
/* Check to see if new access rights were specified */
for (i = 0; i < nrights; i++) {
/* If so change them appropriately */
rights[i])) {
"Couldn't parse access rights (%s) for column \"%s\"\n",
rights[i],
colname[i]);
exit(1);
} else {
break;
} /* parsed correctly */
} /* same name as index */
} /* for all indices */
} /* for all columns */
exit(1);
}
exit(0);
case OP_DESTROY:
exit(1);
}
exit(0);
case OP_ADD:
exit(1);
}
if (*spred == '[')
else
/*
* Parse search criteria.
*/
if (s != NIS_SUCCESS) {
nis_perror(s, "can't parse column values");
exit(1);
}
== 0) {
exit(1);
}
for (j = 0; j < ta_maxcol; j++)
if (strcmp(
break;
if (j < ta_maxcol) {
} else {
"table has no column named \"%s\"\n",
exit(1);
}
}
exit(1);
}
break;
case OP_MODIFY:
/*
* Parse modify criteria.
*/
exit(1);
}
if (s != NIS_SUCCESS) {
nis_perror(s, "can't parse column values");
exit(1);
}
== 0) {
exit(1);
}
for (j = 0; j < ta_maxcol; j++)
if (strcmp(
break;
if (j < ta_maxcol) {
} else {
"table has no column named \"%s\"\n",
exit(1);
}
}
exit(1);
}
exit(1);
}
break;
case OP_REMOVE:
exit(1);
}
if (*spred == '[')
else
exit(1);
}
break;
}
exit(0);
}