1998-08-09 08:43:13 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1994 Regents of the University of Michigan.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that this notice is preserved and that due credit is given
|
|
|
|
* to the University of Michigan at Ann Arbor. The name of the University
|
|
|
|
* may not be used to endorse or promote products derived from this
|
|
|
|
* software without specific prior written permission. This software
|
|
|
|
* is provided ``as is'' without express or implied warranty.
|
|
|
|
*/
|
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/signal.h>
|
|
|
|
#include <ac/string.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/ctype.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/wait.h>
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-11-13 07:19:16 +08:00
|
|
|
#ifdef HAVE_SYS_RESOURCE_H
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/resource.h>
|
1998-11-13 07:19:16 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_PROCESS_H
|
|
|
|
#include <process.h>
|
|
|
|
#endif
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <lber.h>
|
|
|
|
#include <ldap.h>
|
|
|
|
#include <ldapconfig.h>
|
|
|
|
#include "ud.h"
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int load_editor( void );
|
|
|
|
static int modifiable( char *s, short flag );
|
|
|
|
static int print_attrs_and_values( FILE *fp, struct attribute *attrs, short flag );
|
|
|
|
static int ovalues( char *attr );
|
|
|
|
static void write_entry( void );
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
static char *entry_temp_file;
|
|
|
|
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
void
|
|
|
|
edit( char *who )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
LDAPMessage *mp; /* returned from find() */
|
|
|
|
char *dn, **rdns; /* distinguished name */
|
|
|
|
char name[MED_BUF_SIZE]; /* entry to modify */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug & D_TRACE)
|
|
|
|
printf("->edit(%s)\n", who);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* One must be bound in order to edit an entry.
|
|
|
|
*/
|
|
|
|
if (bind_status == UD_NOT_BOUND) {
|
|
|
|
if (auth((char *) NULL, 1) < 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, decide what entry we are going to modify. If the
|
|
|
|
* user has not included a name on the modify command line,
|
|
|
|
* we will use the person who was last looked up with a find
|
|
|
|
* command. If there is no value there either, we don't know
|
|
|
|
* who to modify.
|
|
|
|
*
|
|
|
|
* Once we know who to modify, be sure that they exist, and
|
|
|
|
* parse out their DN.
|
|
|
|
*/
|
|
|
|
if (who == NULL) {
|
|
|
|
if (verbose) {
|
|
|
|
printf(" Enter the name of the person or\n");
|
|
|
|
printf(" group whose entry you want to edit: ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf(" Edit whose entry? ");
|
|
|
|
fflush(stdout);
|
|
|
|
fetch_buffer(name, sizeof(name), stdin);
|
|
|
|
if (name[0] != '\0')
|
|
|
|
who = name;
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((mp = find(who, TRUE)) == NULL) {
|
|
|
|
(void) ldap_msgfree(mp);
|
|
|
|
printf(" Could not locate \"%s\" in the Directory.\n", who);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dn = ldap_get_dn(ld, ldap_first_entry(ld, mp));
|
|
|
|
rdns = ldap_explode_dn(dn, TRUE);
|
|
|
|
Free(dn);
|
|
|
|
if (verbose) {
|
|
|
|
printf("\n Editing directory entry \"%s\"...\n", *rdns);
|
|
|
|
}
|
|
|
|
parse_answer(mp);
|
|
|
|
(void) ldap_msgfree(mp);
|
|
|
|
(void) ldap_value_free(rdns);
|
|
|
|
if (load_editor() < 0)
|
|
|
|
return;
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
write_entry();
|
1998-08-09 08:43:13 +08:00
|
|
|
(void) unlink(entry_temp_file);
|
|
|
|
ldap_uncache_entry(ld, Entry.DN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int
|
|
|
|
load_editor( void )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *cp, *editor = UD_DEFAULT_EDITOR;
|
|
|
|
static char template[MED_BUF_SIZE];
|
1998-11-19 04:08:02 +08:00
|
|
|
#ifndef HAVE_SPAWNLP
|
1998-08-09 08:43:13 +08:00
|
|
|
int pid;
|
|
|
|
int status;
|
1998-11-19 04:08:02 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug & D_TRACE)
|
|
|
|
printf("->load_editor()\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* write the entry into a temp file */
|
|
|
|
(void) strcpy(template, "/tmp/udEdit.XXXXXX");
|
|
|
|
if ((entry_temp_file = mktemp(template)) == NULL) {
|
|
|
|
perror("mktemp");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if ((fp = fopen(entry_temp_file, "w")) == NULL) {
|
|
|
|
perror("fopen");
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
fprintf(fp, "## Directory entry of %s\n", Entry.name);
|
|
|
|
fprintf(fp, "##\n");
|
|
|
|
fprintf(fp, "## Syntax is:\n");
|
|
|
|
fprintf(fp, "## <attribute-name>\n");
|
|
|
|
fprintf(fp, "## <TAB> <value 1>\n");
|
|
|
|
fprintf(fp, "## <TAB> : :\n");
|
|
|
|
fprintf(fp, "## <TAB> <value N>\n");
|
|
|
|
fprintf(fp, "## Lines beginning with a hash mark are comments.\n");
|
|
|
|
fprintf(fp, "##\n");
|
|
|
|
fflush(fp);
|
|
|
|
if (isgroup())
|
|
|
|
rc = print_attrs_and_values(fp, Entry.attrs, ATTR_FLAG_GROUP_MOD);
|
|
|
|
else
|
|
|
|
rc = print_attrs_and_values(fp, Entry.attrs, ATTR_FLAG_PERSON_MOD);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
if ( rc != 0 ) {
|
|
|
|
(void) unlink(entry_temp_file);
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* edit the temp file with the editor of choice */
|
|
|
|
if ((cp = getenv("EDITOR")) != NULL)
|
|
|
|
editor = cp;
|
|
|
|
if (verbose) {
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (( p = strrchr( editor, '/' )) == NULL ) {
|
|
|
|
p = editor;
|
|
|
|
} else {
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
printf(" Using %s as the editor...\n", p );
|
1998-11-13 07:19:16 +08:00
|
|
|
#ifndef HAVE_SPAWNLP
|
1998-08-09 08:43:13 +08:00
|
|
|
sleep(2);
|
1998-11-13 07:19:16 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1998-11-13 07:19:16 +08:00
|
|
|
#ifdef HAVE_SPAWNLP
|
|
|
|
rc = _spawnlp( _P_WAIT, editor, editor, entry_temp_file, NULL );
|
|
|
|
if(rc != 0) {
|
|
|
|
fatal("spawnlp");
|
|
|
|
}
|
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
if ((pid = fork()) == 0) {
|
|
|
|
/* child - edit the Directory entry */
|
1998-10-25 09:41:42 +08:00
|
|
|
(void) SIGNAL(SIGINT, SIG_IGN);
|
1998-08-09 08:43:13 +08:00
|
|
|
(void) execlp(editor, editor, entry_temp_file, NULL);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
(void) fatal(editor);
|
|
|
|
}
|
|
|
|
else if (pid > 0) {
|
|
|
|
/* parent - wait until the child proc is done editing */
|
1998-11-19 04:08:02 +08:00
|
|
|
void (*handler)();
|
1998-10-25 09:41:42 +08:00
|
|
|
handler = SIGNAL(SIGINT, SIG_IGN);
|
1998-08-09 08:43:13 +08:00
|
|
|
(void) wait(&status);
|
1998-10-25 09:41:42 +08:00
|
|
|
(void) SIGNAL(SIGINT, handler);
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
fatal("fork");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
1998-11-13 07:19:16 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int
|
|
|
|
print_attrs_and_values( FILE *fp, struct attribute *attrs, short int flag )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
register int i, j;
|
|
|
|
|
|
|
|
for (i = 0; attrs[i].quipu_name != NULL; i++) {
|
1998-11-19 04:08:02 +08:00
|
|
|
if (!modifiable(attrs[i].quipu_name,
|
|
|
|
(short) (flag|ATTR_FLAG_MAY_EDIT)))
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
continue;
|
1998-11-19 04:08:02 +08:00
|
|
|
}
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
fprintf(fp, "%s\n", attrs[i].quipu_name);
|
|
|
|
if ( attrs[i].number_of_values > MAX_VALUES ) {
|
|
|
|
printf(" The %s attribute has more than %d values.\n",
|
|
|
|
attrs[i].quipu_name, MAX_VALUES );
|
|
|
|
printf(" You cannot use the vedit command on this entry. Sorry!\n" );
|
|
|
|
return( -1 );
|
|
|
|
}
|
|
|
|
for (j = 0; j < attrs[i].number_of_values; j++)
|
|
|
|
fprintf(fp, "\t%s\n", attrs[i].values[j]);
|
|
|
|
}
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int
|
|
|
|
modifiable( char *s, short int flag )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
register int i;
|
|
|
|
|
|
|
|
for (i = 0; attrlist[i].quipu_name != NULL; i++) {
|
|
|
|
if (strcasecmp(s, attrlist[i].quipu_name))
|
|
|
|
continue;
|
|
|
|
if ((attrlist[i].flags & flag) == ATTR_FLAG_NONE)
|
|
|
|
return(FALSE);
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
/* should never be here */
|
|
|
|
return(FALSE);
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static void
|
|
|
|
write_entry( void )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
int i = 0, j, number_of_values = -1;
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
char *cp, line[LARGE_BUF_SIZE], *values[MAX_VALUES], **vp;
|
|
|
|
|
|
|
|
LDAPMod *mods[MAX_ATTRS + 1];
|
|
|
|
LDAPMod *modp = NULL;
|
|
|
|
|
|
|
|
/* parse the file and write the values to the Directory */
|
|
|
|
if ((fp = fopen(entry_temp_file, "r")) == NULL) {
|
|
|
|
perror("fopen");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (;;) {
|
|
|
|
(void) fgets(line, sizeof(line), fp);
|
|
|
|
if (feof(fp))
|
|
|
|
break;
|
|
|
|
line[strlen(line) - 1] = '\0'; /* kill newline */
|
|
|
|
cp = line;
|
|
|
|
if (*cp == '#')
|
|
|
|
continue;
|
|
|
|
if (isspace(*cp)) { /* value */
|
|
|
|
while (isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
values[number_of_values++] = strdup(cp);
|
|
|
|
if ( number_of_values >= MAX_VALUES ) {
|
|
|
|
printf(" A maximum of %d values can be handled at one time. Sorry!\n", MAX_VALUES );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* attribute */
|
|
|
|
while (isspace(*cp))
|
|
|
|
cp++;
|
|
|
|
/*
|
|
|
|
* If the number of values is greater than zero, then we
|
|
|
|
* know that this is not the first time through this
|
|
|
|
* loop, and we also know that we have a little bit
|
|
|
|
* of work to do:
|
|
|
|
*
|
|
|
|
* o The modify operation needs to be changed from
|
|
|
|
* a DELETE to a REPLACE
|
|
|
|
*
|
|
|
|
* o The list of values pointer needs to be changed
|
|
|
|
* from NULL, to a NULL-terminated list of char
|
|
|
|
* pointers.
|
|
|
|
*/
|
|
|
|
if (number_of_values > 0) {
|
|
|
|
modp->mod_op = LDAP_MOD_REPLACE;
|
|
|
|
if ((vp = (char **) Malloc(sizeof(char *) * (number_of_values + 2))) == (char **) NULL) {
|
|
|
|
fatal("Malloc");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
modp->mod_values = vp;
|
|
|
|
for (j = 0; j < number_of_values; j++) {
|
|
|
|
*vp++ = strdup(values[j]);
|
|
|
|
(void) Free(values[j]);
|
|
|
|
}
|
|
|
|
*vp = NULL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If there are no values, and there were no values to begin
|
|
|
|
* with, then there is nothing to do.
|
|
|
|
*/
|
|
|
|
if ((number_of_values == 0) && (ovalues(modp->mod_type) == 0)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug & D_MODIFY)
|
|
|
|
printf(" %s has zero values - skipping\n",
|
|
|
|
modp->mod_type);
|
|
|
|
#endif
|
|
|
|
(void) Free(modp->mod_type);
|
|
|
|
modp->mod_type = strdup(cp);
|
|
|
|
modp->mod_op = LDAP_MOD_DELETE;
|
|
|
|
modp->mod_values = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Fetch a new modify structure.
|
|
|
|
*
|
|
|
|
* Assume a DELETE operation with no values.
|
|
|
|
*/
|
|
|
|
if ((modp = (LDAPMod *) Malloc(sizeof(LDAPMod))) == NULL) {
|
|
|
|
fatal("Malloc");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
modp->mod_values = NULL;
|
|
|
|
modp->mod_type = strdup(cp);
|
|
|
|
modp->mod_op = LDAP_MOD_DELETE;
|
|
|
|
mods[i++] = modp;
|
|
|
|
number_of_values = 0;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/* check the last one too */
|
|
|
|
if (number_of_values > 0) {
|
|
|
|
modp->mod_op = LDAP_MOD_REPLACE;
|
|
|
|
/*
|
|
|
|
* Fetch some value pointers.
|
|
|
|
*
|
|
|
|
* number_of_values To store the values
|
|
|
|
* 1 For the NULL terminator
|
|
|
|
* 1 In case we need it to store
|
|
|
|
* the RDN as on of the values
|
|
|
|
* of 'cn' in case it isn't there
|
|
|
|
*/
|
|
|
|
if ((vp = (char **) Malloc(sizeof(char *) * (number_of_values +
|
|
|
|
2))) == (char **) NULL) {
|
|
|
|
fatal("Malloc");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
modp->mod_values = vp;
|
|
|
|
for (j = 0; j < number_of_values; j++) {
|
|
|
|
*vp++ = strdup(values[j]);
|
|
|
|
(void) Free(values[j]);
|
|
|
|
}
|
|
|
|
*vp = NULL;
|
|
|
|
}
|
|
|
|
else if ((number_of_values == 0) &&
|
|
|
|
(ovalues(mods[i - 1]->mod_type) == 0)) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug & D_MODIFY)
|
|
|
|
printf(" %s has zero values - skipping\n",
|
|
|
|
mods[i - 1]->mod_type);
|
|
|
|
#endif
|
|
|
|
Free(mods[i - 1]->mod_type);
|
|
|
|
Free(mods[i - 1]);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
mods[i] = (LDAPMod *) NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If one of the mods pointers is 'cn', be sure that the RDN is one
|
|
|
|
* of the values.
|
|
|
|
*/
|
|
|
|
for (j = 0; j < i; j++) {
|
|
|
|
if (strcasecmp("cn", mods[j]->mod_type))
|
|
|
|
continue;
|
|
|
|
/*
|
|
|
|
* True only if there WERE values, but the person deleted
|
|
|
|
* them all.
|
|
|
|
*/
|
|
|
|
if (mods[j]->mod_values == NULL) {
|
|
|
|
mods[j]->mod_op = LDAP_MOD_REPLACE;
|
|
|
|
if ((vp = (char **) Malloc(sizeof(char *) * 2)) == (char **) NULL) {
|
|
|
|
fatal("Malloc");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
mods[j]->mod_values = vp;
|
|
|
|
*vp++ = strdup(Entry.name);
|
|
|
|
*vp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Be sure that one of the values of 'cn' is the RDN.
|
|
|
|
*/
|
|
|
|
for (vp = mods[j]->mod_values; *vp != NULL; vp++) {
|
|
|
|
if (strcasecmp(*vp, Entry.DN))
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*vp == NULL) {
|
|
|
|
*vp++ = strdup(Entry.name);
|
|
|
|
*vp = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (debug & D_MODIFY) {
|
|
|
|
register int x, y;
|
|
|
|
|
|
|
|
printf(" ld = 0x%x\n", ld);
|
|
|
|
printf(" dn = [%s]\n", Entry.DN);
|
|
|
|
for (x = 0; mods[x] != (LDAPMod *) NULL; x++) {
|
|
|
|
printf(" mods[%d]->mod_op = %s\n",
|
|
|
|
x, code_to_str(mods[x]->mod_op));
|
|
|
|
printf(" mods[%d]->mod_type = %s\n",
|
|
|
|
x, mods[x]->mod_type);
|
|
|
|
if (mods[x]->mod_values == NULL)
|
|
|
|
printf(" mods[%d]->mod_values = NULL\n", x);
|
|
|
|
else {
|
|
|
|
for (y = 0; mods[x]->mod_values[y] != NULL; y++)
|
|
|
|
printf(" mods[%d]->mod_values[%1d] = %s\n",
|
|
|
|
x, y, mods[x]->mod_values[y]);
|
|
|
|
printf(" mods[%d]->mod_values[%1d] = NULL\n",
|
|
|
|
x, y);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (ldap_modify_s(ld, Entry.DN, mods))
|
|
|
|
mod_perror(ld);
|
|
|
|
else
|
|
|
|
printf(" Modification complete.\n" );
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
for (i = 0; mods[i] != NULL; i++)
|
|
|
|
free_mod_struct(mods[i]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
static int
|
|
|
|
ovalues( char *attr )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
struct attribute *ap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Lookup the attribute with quipu_name 'attr' in the Entry
|
|
|
|
* structure and return the number of values.
|
|
|
|
*/
|
|
|
|
for (ap = Entry.attrs; ap->quipu_name != NULL; ap++) {
|
|
|
|
if (!strcasecmp(ap->quipu_name, attr))
|
|
|
|
return(ap->number_of_values);
|
|
|
|
}
|
|
|
|
/* should never get to this point unless 'attr' was something odd */
|
|
|
|
return(0);
|
|
|
|
}
|