1999-09-08 15:06:24 -04:00
|
|
|
/* $OpenLDAP$ */
|
1999-08-06 19:07:46 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
|
|
|
|
|
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
|
|
|
|
|
*/
|
1998-08-08 20:43:13 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 1995 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-24 21:41:42 -04:00
|
|
|
#include "portable.h"
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
#include <stdio.h>
|
1998-10-24 21:41:42 -04:00
|
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
|
#include <ac/time.h>
|
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
|
1999-10-28 03:13:33 -04:00
|
|
|
#include "ldap_pvt.h"
|
1998-08-08 20:43:13 -04:00
|
|
|
#include "slap.h"
|
|
|
|
|
|
1999-07-27 16:00:31 -04:00
|
|
|
static int add_created_attrs(Operation *op, Entry *e);
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-07-01 17:20:45 -04:00
|
|
|
int
|
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-15 17:40:11 -05:00
|
|
|
do_add( Connection *conn, Operation *op )
|
1998-08-08 20:43:13 -04:00
|
|
|
{
|
|
|
|
|
BerElement *ber = op->o_ber;
|
1999-07-22 13:14:42 -04:00
|
|
|
char *dn, *ndn, *last;
|
1999-06-18 19:53:05 -04:00
|
|
|
ber_len_t len;
|
|
|
|
|
ber_tag_t tag;
|
1998-08-08 20:43:13 -04:00
|
|
|
Entry *e;
|
|
|
|
|
Backend *be;
|
1999-07-01 17:20:45 -04:00
|
|
|
int rc = LDAP_SUCCESS;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
|
|
|
|
|
|
1999-07-01 20:46:28 -04:00
|
|
|
if( op->o_bind_in_progress ) {
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: SASL bind in progress.\n", 0, 0, 0 );
|
|
|
|
|
send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS, NULL,
|
1999-07-15 22:45:46 -04:00
|
|
|
"SASL bind in progress", NULL, NULL );
|
1999-07-01 20:46:28 -04:00
|
|
|
return LDAP_SASL_BIND_IN_PROGRESS;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
/*
|
|
|
|
|
* Parse the add request. It looks like this:
|
|
|
|
|
*
|
|
|
|
|
* AddRequest := [APPLICATION 14] SEQUENCE {
|
|
|
|
|
* name DistinguishedName,
|
|
|
|
|
* attrs SEQUENCE OF SEQUENCE {
|
|
|
|
|
* type AttributeType,
|
|
|
|
|
* values SET OF AttributeValue
|
|
|
|
|
* }
|
|
|
|
|
* }
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* get the name */
|
1999-06-18 19:53:05 -04:00
|
|
|
if ( ber_scanf( ber, "{a", /*}*/ &dn ) == LBER_ERROR ) {
|
1999-06-30 18:43:27 -04:00
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
|
1999-07-07 14:51:39 -04:00
|
|
|
send_ldap_disconnect( conn, op,
|
|
|
|
|
LDAP_PROTOCOL_ERROR, "decoding error" );
|
|
|
|
|
return -1;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1998-12-03 21:20:39 -05:00
|
|
|
|
1999-09-18 21:04:38 -04:00
|
|
|
ndn = ch_strdup( dn );
|
|
|
|
|
|
1999-09-23 21:46:37 -04:00
|
|
|
if ( dn_normalize( ndn ) == NULL ) {
|
1999-07-22 13:14:42 -04:00
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: invalid dn (%s)\n", dn, 0, 0 );
|
|
|
|
|
send_ldap_result( conn, op, LDAP_INVALID_DN_SYNTAX, NULL,
|
|
|
|
|
"invalid DN", NULL, NULL );
|
|
|
|
|
free( dn );
|
1999-09-18 21:04:38 -04:00
|
|
|
free( ndn );
|
1999-07-22 13:14:42 -04:00
|
|
|
return LDAP_INVALID_DN_SYNTAX;
|
|
|
|
|
}
|
|
|
|
|
|
1998-12-03 21:20:39 -05:00
|
|
|
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
e->e_dn = dn;
|
1999-07-22 13:14:42 -04:00
|
|
|
e->e_ndn = ndn;
|
1999-02-10 13:28:25 -05:00
|
|
|
e->e_private = NULL;
|
|
|
|
|
|
1999-01-12 20:17:22 -05:00
|
|
|
Debug( LDAP_DEBUG_ARGS, " do_add: ndn (%s)\n", e->e_ndn, 0, 0 );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
/* get the attrs */
|
|
|
|
|
e->e_attrs = NULL;
|
|
|
|
|
for ( tag = ber_first_element( ber, &len, &last ); tag != LBER_DEFAULT;
|
|
|
|
|
tag = ber_next_element( ber, &len, last ) ) {
|
|
|
|
|
char *type;
|
|
|
|
|
struct berval **vals;
|
|
|
|
|
|
|
|
|
|
if ( ber_scanf( ber, "{a{V}}", &type, &vals ) == LBER_ERROR ) {
|
1999-07-07 14:51:39 -04:00
|
|
|
send_ldap_disconnect( conn, op,
|
|
|
|
|
LDAP_PROTOCOL_ERROR, "decoding error" );
|
1998-08-08 20:43:13 -04:00
|
|
|
entry_free( e );
|
1999-07-07 14:51:39 -04:00
|
|
|
return -1;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( vals == NULL ) {
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "no values for type %s\n", type,
|
|
|
|
|
0, 0 );
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
|
|
|
|
|
NULL, "no values for type", NULL, NULL );
|
1998-12-26 22:55:57 -05:00
|
|
|
free( type );
|
1998-08-08 20:43:13 -04:00
|
|
|
entry_free( e );
|
1999-07-01 17:20:45 -04:00
|
|
|
return LDAP_PROTOCOL_ERROR;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attr_merge( e, type, vals );
|
|
|
|
|
|
|
|
|
|
free( type );
|
|
|
|
|
ber_bvecfree( vals );
|
|
|
|
|
}
|
|
|
|
|
|
1999-06-30 18:43:27 -04:00
|
|
|
if ( ber_scanf( ber, /*{*/ "}") == LBER_ERROR ) {
|
|
|
|
|
entry_free( e );
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: ber_scanf failed\n", 0, 0, 0 );
|
1999-07-07 14:51:39 -04:00
|
|
|
send_ldap_disconnect( conn, op,
|
|
|
|
|
LDAP_PROTOCOL_ERROR, "decoding error" );
|
|
|
|
|
return -1;
|
1999-06-30 18:43:27 -04:00
|
|
|
}
|
|
|
|
|
|
1999-07-01 17:20:45 -04:00
|
|
|
if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
|
1999-06-30 18:43:27 -04:00
|
|
|
entry_free( e );
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: get_ctrls failed\n", 0, 0, 0 );
|
1999-07-01 17:20:45 -04:00
|
|
|
return rc;
|
1999-06-30 18:43:27 -04:00
|
|
|
}
|
|
|
|
|
|
1999-08-07 01:36:48 -04:00
|
|
|
Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d ADD dn=\"%s\"\n",
|
1999-07-16 18:24:32 -04:00
|
|
|
op->o_connid, op->o_opid, e->e_ndn, 0, 0 );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We could be serving multiple database backends. Select the
|
|
|
|
|
* appropriate one, or send a referral to our "referral server"
|
|
|
|
|
* if we don't hold it.
|
|
|
|
|
*/
|
1999-01-12 20:17:22 -05:00
|
|
|
be = select_backend( e->e_ndn );
|
1998-12-26 22:55:57 -05:00
|
|
|
if ( be == NULL ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
entry_free( e );
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, LDAP_REFERRAL, NULL,
|
|
|
|
|
NULL, default_referral, NULL );
|
1999-07-01 17:20:45 -04:00
|
|
|
return rc;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
1999-12-07 23:37:59 -05:00
|
|
|
/* make sure this backend recongizes critical controls */
|
|
|
|
|
rc = backend_check_controls( be, conn, op ) ;
|
|
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
|
send_ldap_result( conn, op, rc,
|
|
|
|
|
NULL, NULL, NULL, NULL );
|
2000-01-31 20:22:06 -05:00
|
|
|
entry_free( e );
|
|
|
|
|
return rc;
|
1999-12-07 23:37:59 -05:00
|
|
|
}
|
|
|
|
|
|
1999-09-02 06:39:51 -04:00
|
|
|
if ( global_readonly || be->be_readonly ) {
|
|
|
|
|
Debug( LDAP_DEBUG_ANY, "do_add: database is read-only\n",
|
|
|
|
|
0, 0, 0 );
|
|
|
|
|
entry_free( e );
|
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM,
|
|
|
|
|
NULL, "database is read-only", NULL, NULL );
|
|
|
|
|
return LDAP_UNWILLING_TO_PERFORM;
|
|
|
|
|
}
|
|
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
/*
|
|
|
|
|
* do the add if 1 && (2 || 3)
|
|
|
|
|
* 1) there is an add function implemented in this backend;
|
|
|
|
|
* 2) this backend is master for what it holds;
|
|
|
|
|
* 3) it's a replica and the dn supplied is the updatedn.
|
|
|
|
|
*/
|
1999-03-03 13:49:59 -05:00
|
|
|
if ( be->be_add ) {
|
1998-08-08 20:43:13 -04:00
|
|
|
/* do the update here */
|
1999-08-03 18:15:19 -04:00
|
|
|
#ifdef SLAPD_MULTIMASTER
|
|
|
|
|
if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
|
|
|
|
|
global_lastmod == ON)) && (be->be_update_ndn == NULL ||
|
|
|
|
|
strcmp( be->be_update_ndn, op->o_ndn )) )
|
|
|
|
|
#else
|
1999-01-19 00:10:50 -05:00
|
|
|
if ( be->be_update_ndn == NULL ||
|
|
|
|
|
strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
|
1999-08-03 18:15:19 -04:00
|
|
|
#endif
|
1999-01-19 00:10:50 -05:00
|
|
|
{
|
1999-08-03 18:15:19 -04:00
|
|
|
#ifndef SLAPD_MULTIMASTER
|
1998-08-18 21:30:57 -04:00
|
|
|
if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
|
1999-07-27 16:00:31 -04:00
|
|
|
global_lastmod == ON)) && be->be_update_ndn == NULL )
|
1999-08-03 18:15:19 -04:00
|
|
|
#endif
|
1999-07-27 16:00:31 -04:00
|
|
|
{
|
|
|
|
|
rc = add_created_attrs( op, e );
|
|
|
|
|
|
|
|
|
|
if( rc != LDAP_SUCCESS ) {
|
|
|
|
|
entry_free( e );
|
|
|
|
|
send_ldap_result( conn, op, rc,
|
|
|
|
|
NULL, "no-user-modification attribute type",
|
|
|
|
|
NULL, NULL );
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1999-07-27 16:00:31 -04:00
|
|
|
|
1998-08-08 20:43:13 -04:00
|
|
|
if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
|
1999-08-03 18:15:19 -04:00
|
|
|
#ifdef SLAPD_MULTIMASTER
|
|
|
|
|
if (be->be_update_ndn == NULL ||
|
|
|
|
|
strcmp( be->be_update_ndn, op->o_ndn ))
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
replog( be, op, e->e_dn, e );
|
|
|
|
|
}
|
1999-04-13 02:08:28 -04:00
|
|
|
be_entry_release_w( be, e );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1998-08-18 21:30:57 -04:00
|
|
|
|
1999-08-03 18:15:19 -04:00
|
|
|
#ifndef SLAPD_MULTIMASTER
|
1998-08-08 20:43:13 -04:00
|
|
|
} else {
|
|
|
|
|
entry_free( e );
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
|
|
|
|
|
be->be_update_refs ? be->be_update_refs : default_referral, NULL );
|
1999-08-03 18:15:19 -04:00
|
|
|
#endif
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
} else {
|
1998-08-18 21:30:57 -04:00
|
|
|
Debug( LDAP_DEBUG_ARGS, " do_add: HHH\n", 0, 0, 0 );
|
1998-08-08 20:43:13 -04:00
|
|
|
entry_free( e );
|
1999-07-15 22:45:46 -04:00
|
|
|
send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
|
|
|
|
|
NULL, "Function not implemented", NULL, NULL );
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
1999-07-01 17:20:45 -04:00
|
|
|
|
|
|
|
|
return rc;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
1999-07-27 16:00:31 -04:00
|
|
|
static int
|
1998-08-08 20:43:13 -04:00
|
|
|
add_created_attrs( Operation *op, Entry *e )
|
|
|
|
|
{
|
1998-09-16 04:33:34 -04:00
|
|
|
char buf[22];
|
1998-08-08 20:43:13 -04:00
|
|
|
struct berval bv;
|
|
|
|
|
struct berval *bvals[2];
|
1999-07-27 16:00:31 -04:00
|
|
|
Attribute *a;
|
1998-08-08 20:43:13 -04:00
|
|
|
struct tm *ltm;
|
1999-03-22 02:14:54 -05:00
|
|
|
time_t currenttime;
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "add_created_attrs\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
|
|
bvals[0] = &bv;
|
|
|
|
|
bvals[1] = NULL;
|
|
|
|
|
|
1999-07-27 16:00:31 -04:00
|
|
|
/* return error on any attempts by the user to add these attrs */
|
|
|
|
|
for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
|
2000-01-27 14:02:24 -05:00
|
|
|
if ( oc_check_op_no_usermod_attr( a->a_type ) ) {
|
1999-07-27 16:00:31 -04:00
|
|
|
return LDAP_CONSTRAINT_VIOLATION;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
|
1999-07-07 14:51:39 -04:00
|
|
|
bv.bv_val = "<anonymous>";
|
1998-08-08 20:43:13 -04:00
|
|
|
bv.bv_len = strlen( bv.bv_val );
|
|
|
|
|
} else {
|
|
|
|
|
bv.bv_val = op->o_dn;
|
|
|
|
|
bv.bv_len = strlen( bv.bv_val );
|
|
|
|
|
}
|
|
|
|
|
attr_merge( e, "creatorsname", bvals );
|
1999-11-01 12:19:01 -05:00
|
|
|
attr_merge( e, "modifiersname", bvals );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
1999-03-22 02:14:54 -05:00
|
|
|
currenttime = slap_get_time();
|
|
|
|
|
ldap_pvt_thread_mutex_lock( &gmtime_mutex );
|
1998-10-21 15:26:49 -04:00
|
|
|
ltm = gmtime( ¤ttime );
|
1998-09-16 04:33:34 -04:00
|
|
|
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
|
1999-03-22 02:14:54 -05:00
|
|
|
ldap_pvt_thread_mutex_unlock( &gmtime_mutex );
|
1998-08-08 20:43:13 -04:00
|
|
|
|
|
|
|
|
bv.bv_val = buf;
|
|
|
|
|
bv.bv_len = strlen( bv.bv_val );
|
|
|
|
|
attr_merge( e, "createtimestamp", bvals );
|
1999-11-01 12:19:01 -05:00
|
|
|
attr_merge( e, "modifytimestamp", bvals );
|
1999-07-27 16:00:31 -04:00
|
|
|
|
|
|
|
|
return LDAP_SUCCESS;
|
1998-08-08 20:43:13 -04:00
|
|
|
}
|