1998-08-09 08:43:13 +08: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-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.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 void add_created_attrs(Operation *op, Entry *e);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
void
|
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
|
|
|
do_add( Connection *conn, Operation *op )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
BerElement *ber = op->o_ber;
|
|
|
|
char *dn, *last;
|
|
|
|
unsigned long len, tag;
|
|
|
|
Entry *e;
|
|
|
|
Backend *be;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "do_add\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
|
|
|
if ( ber_scanf( ber, "{a", &dn ) == LBER_ERROR ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
|
|
|
|
"decoding error" );
|
|
|
|
return;
|
|
|
|
}
|
1998-12-04 10:20:39 +08:00
|
|
|
|
|
|
|
e = (Entry *) ch_calloc( 1, sizeof(Entry) );
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
e->e_dn = dn;
|
1999-01-20 02:17:29 +08:00
|
|
|
e->e_ndn = dn_normalize_case( ch_strdup( dn ) );
|
1999-02-11 02:28:25 +08:00
|
|
|
e->e_private = NULL;
|
|
|
|
|
1999-01-13 09:17:22 +08:00
|
|
|
dn = NULL;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_ARGS, " do_add: ndn (%s)\n", e->e_ndn, 0, 0 );
|
1998-08-09 08:43:13 +08: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 ) {
|
|
|
|
send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR,
|
|
|
|
NULL, "decoding error" );
|
|
|
|
entry_free( e );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( vals == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_ANY, "no values for type %s\n", type,
|
|
|
|
0, 0 );
|
|
|
|
send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
|
|
|
|
NULL );
|
1998-12-27 11:55:57 +08:00
|
|
|
free( type );
|
1998-08-09 08:43:13 +08:00
|
|
|
entry_free( e );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
attr_merge( e, type, vals );
|
|
|
|
|
|
|
|
free( type );
|
|
|
|
ber_bvecfree( vals );
|
|
|
|
}
|
|
|
|
|
|
|
|
Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d ADD dn=\"%s\"\n",
|
1999-01-13 09:17:22 +08:00
|
|
|
conn->c_connid, op->o_opid, e->e_ndn, 0, 0 );
|
1998-08-09 08:43:13 +08: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-13 09:17:22 +08:00
|
|
|
be = select_backend( e->e_ndn );
|
1998-12-27 11:55:57 +08:00
|
|
|
if ( be == NULL ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
entry_free( e );
|
|
|
|
send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
|
|
|
|
default_referral );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
if ( be->be_add != NULL ) {
|
|
|
|
/* do the update here */
|
1999-01-19 13:10:50 +08:00
|
|
|
if ( be->be_update_ndn == NULL ||
|
|
|
|
strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
|
|
|
|
{
|
1998-08-19 09:30:57 +08:00
|
|
|
if ( (be->be_lastmod == ON || (be->be_lastmod == UNDEFINED &&
|
1999-01-19 13:10:50 +08:00
|
|
|
global_lastmod == ON)) && be->be_update_ndn == NULL ) {
|
1998-08-19 09:30:57 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
add_created_attrs( op, e );
|
|
|
|
}
|
|
|
|
if ( (*be->be_add)( be, conn, op, e ) == 0 ) {
|
|
|
|
replog( be, LDAP_REQ_ADD, e->e_dn, e, 0 );
|
|
|
|
}
|
1998-08-19 09:30:57 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
} else {
|
|
|
|
entry_free( e );
|
|
|
|
send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
|
|
|
|
default_referral );
|
|
|
|
}
|
|
|
|
} else {
|
1998-08-19 09:30:57 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS, " do_add: HHH\n", 0, 0, 0 );
|
1998-08-09 08:43:13 +08:00
|
|
|
entry_free( e );
|
|
|
|
send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
|
|
|
|
"Function not implemented" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_created_attrs( Operation *op, Entry *e )
|
|
|
|
{
|
1998-09-16 16:33:34 +08:00
|
|
|
char buf[22];
|
1998-08-09 08:43:13 +08:00
|
|
|
struct berval bv;
|
|
|
|
struct berval *bvals[2];
|
|
|
|
Attribute **a, **next;
|
|
|
|
Attribute *tmp;
|
|
|
|
struct tm *ltm;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "add_created_attrs\n", 0, 0, 0 );
|
|
|
|
|
|
|
|
bvals[0] = &bv;
|
|
|
|
bvals[1] = NULL;
|
|
|
|
|
|
|
|
/* remove any attempts by the user to add these attrs */
|
|
|
|
for ( a = &e->e_attrs; *a != NULL; a = next ) {
|
1998-08-19 09:30:57 +08:00
|
|
|
if ( strcasecmp( (*a)->a_type, "modifiersname" ) == 0 ||
|
|
|
|
strcasecmp( (*a)->a_type, "modifytimestamp" ) == 0 ||
|
|
|
|
strcasecmp( (*a)->a_type, "creatorsname" ) == 0 ||
|
|
|
|
strcasecmp( (*a)->a_type, "createtimestamp" ) == 0 ) {
|
1998-08-09 08:43:13 +08:00
|
|
|
tmp = *a;
|
|
|
|
*a = (*a)->a_next;
|
|
|
|
attr_free( tmp );
|
|
|
|
next = a;
|
|
|
|
} else {
|
|
|
|
next = &(*a)->a_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( op->o_dn == NULL || op->o_dn[0] == '\0' ) {
|
|
|
|
bv.bv_val = "NULLDN";
|
|
|
|
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-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
|
1998-10-22 03:35:30 +08:00
|
|
|
#ifndef LDAP_LOCALTIME
|
1998-10-22 03:26:49 +08:00
|
|
|
ltm = gmtime( ¤ttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%Y%m%d%H%M%SZ", ltm );
|
|
|
|
#else
|
1998-10-22 03:26:49 +08:00
|
|
|
ltm = localtime( ¤ttime );
|
1998-09-16 16:33:34 +08:00
|
|
|
strftime( buf, sizeof(buf), "%y%m%d%H%M%SZ", ltm );
|
|
|
|
#endif
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
bv.bv_val = buf;
|
|
|
|
bv.bv_len = strlen( bv.bv_val );
|
|
|
|
attr_merge( e, "createtimestamp", bvals );
|
|
|
|
}
|