nisedit.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 1991-2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "nisplus.h"
#include <pwd.h>
#include <search.h>
/*
* These are pointers to trees built from the "old" and "new" versions
* of the alias database when we run in edit mode.
*/
static int get_mailias();
/*
* mailias_cmp returns 0 if the the ALIAS_COL ONLY of
* an nis alias table entry are the same. Otherwise it
* it returns -1 if obj1 is lexicographically less than obj2
* it returns 1 if obj1 is lexicographically greater than obj2
* N.B. This needs to be a function instead of a macro because it's
* passed to the tsearch and tfind family of routines.
*/
static int
{
/* basically strcmp inlined for performance */
if (*s1++ == '\0')
return (0);
}
/*
* mailias_eq returns 1 if ALL columns of two alias objects are
* the same. Otherwise it returns 0.
*/
static int
{
/* check ALIAS column */
return (FALSE);
} else
return (FALSE);
/* check EXPN column */
return (FALSE);
} else
return (FALSE);
/* check COMMENTS column */
return (FALSE);
} else
return (FALSE);
/* check OPTIONS column */
return (FALSE);
} else
return (FALSE);
/* Done */
return (TRUE);
}
/*
* nis_mailias_list(fp, map, domain)
* prints the nis alias map contained in "map" in the domain "domain"
* to the file pointed to by "fp" in format which is human readable.
* The format is "alias: value #options#comments
* Note that unless the -n flag was specified (which turns off the
* print_comments flag) this format will NOT be compatible with the
*/
void
{
int i;
sizeof (nis_object),
}
}
}
/*
* check_for_deletes(obj, order, level)
*
* when we walk the tree containing the original version of the aliases
* we call this routine. If obj is in the New aliases database we do
* nothing. If obj is NOT found in the new aliases database we
* delete that alias from the nis aliases database.
*/
/* ARGSUSED2 */
static void
const void *obj;
int level;
{
nis_mailias a;
/*
* need to check objects only once otherwise we might try and delete
* a deleted object
*/
return;
/* N.B. obj is really a (nis_object) ** */
return;
/* fall through and delete the object */
#ifdef DEBUG
#endif
}
/*
* check_for_changes(obj, order, level)
*
* when we walk the tree containing the version of the aliases the user created
* we call this routine. If obj is the same as in the old aliases database
* we do nothing. If obj is NOT found in the old aliases database we
* add that alias to the nis aliases database. If the obj is found in the
* old database but has been changed we change (using the nis_change
* operations) that alias in the database
*/
/* ARGSUSED2 */
static void
const void *obj;
int level;
{
nis_object **result;
nis_mailias a;
/*
* need to check objects only once otherwise we might try and change
* or add an object that has already been changed or added.
*/
return;
/* N.B. obj is really a (nis_object) ** */
#ifdef DEBUG
#endif
return;
}
/* alias entry was not changed */
#ifdef DEBUG
#endif
return;
}
/* i.e. the alias entry has changed */
#ifdef DEBUG
#endif
}
/*
* nis_mailias_edit(FILE *fp, nis_name map, nis_man domain)
*
* Edit's the alias map "map" in domain "domain". If fp is non-NULL
* The file pointed to by fp contains the new alias map and no
* editor is invoked.
* The method used is to build two search trees and compare them.
* The first tree pointed to by oroot contains the original alias map.
* the second tree pointed to by nroot contains the desired aliases map.
* The old tree is walked first, if any of the aliases in the old tree are
* missing in the new tree those aliases are deleted. The new tree is
* then walked. If the aliases are added or changed the apropriate
* mailias_function is called.
*/
void
{
int i;
void *key;
exit(-1);
}
sizeof (nis_object),
}
/* print the aliases into a temporary file */
}
}
/* invoke the users editor on that file */
exit(-1);
}
} else {
/* they used the -f command option to read from a file */
}
/* If there were entries in the existing map */
}
}
}
/*
* mailias_parse_file(fp, map, domain)
*
* Returns a pointer to a tsearch(3) style tree which contains nis mail
* alias objects.
*/
extern void *
{
int next_char;
char *p;
nis_mailias a;
/* This used to be a strchr but was inlined for performance */
;
*p = '\0'; /* get rid of \n in the string */
switch (lbuf[0]) {
case '#':
case '\0':
continue;
case ' ':
case '\t':
if (!skipping)
"Non-continuation line starts with space\n");
continue;
}
/*
* Find and Read Any lines that start with whitespace
* (continuation lines)
*/
/* Read a Continuation line */
p = lp;
if (p != NULL) {
free(p);
}
/*
* used to be a strchr,
* inlined for performance
*/
;
*p = '\0';
} else {
break;
}
}
/* Find The Alias Name */
a.name = "";
a.expn = "";
a.comments = "";
a.options = "";
(void) get_mailias(&a, lp);
}
}
return (root);
}
/*
* get_mailias(a, lbuf)
*
* put's the mail alias from lbuf into the alias structure a.
* are perfectly legal on the right hand side of an alias (although
* sendmail won't handle that sort of alias)
*/
static int
get_mailias(a, lbuf)
nis_mailias *a;
char *lbuf;
{
char *ap; /* pointer to the end of the alias field */
char *ep; /* pointer to the end of the expansion field */
char *cp; /* pointer to the end of the comment field */
int cdepth = 0; /* if > 0 we're in a user name comment */
/* (in parens) */
/* Find the ":", all aliases should be of the form alias: value */
/* There used to be a strchr here that was inlined for performance */
;
if (ap == '\0') {
return (FALSE);
}
/* Allocate space and copy the alias into a->name */
return (FALSE);
}
/* Read the alias value */
if (*ep == '(')
cdepth++;
cdepth--;
}
return (FALSE);
}
/* i.e. there are no comments or options */
if (*ep == '\0')
return (TRUE);
/* Read the comments field value */
cdepth = 0;
/*
* Note that notion of comments in parens inside a comment
* field is a bit strange. It's really just a way to
* embed "#"'s in your comments
*/
if (*cp == '(')
cdepth++;
cdepth--;
}
return (FALSE);
}
/* this eliminates the # */
/* i.e. there are no options */
if (*cp == '\0')
return (TRUE);
return (TRUE);
}