* Was: slapi_utils.h
*/
-int slapi_log_error( int severity, char *subsystem, char *fmt, ... );
-Slapi_Entry *slapi_str2entry( char *s, int flags );
-char *slapi_entry2str( Slapi_Entry *e, int *len );
-int slapi_entry_attr_merge( Slapi_Entry *e, char *type, struct berval **vals );
-int slapi_entry_attr_find( Slapi_Entry *e, char *type, Slapi_Attr **attr );
-char *slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type );
-int slapi_entry_attr_delete( Slapi_Entry *e, char *type );
-int slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type );
-int slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type );
-int slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type );
-int slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type );
-int slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value );
-int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-void slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value);
-void slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l);
-void slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l);
-void slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l);
-void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
-int slapi_is_rootdse( const char *dn );
-int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-int slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-int slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs);
-int slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-int slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-int slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
-int slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value);
-int slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value);
-int slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value);
-int slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr );
-int slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr );
-char *slapi_entry_get_dn( Slapi_Entry *e );
-int slapi_x_entry_get_id( Slapi_Entry *e );
-void slapi_entry_set_dn( Slapi_Entry *e, char *dn );
-Slapi_Entry *slapi_entry_dup( Slapi_Entry *e );
-Slapi_Entry *slapi_entry_alloc();
-void slapi_entry_free( Slapi_Entry *e );
-int slapi_attr_get_values( Slapi_Attr *attr, struct berval ***vals );
+extern int slapi_log_error( int severity, char *subsystem, char *fmt, ... );
+extern Slapi_Entry *slapi_str2entry( char *s, int flags );
+extern char *slapi_entry2str( Slapi_Entry *e, int *len );
+extern int slapi_entry_attr_merge( Slapi_Entry *e, char *type, struct berval **vals );
+extern int slapi_entry_attr_find( Slapi_Entry *e, char *type, Slapi_Attr **attr );
+extern char *slapi_entry_attr_get_charptr( const Slapi_Entry *e, const char *type );
+extern int slapi_entry_attr_delete( Slapi_Entry *e, char *type );
+extern int slapi_entry_attr_get_int( const Slapi_Entry *e, const char *type );
+extern int slapi_entry_attr_get_long( const Slapi_Entry *e, const char *type );
+extern int slapi_entry_attr_get_uint( const Slapi_Entry *e, const char *type );
+extern int slapi_entry_attr_get_ulong( const Slapi_Entry *e, const char *type );
+extern int slapi_entry_attr_hasvalue( Slapi_Entry *e, const char *type, const char *value );
+extern int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern void slapi_entry_attr_set_charptr(Slapi_Entry* e, const char *type, const char *value);
+extern void slapi_entry_attr_set_int( Slapi_Entry* e, const char *type, int l);
+extern void slapi_entry_attr_set_uint( Slapi_Entry* e, const char *type, unsigned int l);
+extern void slapi_entry_attr_set_long(Slapi_Entry* e, const char *type, long l);
+extern void slapi_entry_attr_set_ulong(Slapi_Entry* e, const char *type, unsigned long l);
+extern int slapi_is_rootdse( const char *dn );
+extern int slapi_entry_attr_merge_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern int slapi_entry_add_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern int slapi_entry_add_valueset(Slapi_Entry *e, const char *type, Slapi_ValueSet *vs);
+extern int slapi_entry_delete_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern int slapi_entry_merge_values_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern int slapi_entry_attr_replace_sv( Slapi_Entry *e, const char *type, Slapi_Value **vals );
+extern int slapi_entry_add_value(Slapi_Entry *e, const char *type, const Slapi_Value *value);
+extern int slapi_entry_add_string(Slapi_Entry *e, const char *type, const char *value);
+extern int slapi_entry_delete_string(Slapi_Entry *e, const char *type, const char *value);
+extern int slapi_entry_first_attr( const Slapi_Entry *e, Slapi_Attr **attr );
+extern int slapi_entry_next_attr( const Slapi_Entry *e, Slapi_Attr *prevattr, Slapi_Attr **attr );
+extern char *slapi_entry_get_dn( Slapi_Entry *e );
+extern int slapi_x_entry_get_id( Slapi_Entry *e );
+extern void slapi_entry_set_dn( Slapi_Entry *e, char *dn );
+extern Slapi_Entry *slapi_entry_dup( Slapi_Entry *e );
+extern Slapi_Entry *slapi_entry_alloc();
+extern void slapi_entry_free( Slapi_Entry *e );
+extern int slapi_attr_get_values( Slapi_Attr *attr, struct berval ***vals );
/* DS 5.x SLAPI */
-int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
+extern int slapi_access_allowed( Slapi_PBlock *pb, Slapi_Entry *e, char *attr,
struct berval *val, int access );
-int slapi_acl_check_mods( Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods,
+extern int slapi_acl_check_mods( Slapi_PBlock *pb, Slapi_Entry *e, LDAPMod **mods,
char **errbuf );
-Slapi_Attr *slapi_attr_new( void );
-Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type );
-void slapi_attr_free( Slapi_Attr **a );
-Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr );
-int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v );
-int slapi_attr_type2plugin( const char *type, void **pi );
-int slapi_attr_get_type( const Slapi_Attr *attr, char **type );
-int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp );
-int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags );
-int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag );
-int slapi_attr_value_cmp( const Slapi_Attr *attr, const struct berval *v1,
+extern Slapi_Attr *slapi_attr_new( void );
+extern Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type );
+extern void slapi_attr_free( Slapi_Attr **a );
+extern Slapi_Attr *slapi_attr_dup( const Slapi_Attr *attr );
+extern int slapi_attr_add_value( Slapi_Attr *a, const Slapi_Value *v );
+extern int slapi_attr_type2plugin( const char *type, void **pi );
+extern int slapi_attr_get_type( const Slapi_Attr *attr, char **type );
+extern int slapi_attr_get_oid_copy( const Slapi_Attr *attr, char **oidp );
+extern int slapi_attr_get_flags( const Slapi_Attr *attr, unsigned long *flags );
+extern int slapi_attr_flag_is_set( const Slapi_Attr *attr, unsigned long flag );
+extern int slapi_attr_value_cmp( const Slapi_Attr *attr, const struct berval *v1,
const struct berval *v2 );
-int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v );
+extern int slapi_attr_value_find( const Slapi_Attr *a, struct berval *v );
#if 0
#define SLAPI_TYPE_CMP_EXACT 0
#define SLAPI_TYPE_CMP_BASE 1
#define SLAPI_TYPE_CMP_SUBTYPE 2
#endif
-int slapi_attr_type_cmp( const char *t1, const char *t2, int opt );
-int slapi_attr_types_equivalent( const char *t1, const char *t2 );
-int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v );
-int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v );
-int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues );
-int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs );
-int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals );
-char *slapi_attr_syntax_normalize( const char *s );
+extern int slapi_attr_type_cmp( const char *t1, const char *t2, int opt );
+extern int slapi_attr_types_equivalent( const char *t1, const char *t2 );
+extern int slapi_attr_first_value( Slapi_Attr *a, Slapi_Value **v );
+extern int slapi_attr_next_value( Slapi_Attr *a, int hint, Slapi_Value **v );
+extern int slapi_attr_get_numvalues( const Slapi_Attr *a, int *numValues );
+extern int slapi_attr_get_valueset( const Slapi_Attr *a, Slapi_ValueSet **vs );
+extern int slapi_attr_get_bervals_copy( Slapi_Attr *a, struct berval ***vals );
+extern char *slapi_attr_syntax_normalize( const char *s );
-Slapi_Value *slapi_value_new( void );
-Slapi_Value *slapi_value_new_berval(const struct berval *bval);
-Slapi_Value *slapi_value_new_value(const Slapi_Value *v);
-Slapi_Value *slapi_value_new_string(const char *s);
-Slapi_Value *slapi_value_init(Slapi_Value *v);
-Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval);
-Slapi_Value *slapi_value_init_string(Slapi_Value *v,const char *s);
-Slapi_Value *slapi_value_dup(const Slapi_Value *v);
-void slapi_value_free(Slapi_Value **value);
-const struct berval *slapi_value_get_berval( const Slapi_Value *value );
-Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval );
-Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom);
-Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len);
-int slapi_value_set_string(Slapi_Value *value, const char *strVal);
-int slapi_value_set_int(Slapi_Value *value, int intVal);
-const char*slapi_value_get_string(const Slapi_Value *value);
-int slapi_value_get_int(const Slapi_Value *value);
-unsigned int slapi_value_get_uint(const Slapi_Value *value);
-long slapi_value_get_long(const Slapi_Value *value);
-unsigned long slapi_value_get_ulong(const Slapi_Value *value);
-size_t slapi_value_get_length(const Slapi_Value *value);
-int slapi_value_compare(const Slapi_Attr *a,const Slapi_Value *v1,const Slapi_Value *v2);
+extern Slapi_Value *slapi_value_new( void );
+extern Slapi_Value *slapi_value_new_berval(const struct berval *bval);
+extern Slapi_Value *slapi_value_new_value(const Slapi_Value *v);
+extern Slapi_Value *slapi_value_new_string(const char *s);
+extern Slapi_Value *slapi_value_init(Slapi_Value *v);
+extern Slapi_Value *slapi_value_init_berval(Slapi_Value *v, struct berval *bval);
+extern Slapi_Value *slapi_value_init_string(Slapi_Value *v,const char *s);
+extern Slapi_Value *slapi_value_dup(const Slapi_Value *v);
+extern void slapi_value_free(Slapi_Value **value);
+extern const struct berval *slapi_value_get_berval( const Slapi_Value *value );
+extern Slapi_Value *slapi_value_set_berval( Slapi_Value *value, const struct berval *bval );
+extern Slapi_Value *slapi_value_set_value( Slapi_Value *value, const Slapi_Value *vfrom);
+extern Slapi_Value *slapi_value_set( Slapi_Value *value, void *val, unsigned long len);
+extern int slapi_value_set_string(Slapi_Value *value, const char *strVal);
+extern int slapi_value_set_int(Slapi_Value *value, int intVal);
+extern const char*slapi_value_get_string(const Slapi_Value *value);
+extern int slapi_value_get_int(const Slapi_Value *value);
+extern unsigned int slapi_value_get_uint(const Slapi_Value *value);
+extern long slapi_value_get_long(const Slapi_Value *value);
+extern unsigned long slapi_value_get_ulong(const Slapi_Value *value);
+extern size_t slapi_value_get_length(const Slapi_Value *value);
+extern int slapi_value_compare(const Slapi_Attr *a,const Slapi_Value *v1,const Slapi_Value *v2);
-Slapi_ValueSet *slapi_valueset_new( void );
-void slapi_valueset_free(Slapi_ValueSet *vs);
-void slapi_valueset_init(Slapi_ValueSet *vs);
-void slapi_valueset_done(Slapi_ValueSet *vs);
-void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
-int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v );
-int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
-int slapi_valueset_count( const Slapi_ValueSet *vs);
-void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
+extern Slapi_ValueSet *slapi_valueset_new( void );
+extern void slapi_valueset_free(Slapi_ValueSet *vs);
+extern void slapi_valueset_init(Slapi_ValueSet *vs);
+extern void slapi_valueset_done(Slapi_ValueSet *vs);
+extern void slapi_valueset_add_value(Slapi_ValueSet *vs, const Slapi_Value *addval);
+extern int slapi_valueset_first_value( Slapi_ValueSet *vs, Slapi_Value **v );
+extern int slapi_valueset_next_value( Slapi_ValueSet *vs, int index, Slapi_Value **v);
+extern int slapi_valueset_count( const Slapi_ValueSet *vs);
+extern void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2);
-Slapi_Mutex *slapi_new_mutex( void );
-void slapi_destroy_mutex( Slapi_Mutex *mutex );
-void slapi_lock_mutex( Slapi_Mutex *mutex );
-int slapi_unlock_mutex( Slapi_Mutex *mutex );
-Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex );
-void slapi_destroy_condvar( Slapi_CondVar *cvar );
-int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout );
-int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all );
+extern Slapi_Mutex *slapi_new_mutex( void );
+extern void slapi_destroy_mutex( Slapi_Mutex *mutex );
+extern void slapi_lock_mutex( Slapi_Mutex *mutex );
+extern int slapi_unlock_mutex( Slapi_Mutex *mutex );
+extern Slapi_CondVar *slapi_new_condvar( Slapi_Mutex *mutex );
+extern void slapi_destroy_condvar( Slapi_CondVar *cvar );
+extern int slapi_wait_condvar( Slapi_CondVar *cvar, struct timeval *timeout );
+extern int slapi_notify_condvar( Slapi_CondVar *cvar, int notify_all );
-char *slapi_ch_malloc( unsigned long size );
-void slapi_ch_free( void **ptr );
-void slapi_ch_free_string( char **s );
-char *slapi_ch_calloc( unsigned long nelem, unsigned long size );
-char *slapi_ch_realloc( char *block, unsigned long size );
-char *slapi_ch_strdup( char *s );
-void slapi_ch_array_free( char **arrayp );
-struct berval *slapi_ch_bvdup(const struct berval *v);
-struct berval **slapi_ch_bvecdup(const struct berval **v);
+extern char *slapi_ch_malloc( unsigned long size );
+extern void slapi_ch_free( void **ptr );
+extern void slapi_ch_free_string( char **s );
+extern char *slapi_ch_calloc( unsigned long nelem, unsigned long size );
+extern char *slapi_ch_realloc( char *block, unsigned long size );
+extern char *slapi_ch_strdup( char *s );
+extern void slapi_ch_array_free( char **arrayp );
+extern struct berval *slapi_ch_bvdup(const struct berval *v);
+extern struct berval **slapi_ch_bvecdup(const struct berval **v);
/*
* FIXME: these two were missing, but widely used in a couple of .c files
*/
-size_t slapi_strlen(char *s );
+extern size_t slapi_strlen(char *s );
#define slapi_ch_stlen(s) slapi_strlen(s)
/*
* end of FIXME
*/
-char *slapi_dn_normalize( char *dn );
-char *slapi_dn_normalize_case( char *dn );
-char * slapi_esc_dn_normalize( char *dn );
-char * slapi_esc_dn_normalize_case( char *dn );
-int slapi_dn_isroot( Slapi_PBlock *pb, char *dn );
-int slapi_dn_issuffix( char *dn, char *suffix );
-char *slapi_dn_ignore_case( char *dn );
-char *slapi_get_hostname();
-void slapi_register_supported_saslmechanism( char *mechanism );
-void slapi_send_ldap_result( Slapi_PBlock *pb, int err,
+extern char *slapi_dn_normalize( char *dn );
+extern char *slapi_dn_normalize_case( char *dn );
+extern char * slapi_esc_dn_normalize( char *dn );
+extern char * slapi_esc_dn_normalize_case( char *dn );
+extern int slapi_dn_isroot( Slapi_PBlock *pb, char *dn );
+extern int slapi_dn_issuffix( char *dn, char *suffix );
+extern char *slapi_dn_ignore_case( char *dn );
+extern char *slapi_get_hostname();
+extern void slapi_register_supported_saslmechanism( char *mechanism );
+extern void slapi_send_ldap_result( Slapi_PBlock *pb, int err,
char *matched, char *text, int nentries, struct berval **urls );
-int slapi_send_ldap_extended_response(Connection *conn, Operation *op,
+extern int slapi_send_ldap_extended_response(Connection *conn, Operation *op,
int errornum, char *respName, struct berval *response);
-int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e,
+extern int slapi_send_ldap_search_entry( Slapi_PBlock *pb, Slapi_Entry *e,
LDAPControl **ectrls, char **attrs, int attrsonly );
-void slapi_register_supported_control(char *controloid,
+extern void slapi_register_supported_control(char *controloid,
unsigned long controlops);
-int slapi_get_supported_controls(char ***ctrloidsp, unsigned long **ctrlopsp);
-int slapi_control_present( LDAPControl **controls, char *oid,
+extern int slapi_get_supported_controls(char ***ctrloidsp, unsigned long **ctrlopsp);
+extern int slapi_control_present( LDAPControl **controls, char *oid,
struct berval **val, int *iscritical);
-void slapi_register_supported_saslmechanism(char *mechanism);
-char **slapi_get_supported_saslmechanisms();
-char **slapi_get_supported_extended_ops(void);
-int checkControlHonored(LDAPControl **controls, char *pControlOid,
+extern void slapi_register_supported_saslmechanism(char *mechanism);
+extern char **slapi_get_supported_saslmechanisms();
+extern char **slapi_get_supported_extended_ops(void);
+extern int checkControlHonored(LDAPControl **controls, char *pControlOid,
unsigned long operation, int *isHonored );
-void slapi_broadcast_be(int funcType, Slapi_PBlock *pPB);
-Slapi_Filter *slapi_str2filter( char *str );
-Slapi_Filter *slapi_filter_dup( Slapi_Filter *f );
-void slapi_filter_free( Slapi_Filter *f, int recurse );
-int slapi_filter_get_choice( Slapi_Filter *f);
-int slapi_filter_get_ava( Slapi_Filter *f, char **type, struct berval **bval );
-Slapi_Filter *slapi_filter_list_first( Slapi_Filter *f );
-Slapi_Filter *slapi_filter_list_next( Slapi_Filter *f, Slapi_Filter *fprev );
-int slapi_filter_get_attribute_type( Slapi_Filter *f, char **type );
-int slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
+extern void slapi_broadcast_be(int funcType, Slapi_PBlock *pPB);
+extern Slapi_Filter *slapi_str2filter( char *str );
+extern Slapi_Filter *slapi_filter_dup( Slapi_Filter *f );
+extern void slapi_filter_free( Slapi_Filter *f, int recurse );
+extern int slapi_filter_get_choice( Slapi_Filter *f);
+extern int slapi_filter_get_ava( Slapi_Filter *f, char **type, struct berval **bval );
+extern Slapi_Filter *slapi_filter_list_first( Slapi_Filter *f );
+extern Slapi_Filter *slapi_filter_list_next( Slapi_Filter *f, Slapi_Filter *fprev );
+extern int slapi_filter_get_attribute_type( Slapi_Filter *f, char **type );
+extern int slapi_filter_get_subfilt( Slapi_Filter *f, char **type, char **initial,
char ***any, char **final );
-Slapi_Filter *slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2);
-int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
+extern Slapi_Filter *slapi_filter_join( int ftype, Slapi_Filter *f1, Slapi_Filter *f2);
+extern int slapi_filter_test( Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Filter *f,
int verify_access );
-int slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code );
-int slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f);
-void slapi_free_search_results_internal(Slapi_PBlock *pb);
-int slapi_is_connection_ssl(Slapi_PBlock *pPB, int *isSSL);
-int slapi_get_client_port(Slapi_PBlock *pPB, int *fromPort);
-int slapi_get_num_be(char *type);
-unsigned long slapi_timer_current_time();
-unsigned long slapi_timer_get_time(char *label);
-void slapi_timer_elapsed_time(char *label,unsigned long start);
-int slapi_audit_init_header( Connection *conn, Operation *op,
+extern int slapi_filter_apply( Slapi_Filter *f, FILTER_APPLY_FN fn, void *arg, int *error_code );
+extern int slapi_filter_test_simple( Slapi_Entry *e, Slapi_Filter *f);
+extern void slapi_free_search_results_internal(Slapi_PBlock *pb);
+extern int slapi_is_connection_ssl(Slapi_PBlock *pPB, int *isSSL);
+extern int slapi_get_client_port(Slapi_PBlock *pPB, int *fromPort);
+extern int slapi_get_num_be(char *type);
+extern unsigned long slapi_timer_current_time();
+extern unsigned long slapi_timer_get_time(char *label);
+extern void slapi_timer_elapsed_time(char *label,unsigned long start);
+extern int slapi_audit_init_header( Connection *conn, Operation *op,
Audit_record **arp, void **audit_op_str,
int audit_op, int audit_ext_op, int audit_op_str_len);
-int slapi_audit_send_record( Slapi_PBlock *pb, Connection *conn,
+extern int slapi_audit_send_record( Slapi_PBlock *pb, Connection *conn,
Operation *op, int rc);
-int slapi_x_backend_set_pb( Slapi_PBlock *pb, Backend *be );
-int slapi_x_connection_set_pb( Slapi_PBlock *pb, Connection *conn );
-int slapi_x_operation_set_pb( Slapi_PBlock *pb, Operation *op );
+extern int slapi_x_backend_set_pb( Slapi_PBlock *pb, Backend *be );
+extern int slapi_x_connection_set_pb( Slapi_PBlock *pb, Connection *conn );
+extern int slapi_x_operation_set_pb( Slapi_PBlock *pb, Operation *op );
-LDAPMod **slapi_x_modifications2ldapmods(Modifications **);
-Modifications *slapi_x_ldapmods2modifications(LDAPMod **);
-void slapi_x_free_ldapmods(LDAPMod **);
+extern LDAPMod **slapi_x_modifications2ldapmods(Modifications **);
+extern Modifications *slapi_x_ldapmods2modifications(LDAPMod **);
+extern void slapi_x_free_ldapmods(LDAPMod **);
-int slapi_compute_add_evaluator(slapi_compute_callback_t function);
-int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function);
-int compute_rewrite_search_filter(Slapi_PBlock *pb);
-int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn);
-int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e);
-int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb);
+extern int slapi_compute_add_evaluator(slapi_compute_callback_t function);
+extern int slapi_compute_add_search_rewriter(slapi_search_rewrite_callback_t function);
+extern int compute_rewrite_search_filter(Slapi_PBlock *pb);
+extern int compute_evaluator(computed_attr_context *c, char *type, Slapi_Entry *e, slapi_compute_output_t outputfn);
+extern int slapi_x_compute_output_ber(computed_attr_context *c, Slapi_Attr *a, Slapi_Entry *e);
+extern int slapi_x_compute_get_pblock(computed_attr_context *c, Slapi_PBlock **pb);
extern ldap_pvt_thread_mutex_t slapi_hn_mutex;
extern ldap_pvt_thread_mutex_t slapi_time_mutex;
* Was: slapi_pblock.h
*/
-Slapi_PBlock *slapi_pblock_new( void );
-void slapi_pblock_destroy( Slapi_PBlock* );
-int slapi_pblock_get( Slapi_PBlock *pb, int arg, void *value );
-int slapi_pblock_set( Slapi_PBlock *pb, int arg, void *value );
-void slapi_pblock_check_params( Slapi_PBlock *pb, int flag );
-int slapi_pblock_delete_param( Slapi_PBlock *p, int param );
-void slapi_pblock_clear( Slapi_PBlock *pb );
+extern Slapi_PBlock *slapi_pblock_new( void );
+extern void slapi_pblock_destroy( Slapi_PBlock* );
+extern int slapi_pblock_get( Slapi_PBlock *pb, int arg, void *value );
+extern int slapi_pblock_set( Slapi_PBlock *pb, int arg, void *value );
+extern void slapi_pblock_check_params( Slapi_PBlock *pb, int flag );
+extern int slapi_pblock_delete_param( Slapi_PBlock *p, int param );
+extern void slapi_pblock_clear( Slapi_PBlock *pb );
/*
* OpenLDAP extensions
*/
-int slapi_x_pblock_get_first( Backend *be, Slapi_PBlock **pb );
-int slapi_x_pblock_get_next( Slapi_PBlock **pb );
+extern int slapi_x_pblock_get_first( Backend *be, Slapi_PBlock **pb );
+extern int slapi_x_pblock_get_next( Slapi_PBlock **pb );
/*
* Was: plugin.h
*/
-Slapi_PBlock *newPlugin ( int type, const char *path, const char *initfunc,
+extern Slapi_PBlock *newPlugin ( int type, const char *path, const char *initfunc,
int argc, char *argv[] );
-int insertPlugin(Backend *be, Slapi_PBlock *pPB);
-int doPluginFNs(Backend *be, int funcType, Slapi_PBlock * pPB);
-int getAllPluginFuncs(Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs);
-int newExtendedOp(Backend *pBE, ExtendedOp **opList, Slapi_PBlock *pPB);
-int getPluginFunc(struct berval *reqoid, SLAPI_FUNC *pFuncAddr );
-int netscape_plugin(Backend *be, const char *fname, int lineno,
+extern int insertPlugin(Backend *be, Slapi_PBlock *pPB);
+extern int doPluginFNs(Backend *be, int funcType, Slapi_PBlock * pPB);
+extern int getAllPluginFuncs(Backend *be, int functype, SLAPI_FUNC **ppFuncPtrs);
+extern int newExtendedOp(Backend *pBE, ExtendedOp **opList, Slapi_PBlock *pPB);
+extern int getPluginFunc(struct berval *reqoid, SLAPI_FUNC *pFuncAddr );
+extern int netscape_plugin(Backend *be, const char *fname, int lineno,
int argc, char **argv );
-int slapi_init(void);
+extern int slapi_init(void);
/*
* Was: slapi_ops.h
*/
-Slapi_PBlock *slapi_search_internal( char *base, int scope, char *filter,
+extern Slapi_PBlock *slapi_search_internal( char *base, int scope, char *filter,
LDAPControl **controls, char **attrs, int attrsonly );
-Slapi_PBlock *slapi_search_internal_bind( char *bindDN, char *base,
+extern Slapi_PBlock *slapi_search_internal_bind( char *bindDN, char *base,
int scope, char *filter, LDAPControl **controls,
char **attrs, int attrsonly ); /* d58508 */
-Slapi_PBlock *slapi_modify_internal( char *dn, LDAPMod **mods,
+extern Slapi_PBlock *slapi_modify_internal( char *dn, LDAPMod **mods,
LDAPControl **controls, int log_change );
-Slapi_PBlock *slapi_add_entry_internal( Slapi_Entry * e,
+extern Slapi_PBlock *slapi_add_entry_internal( Slapi_Entry * e,
LDAPControl **controls, int log_change );
-Slapi_PBlock *slapi_add_internal( char * dn, LDAPMod **attrs,
+extern Slapi_PBlock *slapi_add_internal( char * dn, LDAPMod **attrs,
LDAPControl **controls, int log_changes );
-Slapi_PBlock *slapi_add_entry_internal( Slapi_Entry * e,
+extern Slapi_PBlock *slapi_add_entry_internal( Slapi_Entry * e,
LDAPControl **controls, int log_change );
-Slapi_PBlock *slapi_delete_internal( char * dn, LDAPControl **controls,
+extern Slapi_PBlock *slapi_delete_internal( char * dn, LDAPControl **controls,
int log_change );
-Slapi_PBlock *slapi_modrdn_internal( char * olddn, char * newrdn,
+extern Slapi_PBlock *slapi_modrdn_internal( char * olddn, char * newrdn,
int deloldrdn, LDAPControl **controls, int log_change);
#if 0
-Slapi_PBlock *slapi_modrdn_internal( char * olddn, char * newrdn,
+extern Slapi_PBlock *slapi_modrdn_internal( char * olddn, char * newrdn,
char *newParent, int deloldrdn, LDAPControl **controls,
int log_change);
#endif
-char **slapi_get_supported_extended_ops(void);
-int duplicateBVMod( LDAPMod *pMod, LDAPMod **ppNewMod );
+extern char **slapi_get_supported_extended_ops(void);
+extern int duplicateBVMod( LDAPMod *pMod, LDAPMod **ppNewMod );
/*
* Was: slapi_cl.h
*/
-void slapi_register_changelog_suffix(char *suffix);
-char **slapi_get_changelog_suffixes();
-void slapi_update_changelog_counters(long curNum, long numEntries);
-char *slapi_get_cl_firstNum();
-char *slapi_get_cl_lastNum();
-int slapi_add_to_changelog(Slapi_Entry *ent, char *suffix,
+extern void slapi_register_changelog_suffix(char *suffix);
+extern char **slapi_get_changelog_suffixes();
+extern void slapi_update_changelog_counters(long curNum, long numEntries);
+extern char *slapi_get_cl_firstNum();
+extern char *slapi_get_cl_lastNum();
+extern int slapi_add_to_changelog(Slapi_Entry *ent, char *suffix,
char *chNum, Operation* op);
-int slapi_delete_changelog(char *dn, char *suffix,
+extern int slapi_delete_changelog(char *dn, char *suffix,
char *chNum, Operation* op);
-int slapi_modify_changelog(char *dn, LDAPMod *mods,char *suffix,
+extern int slapi_modify_changelog(char *dn, LDAPMod *mods,char *suffix,
char *chNum, Operation* op);
-int slapi_modifyrdn_changelog(char *olddn, char *newRdn, int delRdn,
+extern int slapi_modifyrdn_changelog(char *olddn, char *newRdn, int delRdn,
char *suffix, char *chNum, Operation* op);
-Backend * slapi_cl_get_be(char *dn);
+extern Backend * slapi_cl_get_be(char *dn);
LDAP_END_DECL
-/*\r
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.\r
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file\r
- */\r
-/*\r
- * (C) Copyright IBM Corp. 1997,2002\r
- * Redistribution and use in source and binary forms are permitted\r
- * provided that this notice is preserved and that due credit is\r
- * given to IBM Corporation. This software is provided ``as is''\r
- * without express or implied warranty.\r
- */\r
-\r
-#include "portable.h"\r
-#include <slap.h>\r
-#include <slapi.h>\r
-#include <lber.h>\r
-#include "../../../libraries/liblber/lber-int.h"\r
-\r
-\r
-int bvptr2obj( struct berval **bvptr, struct berval **bvobj );\r
-\r
-static void\r
-internal_result_v3(\r
- Connection *conn, \r
- Operation *op, \r
- ber_int_t err,\r
- const char *matched, \r
- const char *text, \r
- BerVarray referrals,\r
- LDAPControl **ctrls )\r
-{\r
- return;\r
-}\r
-\r
-static int\r
-internal_search_entry(\r
- Backend *be, \r
- Connection *conn, \r
- Operation *op, \r
- Entry *e, \r
- AttributeName *attrs, \r
- int attrsonly, \r
- LDAPControl **ctrls ) \r
-{\r
- char *ent2str = NULL;\r
- int nentries = 0, len = 0, i = 0;\r
- Slapi_Entry **head = NULL, **tp;\r
- \r
- ent2str = slapi_entry2str( e, &len );\r
- if ( ent2str == NULL ) {\r
- return 1;\r
- }\r
-\r
- slapi_pblock_get( (Slapi_PBlock *)op->o_pb,\r
- SLAPI_NENTRIES, &nentries );\r
- slapi_pblock_get( (Slapi_PBlock *)op->o_pb,\r
- SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );\r
- \r
- i = nentries + 1;\r
- if ( nentries == 0 ) {\r
- tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );\r
- if ( tp == NULL ) {\r
- return 1;\r
- }\r
-\r
- tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );\r
- if ( tp[ 0 ] == NULL ) { \r
- return 1;\r
- }\r
-\r
- } else {\r
- tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,\r
- sizeof(Slapi_Entry *) * ( i + 1 ) );\r
- if ( tp == NULL ) {\r
- return 1;\r
- }\r
- tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );\r
- if ( tp[ i - 1 ] == NULL ) { \r
- return 1;\r
- }\r
- }\r
- tp[ i ] = NULL;\r
- \r
- slapi_pblock_set( (Slapi_PBlock *)op->o_pb,\r
- SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );\r
- slapi_pblock_set( (Slapi_PBlock *)op->o_pb,\r
- SLAPI_NENTRIES, (void *)i );\r
-\r
- return LDAP_SUCCESS;\r
-}\r
-\r
-static void\r
-internal_search_result(\r
- Connection *conn, \r
- Operation *op,\r
- ber_int_t err, \r
- const char *matched, \r
- const char *text, \r
- BerVarray refs,\r
- LDAPControl **ctrls,\r
- int nentries ) \r
-{\r
- slapi_pblock_set( (Slapi_PBlock *)op->o_pb,\r
- SLAPI_NENTRIES, (void *)nentries );\r
-\r
- return;\r
-}\r
-\r
-static void\r
-internal_result_ext(\r
- Connection *conn, \r
- Operation *op, \r
- ber_int_t errnum, \r
- const char *matched,\r
- const char *text,\r
- BerVarray refs,\r
- const char *rspoid,\r
- struct berval *rspdata,\r
- LDAPControl **ctrls )\r
-{\r
- return;\r
-}\r
-\r
-static int\r
-internal_search_reference(\r
- Backend *be,\r
- Connection *conn, \r
- Operation *op, \r
- Entry *e,\r
- BerVarray refs,\r
- LDAPControl **ctrls,\r
- BerVarray *v2refs )\r
-{\r
- return LDAP_SUCCESS;\r
-}\r
-\r
-static Connection *\r
-fakeConnection(\r
- char *DN, \r
- int OpType ) \r
-{ \r
- Connection *pConn, *c;\r
- ber_len_t max = sockbuf_max_incoming;\r
-\r
- pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));\r
- if (pConn == NULL) {\r
- return (Connection *)NULL;\r
- }\r
-\r
- LDAP_STAILQ_INIT( &pConn->c_pending_ops );\r
-\r
- pConn->c_pending_ops.stqh_first =\r
- (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );\r
- if ( pConn->c_pending_ops.stqh_first == NULL ) { \r
- slapi_ch_free( (void **)&pConn );\r
- return (Connection *)NULL;\r
- }\r
-\r
- pConn->c_pending_ops.stqh_first->o_pb = \r
- (Slapi_PBlock *) slapi_pblock_new();\r
- if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {\r
- slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );\r
- slapi_ch_free( (void **)&pConn );\r
- return (Connection *)NULL;\r
- }\r
-\r
- c = pConn;\r
-\r
- /* operation object */\r
- c->c_pending_ops.stqh_first->o_tag = OpType;\r
- c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3; \r
- c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL; \r
- c->c_pending_ops.stqh_first->o_authmech.bv_len = 0; \r
- c->c_pending_ops.stqh_first->o_time = slap_get_time();\r
- c->c_pending_ops.stqh_first->o_do_not_cache = 1;\r
- c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );\r
-\r
- /* connection object */\r
- c->c_authmech.bv_val = NULL;\r
- c->c_authmech.bv_len = 0;\r
- c->c_dn.bv_val = NULL;\r
- c->c_dn.bv_len = 0;\r
- c->c_ndn.bv_val = NULL;\r
- c->c_ndn.bv_len = 0;\r
- c->c_groups = NULL;\r
-\r
- c->c_listener = NULL;\r
- c->c_peer_domain.bv_val = NULL;\r
- c->c_peer_domain.bv_len = 0;\r
- c->c_peer_name.bv_val = NULL;\r
- c->c_peer_name.bv_len = 0;\r
-\r
- LDAP_STAILQ_INIT( &c->c_ops );\r
-\r
- c->c_sasl_bind_mech.bv_val = NULL;\r
- c->c_sasl_bind_mech.bv_len = 0;\r
- c->c_sasl_context = NULL;\r
- c->c_sasl_extra = NULL;\r
-\r
- c->c_sb = ber_sockbuf_alloc( );\r
-\r
- ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );\r
-\r
- c->c_currentber = NULL;\r
-\r
- /* should check status of thread calls */\r
- ldap_pvt_thread_mutex_init( &c->c_mutex );\r
- ldap_pvt_thread_mutex_init( &c->c_write_mutex );\r
- ldap_pvt_thread_cond_init( &c->c_write_cv );\r
-\r
- c->c_n_ops_received = 0;\r
- c->c_n_ops_executing = 0;\r
- c->c_n_ops_pending = 0;\r
- c->c_n_ops_completed = 0;\r
-\r
- c->c_n_get = 0;\r
- c->c_n_read = 0;\r
- c->c_n_write = 0;\r
-\r
- c->c_protocol = LDAP_VERSION3; \r
-\r
- c->c_activitytime = c->c_starttime = slap_get_time();\r
-\r
- c->c_connid = 0;\r
-\r
- c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */\r
- c->c_struct_state = 0x02; /* SLAP_C_USED */\r
-\r
- c->c_ssf = c->c_transport_ssf = 0;\r
- c->c_tls_ssf = 0;\r
-\r
- backend_connection_init( c );\r
-\r
- pConn->c_send_ldap_result = internal_result_v3;\r
- pConn->c_send_search_entry = internal_search_entry;\r
- pConn->c_send_search_result = internal_search_result;\r
- pConn->c_send_ldap_extended = internal_result_ext;\r
- pConn->c_send_search_reference = internal_search_reference;\r
-\r
- return pConn;\r
-}\r
-\r
-/*\r
- * Function : values2obj\r
- * Convert an array of strings into a BerVarray.\r
- * the strings.\r
- */\r
-static int\r
-values2obj(\r
- char **ppValue,\r
- BerVarray *bvobj)\r
-{\r
- int rc = LDAP_SUCCESS;\r
- int i;\r
- BerVarray tmpberval;\r
-\r
- if ( ppValue == NULL ) {\r
- *bvobj = NULL;\r
- return LDAP_SUCCESS;\r
- }\r
-\r
- for ( i = 0; ppValue[i] != NULL; i++ )\r
- ;\r
-\r
- tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );\r
- if ( tmpberval == NULL ) {\r
- return LDAP_NO_MEMORY;\r
- }\r
- for ( i = 0; ppValue[i] != NULL; i++ ) {\r
- tmpberval[i].bv_val = ppValue[i];\r
- tmpberval[i].bv_len = strlen( ppValue[i] );\r
- }\r
- tmpberval[i].bv_val = NULL;\r
- tmpberval[i].bv_len = 0;\r
-\r
- *bvobj = tmpberval;\r
-\r
- return LDAP_SUCCESS;\r
-}\r
-\r
-static void\r
-freeMods( Modifications *ml )\r
-{\r
- /*\r
- * Free a modification list whose values have been \r
- * set with bvptr2obj() or values2obj() (ie. they\r
- * do not own the pointer to the underlying values)\r
- */\r
- Modifications *next;\r
-\r
- for ( ; ml != NULL; ml = next ) {\r
- next = ml->sml_next;\r
-\r
- slapi_ch_free( (void **)&ml->sml_bvalues );\r
- slapi_ch_free( (void **)&ml );\r
- }\r
-}\r
-\r
-/*\r
- * Function : LDAPModToEntry \r
- * convert a dn plus an array of LDAPMod struct ptrs to an entry structure\r
- * with a link list of the correspondent attributes.\r
- * Return value : LDAP_SUCCESS\r
- * LDAP_NO_MEMORY\r
- * LDAP_OTHER\r
-*/\r
-Entry *\r
-LDAPModToEntry(\r
- char *ldn, \r
- LDAPMod **mods )\r
-{\r
- struct berval dn = { 0, NULL };\r
- Entry *pEntry=NULL;\r
- LDAPMod *pMod;\r
- struct berval *bv;\r
- Backend *be;\r
- Operation *op;\r
-\r
- Modifications *modlist = NULL;\r
- Modifications **modtail = &modlist;\r
- Modifications tmp;\r
-\r
- int rc = LDAP_SUCCESS;\r
- int i;\r
-\r
- const char *text = NULL;\r
-\r
-\r
- op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));\r
- if ( pEntry == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- } \r
- op->o_tag = LDAP_REQ_ADD;\r
-\r
- pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );\r
- if ( pEntry == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- } \r
-\r
- dn.bv_val = slapi_ch_strdup(ldn);\r
- dn.bv_len = strlen(ldn);\r
-\r
- rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );\r
- if (rc != LDAP_SUCCESS) goto cleanup;\r
-\r
- if ( rc == LDAP_SUCCESS ) {\r
- for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {\r
- Modifications *mod;\r
- if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {\r
- /* attr values are in berval format */\r
- /* convert an array of pointers to bervals to an array of bervals */\r
- rc = bvptr2obj(pMod->mod_bvalues, &bv);\r
- if (rc != LDAP_SUCCESS) goto cleanup;\r
- tmp.sml_type.bv_val = pMod->mod_type;\r
- tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
- tmp.sml_bvalues = bv;\r
- \r
- mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
-\r
- mod->sml_op = LDAP_MOD_ADD;\r
- mod->sml_next = NULL;\r
- mod->sml_desc = NULL;\r
- mod->sml_type = tmp.sml_type;\r
- mod->sml_bvalues = tmp.sml_bvalues;\r
-\r
- *modtail = mod;\r
- modtail = &mod->sml_next;\r
-\r
- } else {\r
- /* attr values are in string format, need to be converted */\r
- /* to an array of bervals */ \r
- if ( pMod->mod_values == NULL ) {\r
- rc = LDAP_OTHER;\r
- } else {\r
- rc = values2obj( pMod->mod_values, &bv );\r
- if (rc != LDAP_SUCCESS) goto cleanup;\r
- tmp.sml_type.bv_val = pMod->mod_type;\r
- tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
- tmp.sml_bvalues = bv;\r
- \r
- mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
-\r
- mod->sml_op = LDAP_MOD_ADD;\r
- mod->sml_next = NULL;\r
- mod->sml_desc = NULL;\r
- mod->sml_type = tmp.sml_type;\r
- mod->sml_bvalues = tmp.sml_bvalues;\r
-\r
- *modtail = mod;\r
- modtail = &mod->sml_next;\r
- }\r
- }\r
- } /* for each LDAPMod */\r
- }\r
-\r
- be = select_backend(&pEntry->e_nname, 0, 0);\r
- if ( be == NULL ) {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- goto cleanup;\r
- }\r
-\r
- if ( be ) {\r
- int repl_user = be_isupdate(be, &be->be_rootdn );\r
- if ( !be->be_update_ndn.bv_len || repl_user ) {\r
- int update = be->be_update_ndn.bv_len;\r
- char textbuf[SLAP_TEXT_BUFLEN];\r
- size_t textlen = sizeof textbuf;\r
-\r
- rc = slap_mods_check( modlist, update, &text, \r
- textbuf, textlen );\r
- if ( rc != LDAP_SUCCESS) {\r
- goto cleanup;\r
- }\r
-\r
- if ( !repl_user ) {\r
- rc = slap_mods_opattrs( be, op,\r
- modlist, modtail, &text, \r
- textbuf, textlen );\r
- if ( rc != LDAP_SUCCESS) {\r
- goto cleanup;\r
- }\r
- }\r
-\r
- /*\r
- * FIXME: slap_mods2entry is declared static \r
- * in servers/slapd/add.c\r
- */\r
- rc = slap_mods2entry( modlist, &pEntry, repl_user,\r
- &text, textbuf, textlen );\r
- if (rc != LDAP_SUCCESS) {\r
- goto cleanup;\r
- }\r
-\r
- } else {\r
- rc = LDAP_REFERRAL;\r
- }\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
-\r
- if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );\r
- if ( op ) slapi_ch_free( (void **)&op );\r
- if ( modlist != NULL ) freeMods( modlist );\r
- if ( rc != LDAP_SUCCESS ) {\r
- if ( pEntry != NULL ) {\r
- slapi_entry_free( pEntry );\r
- }\r
- pEntry = NULL;\r
- }\r
-\r
- return( pEntry );\r
-}\r
-\r
-/* Function : slapi_delete_internal\r
- *\r
- * Description : Plugin functions call this routine to delete an entry \r
- * in the backend directly\r
- * Return values : LDAP_SUCCESS\r
- * LDAP_PARAM_ERROR\r
- * LDAP_NO_MEMORY\r
- * LDAP_OTHER\r
- * LDAP_UNWILLING_TO_PERFORM\r
-*/\r
-Slapi_PBlock *\r
-slapi_delete_internal(\r
- char *ldn, \r
- LDAPControl **controls, \r
- int log_change )\r
-{\r
-#if defined(LDAP_SLAPI)\r
- Backend *be;\r
- Connection *pConn = NULL;\r
- Operation *op = NULL;\r
- Slapi_PBlock *pPB = NULL;\r
- Slapi_PBlock *pSavePB = NULL;\r
-\r
- struct berval dn = { 0, NULL };\r
- struct berval pdn = { 0, NULL };\r
- struct berval ndn = { 0, NULL };\r
-\r
- int rc=LDAP_SUCCESS;\r
- int manageDsaIt = 0;\r
- int isCritical;\r
-\r
- if ( ldn == NULL ) {\r
- rc = LDAP_PARAM_ERROR; \r
- goto cleanup;\r
- }\r
-\r
- pConn = fakeConnection( NULL, LDAP_REQ_DELETE );\r
- if (pConn == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- }\r
-\r
- op = (Operation *)pConn->c_pending_ops.stqh_first;\r
- pPB = (Slapi_PBlock *)op->o_pb;\r
- op->o_ctrls = controls;\r
-\r
- dn.bv_val = slapi_ch_strdup(ldn);\r
- dn.bv_len = slapi_strlen(ldn);\r
- rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-\r
- if ( slapi_control_present( controls, \r
- SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {\r
- manageDsaIt = 1; \r
- }\r
-\r
- be = select_backend( &ndn, manageDsaIt, 0 );\r
- if ( be == NULL ) {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- goto cleanup;\r
- }\r
-\r
- op->o_dn = pConn->c_dn = be->be_rootdn;\r
- op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
-\r
- suffix_alias( be, &ndn );\r
-\r
- if ( be->be_delete ) {\r
- int repl_user = be_isupdate( be, &op->o_ndn );\r
- if ( !be->be_update_ndn.bv_len || repl_user ) {\r
- rc = (*be->be_delete)( be, pConn, op, &pdn, &ndn );\r
- if ( rc == 0 ) {\r
- if (log_change) {\r
- replog( be, op, &pdn, &ndn, NULL );\r
- }\r
- rc = LDAP_SUCCESS;\r
- } else {\r
- rc = LDAP_OPERATIONS_ERROR;\r
- }\r
- } else {\r
- rc = LDAP_REFERRAL;\r
- }\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
- if (pPB != NULL) \r
- slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
-\r
- if (dn.bv_val) slapi_ch_free( (void **)&dn.bv_val );\r
- if (pdn.bv_val) slapi_ch_free( (void **)&pdn.bv_val );\r
- if (ndn.bv_val) slapi_ch_free( (void **)&ndn.bv_val );\r
-\r
- if ( pConn != NULL ) {\r
- if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( op ) slapi_ch_free( (void **)&op );\r
- pSavePB = pPB;\r
- free( pConn );\r
- }\r
- \r
- return (pSavePB);\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-Slapi_PBlock * \r
-slapi_add_entry_internal(\r
- Slapi_Entry *e, \r
- LDAPControl **controls, \r
- int log_changes ) \r
-{\r
-#if defined(LDAP_SLAPI)\r
- Connection *pConn = NULL;\r
- Operation *op = NULL;\r
- Slapi_PBlock *pPB = NULL, *pSavePB = NULL;\r
- Backend *be;\r
-\r
- int manageDsaIt = 0;\r
- int isCritical;\r
- int rc = LDAP_SUCCESS;\r
-\r
- if ( e == NULL ) {\r
- rc = LDAP_PARAM_ERROR;\r
- goto cleanup;\r
- }\r
- \r
- pConn = fakeConnection( NULL, LDAP_REQ_ADD );\r
- if ( pConn == NULL ) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- }\r
-\r
- if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,\r
- NULL, &isCritical ) ) {\r
- manageDsaIt = 1; \r
- }\r
-\r
- op = (Operation *)pConn->c_pending_ops.stqh_first;\r
- pPB = (Slapi_PBlock *)op->o_pb;\r
- op->o_ctrls = controls;\r
-\r
- be = select_backend( &e->e_nname, manageDsaIt, 0 );\r
- if ( be == NULL ) {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- goto cleanup;\r
- }\r
-\r
- op->o_dn = pConn->c_dn = be->be_rootdn;\r
- op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
-\r
- if ( be->be_add ) {\r
- int repl_user = be_isupdate( be, &op->o_ndn );\r
- if ( !be->be_update_ndn.bv_len || repl_user ){\r
- if ( (*be->be_add)( be, pConn, op, e ) == 0 ) {\r
- if ( log_changes ) {\r
- replog( be, op, &e->e_name, \r
- &e->e_nname, e );\r
- }\r
- rc = LDAP_SUCCESS;\r
- }\r
- } else {\r
- rc = LDAP_REFERRAL;\r
- }\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
-\r
- if ( pPB != NULL ) {\r
- slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
- }\r
-\r
- if ( pConn != NULL ) {\r
- if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( op != NULL ) slapi_ch_free( (void **)&op );\r
- pSavePB = pPB;\r
- free( pConn );\r
- }\r
- return( pSavePB );\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-\r
-Slapi_PBlock *\r
-slapi_add_internal(\r
- char *dn, \r
- LDAPMod **mods, \r
- LDAPControl **controls, \r
- int log_changes ) \r
-{\r
-#if defined(LDAP_SLAPI)\r
- LDAPMod *pMod = NULL;\r
- Slapi_PBlock *pb = NULL;\r
- Entry *pEntry = NULL;\r
- int i, rc=LDAP_SUCCESS;\r
-\r
- if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {\r
- rc = LDAP_PARAM_ERROR ;\r
- }\r
-\r
- if ( rc == LDAP_SUCCESS ) {\r
- for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {\r
- if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {\r
- rc = LDAP_OTHER;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if ( rc == LDAP_SUCCESS ) {\r
- if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {\r
- rc = LDAP_OTHER;\r
- }\r
- }\r
-\r
- if ( rc != LDAP_SUCCESS ) {\r
- pb = slapi_pblock_new();\r
- slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
- } else {\r
- pb = slapi_add_entry_internal( pEntry, controls, log_changes );\r
- }\r
-\r
- if ( pEntry ) {\r
- slapi_entry_free(pEntry);\r
- }\r
-\r
- return(pb);\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-/* Function : slapi_modrdn_internal\r
- *\r
- * Description : Plugin functions call this routine to modify the rdn \r
- * of an entry in the backend directly\r
- * Return values : LDAP_SUCCESS\r
- * LDAP_PARAM_ERROR\r
- * LDAP_OPERATIONS_ERROR\r
- * LDAP_NO_MEMORY\r
- * LDAP_OTHER\r
- * LDAP_UNWILLING_TO_PERFORM\r
- *\r
- * NOTE: This function does not support the "newSuperior" option from LDAP V3.\r
- */\r
-Slapi_PBlock *\r
-slapi_modrdn_internal(\r
- char *olddn, \r
- char *lnewrdn, \r
- int deloldrdn, \r
- LDAPControl **controls, \r
- int log_change )\r
-{\r
-#if defined(LDAP_SLAPI)\r
- int rc = LDAP_SUCCESS;\r
-\r
- struct berval dn = { 0, NULL };\r
- struct berval pdn = { 0, NULL };\r
- struct berval ndn = { 0, NULL };\r
-\r
- struct berval newrdn = { 0, NULL };\r
- struct berval pnewrdn = { 0, NULL };\r
- struct berval nnewrdn = { 0, NULL };\r
-\r
-#if 0 /* currently unused */\r
- struct berval newSuperior = { 0, NULL };\r
-#endif\r
- struct berval pnewSuperior = { 0, NULL }; \r
-#if 0 /* currently unused */\r
- struct berval nnewSuperior = { 0, NULL }; \r
-#endif\r
-\r
- struct berval *pnewS = NULL;\r
- struct berval *nnewS = NULL;\r
-\r
- Connection *pConn = NULL;\r
- Operation *op = NULL;\r
- Slapi_PBlock *pPB = NULL;\r
- Slapi_PBlock *pSavePB = NULL;\r
-\r
- Backend *be;\r
-#if 0 /* currently unused */\r
- Backend *newSuperior_be = NULL;\r
-#endif\r
-\r
- int manageDsaIt = 0;\r
- int isCritical;\r
-#if 0 /* currently unused */\r
- const char *text = NULL;\r
-#endif\r
-\r
- dn.bv_val = slapi_ch_strdup(olddn);\r
- dn.bv_len = slapi_ch_stlen(olddn);\r
-\r
- rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );\r
-\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-\r
- if ( ndn.bv_len == 0 ) {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- goto cleanup;\r
- }\r
-\r
- newrdn.bv_val = slapi_ch_strdup( lnewrdn );\r
- newrdn.bv_len = slapi_ch_stlen( lnewrdn );\r
-\r
- rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );\r
-\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-\r
- if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;\r
-\r
- pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);\r
- if ( pConn == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- }\r
-\r
- op = (Operation *)pConn->c_pending_ops.stqh_first;\r
- pPB = (Slapi_PBlock *)op->o_pb;\r
- op->o_ctrls = controls;\r
-\r
- if ( slapi_control_present( controls, \r
- SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {\r
- manageDsaIt = 1;\r
- }\r
-\r
- be = select_backend( &ndn, manageDsaIt, 0 );\r
- if ( be == NULL ) {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- goto cleanup;\r
- }\r
-\r
- op->o_dn = pConn->c_dn = be->be_rootdn;\r
- op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
-\r
- suffix_alias( be, &ndn );\r
-\r
- if ( be->be_modrdn ) {\r
- int repl_user = be_isupdate( be, &op->o_ndn );\r
- if ( !be->be_update_ndn.bv_len || repl_user ) {\r
- rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,\r
- &pnewrdn, &nnewrdn, deloldrdn, pnewS,\r
- nnewS );\r
- if ( rc == 0 ) {\r
- struct slap_replog_moddn moddn;\r
- moddn.newrdn = &pnewrdn;\r
- moddn.deloldrdn = deloldrdn;\r
- moddn.newsup = &pnewSuperior;\r
- if ( log_change ) {\r
- replog( be, op, &pdn, &ndn, &moddn );\r
- }\r
- rc = LDAP_SUCCESS;\r
-\r
- } else {\r
- rc = LDAP_OPERATIONS_ERROR;\r
- }\r
-\r
- } else {\r
- rc = LDAP_REFERRAL;\r
- }\r
-\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
-\r
- if ( pPB != NULL ) {\r
- slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
- }\r
- \r
- if ( dn.bv_val ) ch_free( dn.bv_val );\r
- if ( pdn.bv_val ) ch_free( pdn.bv_val );\r
- if ( ndn.bv_val ) ch_free( ndn.bv_val );\r
-\r
- if ( newrdn.bv_val ) ch_free( newrdn.bv_val );\r
- if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );\r
- if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );\r
-\r
- if ( pConn != NULL ) {\r
- if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( op != NULL ) slapi_ch_free( (void **)&op );\r
- pSavePB = pPB;\r
- free( pConn );\r
- }\r
-\r
- return( pSavePB );\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-/* Function : slapi_modify_internal\r
- *\r
- * Description: Plugin functions call this routine to modify an entry \r
- * in the backend directly\r
- * Return values : LDAP_SUCCESS\r
- * LDAP_PARAM_ERROR\r
- * LDAP_NO_MEMORY\r
- * LDAP_OPERATIONS_ERROR\r
- * LDAP_OTHER\r
- * LDAP_UNWILLING_TO_PERFORM\r
-*/\r
-Slapi_PBlock *\r
-slapi_modify_internal(\r
- char *ldn, \r
- LDAPMod **mods, \r
- LDAPControl **controls, \r
- int log_change )\r
-{\r
-#if defined(LDAP_SLAPI)\r
- int i, rc = LDAP_SUCCESS;\r
- Connection *pConn = NULL;\r
- Operation *op = NULL;\r
- Slapi_PBlock *pPB = NULL;\r
- Slapi_PBlock *pSavePB = NULL;\r
-\r
- struct berval dn = { 0, NULL };\r
- struct berval pdn = { 0, NULL };\r
- struct berval ndn = { 0, NULL };\r
-\r
- int manageDsaIt = 0;\r
- int isCritical;\r
- Backend *be;\r
- struct berval *bv;\r
- LDAPMod *pMod;\r
-\r
- Modifications *modlist = NULL;\r
- Modifications **modtail = &modlist;\r
- Modifications tmp;\r
-\r
- if ( mods == NULL || *mods == NULL || ldn == NULL ) {\r
- rc = LDAP_PARAM_ERROR ;\r
- goto cleanup;\r
- }\r
-\r
- pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );\r
- if ( pConn == NULL ) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- }\r
-\r
- op = (Operation *)pConn->c_pending_ops.stqh_first;\r
- pPB = (Slapi_PBlock *)op->o_pb;\r
- op->o_ctrls = controls;\r
-\r
- dn.bv_val = slapi_ch_strdup( ldn );\r
- dn.bv_len = slapi_strlen( ldn );\r
- rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
-\r
- if ( slapi_control_present( controls, \r
- SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {\r
- manageDsaIt = 1;\r
- }\r
-\r
- be = select_backend( &ndn, manageDsaIt, 0 );\r
- if ( be == NULL ) {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- goto cleanup;\r
- }\r
-\r
- op->o_dn = pConn->c_dn = be->be_rootdn;\r
- op->o_ndn = pConn->c_ndn = be->be_rootndn;\r
-\r
- suffix_alias( be, &ndn );\r
-\r
- for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL; \r
- pMod = mods[++i] ) {\r
- Modifications *mod;\r
- if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {\r
- /*\r
- * attr values are in berval format\r
- * convert an array of pointers to bervals\r
- * to an array of bervals\r
- */\r
- rc = bvptr2obj( pMod->mod_bvalues, &bv );\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
- tmp.sml_type.bv_val = pMod->mod_type;\r
- tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
- tmp.sml_bvalues = bv;\r
-\r
- mod = (Modifications *)ch_malloc( sizeof(Modifications) );\r
-\r
- mod->sml_op = pMod->mod_op;\r
- mod->sml_next = NULL;\r
- mod->sml_desc = NULL;\r
- mod->sml_type = tmp.sml_type;\r
- mod->sml_bvalues = tmp.sml_bvalues;\r
- } else { \r
- rc = values2obj( pMod->mod_values, &bv );\r
- if ( rc != LDAP_SUCCESS ) goto cleanup;\r
- tmp.sml_type.bv_val = pMod->mod_type;\r
- tmp.sml_type.bv_len = strlen( pMod->mod_type );\r
- tmp.sml_bvalues = bv;\r
-\r
- mod = (Modifications *) ch_malloc( sizeof(Modifications) );\r
-\r
- mod->sml_op = pMod->mod_op;\r
- mod->sml_next = NULL;\r
- mod->sml_desc = NULL;\r
- mod->sml_type = tmp.sml_type;\r
- mod->sml_bvalues = tmp.sml_bvalues;\r
- }\r
- *modtail = mod;\r
- modtail = &mod->sml_next;\r
-\r
- switch( pMod->mod_op ) {\r
- case LDAP_MOD_ADD:\r
- if ( mod->sml_bvalues == NULL ) {\r
- rc = LDAP_PROTOCOL_ERROR;\r
- goto cleanup;\r
- }\r
-\r
- /* fall through */\r
- case LDAP_MOD_DELETE:\r
- case LDAP_MOD_REPLACE:\r
- break;\r
-\r
- default:\r
- rc = LDAP_PROTOCOL_ERROR;\r
- goto cleanup;\r
- }\r
- } \r
- *modtail = NULL;\r
-\r
- if ( ndn.bv_len == 0 ) {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- goto cleanup;\r
- }\r
-\r
- if ( be->be_modify ) {\r
- int repl_user = be_isupdate( be, &op->o_ndn );\r
- if ( !be->be_update_ndn.bv_len || repl_user ) {\r
- int update = be->be_update_ndn.bv_len;\r
- const char *text = NULL;\r
- char textbuf[SLAP_TEXT_BUFLEN];\r
- size_t textlen = sizeof( textbuf );\r
-\r
- rc = slap_mods_check( modlist, update,\r
- &text, textbuf, textlen );\r
- if (rc != LDAP_SUCCESS) {\r
- goto cleanup;\r
- }\r
-\r
- if ( !repl_user ) {\r
- rc = slap_mods_opattrs( be, op, modlist,\r
- modtail, &text, textbuf, \r
- textlen );\r
- if (rc != LDAP_SUCCESS) {\r
- goto cleanup;\r
- }\r
- }\r
- rc = (*be->be_modify)( be, pConn, op,\r
- &pdn, &ndn, modlist );\r
- if ( rc == 0 ) {\r
- if ( log_change ) {\r
- replog( be, op, &pdn, &ndn, modlist );\r
- }\r
- rc = LDAP_SUCCESS;\r
- } else {\r
- rc = LDAP_OPERATIONS_ERROR;\r
- }\r
- } else {\r
- rc = LDAP_REFERRAL;\r
- }\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
-\r
- if ( pPB != NULL ) \r
- slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
-\r
- if ( dn.bv_val ) ch_free( dn.bv_val );\r
- if ( pdn.bv_val ) ch_free( pdn.bv_val );\r
- if ( ndn.bv_val ) ch_free( ndn.bv_val );\r
-\r
- if ( modlist != NULL ) freeMods( modlist );\r
-\r
- if ( pConn != NULL ) {\r
- if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );\r
- if ( op != NULL ) slapi_ch_free( (void **)&op );\r
- pSavePB = pPB;\r
- free( pConn );\r
- }\r
-\r
- return ( pSavePB );\r
-\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-Slapi_PBlock *\r
-slapi_search_internal_bind(\r
- char *bindDN, \r
- char *ldn, \r
- int scope, \r
- char *filStr, \r
- LDAPControl **controls, \r
- char **attrs, \r
- int attrsonly ) \r
-{ \r
-#if defined(LDAP_SLAPI)\r
- Backend *be;\r
- Connection *c;\r
- Operation *op = NULL;\r
- Slapi_PBlock *ptr = NULL; \r
- Slapi_PBlock *pSavePB = NULL; \r
- struct berval dn = { 0, NULL };\r
- struct berval pdn = { 0, NULL };\r
- struct berval ndn = { 0, NULL };\r
- Filter *filter=NULL;\r
- struct berval fstr = { 0, NULL };\r
- AttributeName *an = NULL;\r
- const char *text = NULL;\r
-\r
- int deref=0;\r
- int sizelimit=-1, timelimit=-1;\r
-\r
- int manageDsaIt = 0; \r
- int isCritical;\r
-\r
- int i, rc = LDAP_SUCCESS;\r
- \r
- c = fakeConnection( NULL, LDAP_REQ_SEARCH );\r
- if (c == NULL) {\r
- rc = LDAP_NO_MEMORY;\r
- goto cleanup;\r
- }\r
-\r
- op = (Operation *)c->c_pending_ops.stqh_first;\r
- ptr = (Slapi_PBlock *)op->o_pb;\r
- op->o_ctrls = controls;\r
-\r
- dn.bv_val = slapi_ch_strdup(ldn);\r
- dn.bv_len = slapi_strlen(ldn);\r
-\r
- rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );\r
- if (rc != LDAP_SUCCESS) goto cleanup;\r
-\r
- if ( scope != LDAP_SCOPE_BASE && \r
- scope != LDAP_SCOPE_ONELEVEL && \r
- scope != LDAP_SCOPE_SUBTREE ) {\r
- rc = LDAP_PROTOCOL_ERROR;\r
- goto cleanup;\r
- }\r
-\r
- filter = slapi_str2filter(filStr);\r
- if ( filter == NULL ) {\r
- rc = LDAP_PROTOCOL_ERROR;\r
- goto cleanup;\r
- }\r
-\r
- filter2bv( filter, &fstr );\r
-\r
- for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {\r
- ; /* count the number of attributes */\r
- }\r
-\r
- if (i > 0) {\r
- an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );\r
- for (i = 0; attrs[i] != 0; i++) {\r
- an[i].an_desc = NULL;\r
- an[i].an_oc = NULL;\r
- an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);\r
- an[i].an_name.bv_len = slapi_strlen(attrs[i]);\r
- slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );\r
- }\r
- an[i].an_name.bv_val = NULL;\r
- }\r
-\r
- if ( scope == LDAP_SCOPE_BASE ) {\r
- Entry *entry = NULL;\r
-\r
- if ( ndn.bv_len == 0 ) {\r
- rc = root_dse_info( c, &entry, &text );\r
- }\r
-\r
- if( rc != LDAP_SUCCESS ) {\r
- send_ldap_result( c, op, rc, NULL, text, NULL, NULL );\r
- goto cleanup;\r
- } else if ( entry != NULL ) {\r
- rc = test_filter( NULL, c, op, entry, filter );\r
-\r
- if( rc == LDAP_COMPARE_TRUE ) {\r
- send_search_entry( NULL, c, op, entry,\r
- an, attrsonly, NULL );\r
- }\r
-\r
- entry_free( entry );\r
-\r
- send_ldap_result( c, op, LDAP_SUCCESS, \r
- NULL, NULL, NULL, NULL );\r
-\r
- rc = LDAP_SUCCESS;\r
-\r
- goto cleanup;\r
- }\r
- }\r
-\r
- if ( !ndn.bv_len && default_search_nbase.bv_len ) {\r
- ch_free( pdn.bv_val );\r
- ch_free( ndn.bv_val );\r
-\r
- ber_dupbv( &pdn, &default_search_base );\r
- ber_dupbv( &ndn, &default_search_nbase );\r
- }\r
-\r
- if ( slapi_control_present( controls,\r
- LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {\r
- manageDsaIt = 1;\r
- }\r
-\r
- be = select_backend( &ndn, manageDsaIt, 0 );\r
- if ( be == NULL ) {\r
- if ( manageDsaIt == 1 ) {\r
- rc = LDAP_NO_SUCH_OBJECT;\r
- } else {\r
- rc = LDAP_PARTIAL_RESULTS;\r
- }\r
- goto cleanup;\r
- } \r
-\r
- op->o_dn = c->c_dn = be->be_rootdn;\r
- op->o_ndn = c->c_ndn = be->be_rootndn;\r
-\r
- if ( be->be_search ) {\r
- rc = (*be->be_search)( be, c, op, &pdn, &ndn,\r
- scope, deref, sizelimit, timelimit,\r
- filter, &fstr, an, attrsonly );\r
- if ( rc == 0 ) {\r
- rc = LDAP_SUCCESS;\r
- } else {\r
- rc = LDAP_OPERATIONS_ERROR;\r
- }\r
- } else {\r
- rc = LDAP_UNWILLING_TO_PERFORM;\r
- }\r
-\r
-cleanup:\r
-\r
- if ( ptr != NULL )\r
- slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );\r
-\r
- if ( dn.bv_val ) free( dn.bv_val );\r
- if ( ndn.bv_val ) free( ndn.bv_val );\r
- if ( pdn.bv_val ) free( pdn.bv_val );\r
-\r
- if ( filter ) slapi_filter_free( filter, 1 );\r
- if ( fstr.bv_val ) free ( fstr.bv_val );\r
-\r
- if ( an != NULL ) free( an );\r
-\r
- if ( c != NULL ) {\r
- if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );\r
- if ( op != NULL ) slapi_ch_free( (void **)&op );\r
- pSavePB = ptr;\r
- free( c );\r
- }\r
- return( pSavePB );\r
-#endif /* LDAP_SLAPI */\r
- return NULL;\r
-}\r
-\r
-Slapi_PBlock * \r
-slapi_search_internal(\r
- char *base,\r
- int scope,\r
- char *filStr, \r
- LDAPControl **controls,\r
- char **attrs,\r
- int attrsonly ) \r
-{\r
-#if defined(LDAP_SLAPI)\r
- return slapi_search_internal_bind( NULL, base, scope, filStr,\r
- controls, attrs, attrsonly );\r
-#else\r
- return NULL;\r
-#endif /* LDAP_SLAPI */\r
-}\r
-\r
+/*
+ * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*
+ * (C) Copyright IBM Corp. 1997,2002
+ * Redistribution and use in source and binary forms are permitted
+ * provided that this notice is preserved and that due credit is
+ * given to IBM Corporation. This software is provided ``as is''
+ * without express or implied warranty.
+ */
+
+#include "portable.h"
+#include <slap.h>
+#include <slapi.h>
+#include <lber.h>
+#include "../../../libraries/liblber/lber-int.h"
+
+
+int bvptr2obj( struct berval **bvptr, struct berval **bvobj );
+
+static void
+internal_result_v3(
+ Connection *conn,
+ Operation *op,
+ ber_int_t err,
+ const char *matched,
+ const char *text,
+ BerVarray referrals,
+ LDAPControl **ctrls )
+{
+ return;
+}
+
+static int
+internal_search_entry(
+ Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e,
+ AttributeName *attrs,
+ int attrsonly,
+ LDAPControl **ctrls )
+{
+ char *ent2str = NULL;
+ int nentries = 0, len = 0, i = 0;
+ Slapi_Entry **head = NULL, **tp;
+
+ ent2str = slapi_entry2str( e, &len );
+ if ( ent2str == NULL ) {
+ return 1;
+ }
+
+ slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
+ SLAPI_NENTRIES, &nentries );
+ slapi_pblock_get( (Slapi_PBlock *)op->o_pb,
+ SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, &head );
+
+ i = nentries + 1;
+ if ( nentries == 0 ) {
+ tp = (Slapi_Entry **)slapi_ch_malloc( 2 * sizeof(Slapi_Entry *) );
+ if ( tp == NULL ) {
+ return 1;
+ }
+
+ tp[ 0 ] = (Slapi_Entry *)str2entry( ent2str );
+ if ( tp[ 0 ] == NULL ) {
+ return 1;
+ }
+
+ } else {
+ tp = (Slapi_Entry **)slapi_ch_realloc( (char *)head,
+ sizeof(Slapi_Entry *) * ( i + 1 ) );
+ if ( tp == NULL ) {
+ return 1;
+ }
+ tp[ i - 1 ] = (Slapi_Entry *)str2entry( ent2str );
+ if ( tp[ i - 1 ] == NULL ) {
+ return 1;
+ }
+ }
+ tp[ i ] = NULL;
+
+ slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
+ SLAPI_PLUGIN_INTOP_SEARCH_ENTRIES, (void *)tp );
+ slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
+ SLAPI_NENTRIES, (void *)i );
+
+ return LDAP_SUCCESS;
+}
+
+static void
+internal_search_result(
+ Connection *conn,
+ Operation *op,
+ ber_int_t err,
+ const char *matched,
+ const char *text,
+ BerVarray refs,
+ LDAPControl **ctrls,
+ int nentries )
+{
+ slapi_pblock_set( (Slapi_PBlock *)op->o_pb,
+ SLAPI_NENTRIES, (void *)nentries );
+
+ return;
+}
+
+static void
+internal_result_ext(
+ Connection *conn,
+ Operation *op,
+ ber_int_t errnum,
+ const char *matched,
+ const char *text,
+ BerVarray refs,
+ const char *rspoid,
+ struct berval *rspdata,
+ LDAPControl **ctrls )
+{
+ return;
+}
+
+static int
+internal_search_reference(
+ Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e,
+ BerVarray refs,
+ LDAPControl **ctrls,
+ BerVarray *v2refs )
+{
+ return LDAP_SUCCESS;
+}
+
+static Connection *
+fakeConnection(
+ char *DN,
+ int OpType )
+{
+ Connection *pConn, *c;
+ ber_len_t max = sockbuf_max_incoming;
+
+ pConn = (Connection *) slapi_ch_calloc(1, sizeof(Connection));
+ if (pConn == NULL) {
+ return (Connection *)NULL;
+ }
+
+ LDAP_STAILQ_INIT( &pConn->c_pending_ops );
+
+ pConn->c_pending_ops.stqh_first =
+ (Operation *) slapi_ch_calloc( 1, sizeof(Operation) );
+ if ( pConn->c_pending_ops.stqh_first == NULL ) {
+ slapi_ch_free( (void **)&pConn );
+ return (Connection *)NULL;
+ }
+
+ pConn->c_pending_ops.stqh_first->o_pb =
+ (Slapi_PBlock *) slapi_pblock_new();
+ if ( pConn->c_pending_ops.stqh_first->o_pb == NULL ) {
+ slapi_ch_free( (void **)&pConn->c_pending_ops.stqh_first );
+ slapi_ch_free( (void **)&pConn );
+ return (Connection *)NULL;
+ }
+
+ c = pConn;
+
+ /* operation object */
+ c->c_pending_ops.stqh_first->o_tag = OpType;
+ c->c_pending_ops.stqh_first->o_protocol = LDAP_VERSION3;
+ c->c_pending_ops.stqh_first->o_authmech.bv_val = NULL;
+ c->c_pending_ops.stqh_first->o_authmech.bv_len = 0;
+ c->c_pending_ops.stqh_first->o_time = slap_get_time();
+ c->c_pending_ops.stqh_first->o_do_not_cache = 1;
+ c->c_pending_ops.stqh_first->o_threadctx = ldap_pvt_thread_pool_context( &connection_pool );
+
+ /* connection object */
+ c->c_authmech.bv_val = NULL;
+ c->c_authmech.bv_len = 0;
+ c->c_dn.bv_val = NULL;
+ c->c_dn.bv_len = 0;
+ c->c_ndn.bv_val = NULL;
+ c->c_ndn.bv_len = 0;
+ c->c_groups = NULL;
+
+ c->c_listener = NULL;
+ c->c_peer_domain.bv_val = NULL;
+ c->c_peer_domain.bv_len = 0;
+ c->c_peer_name.bv_val = NULL;
+ c->c_peer_name.bv_len = 0;
+
+ LDAP_STAILQ_INIT( &c->c_ops );
+
+ c->c_sasl_bind_mech.bv_val = NULL;
+ c->c_sasl_bind_mech.bv_len = 0;
+ c->c_sasl_context = NULL;
+ c->c_sasl_extra = NULL;
+
+ c->c_sb = ber_sockbuf_alloc( );
+
+ ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max );
+
+ c->c_currentber = NULL;
+
+ /* should check status of thread calls */
+ ldap_pvt_thread_mutex_init( &c->c_mutex );
+ ldap_pvt_thread_mutex_init( &c->c_write_mutex );
+ ldap_pvt_thread_cond_init( &c->c_write_cv );
+
+ c->c_n_ops_received = 0;
+ c->c_n_ops_executing = 0;
+ c->c_n_ops_pending = 0;
+ c->c_n_ops_completed = 0;
+
+ c->c_n_get = 0;
+ c->c_n_read = 0;
+ c->c_n_write = 0;
+
+ c->c_protocol = LDAP_VERSION3;
+
+ c->c_activitytime = c->c_starttime = slap_get_time();
+
+ c->c_connid = 0;
+
+ c->c_conn_state = 0x01; /* SLAP_C_ACTIVE */
+ c->c_struct_state = 0x02; /* SLAP_C_USED */
+
+ c->c_ssf = c->c_transport_ssf = 0;
+ c->c_tls_ssf = 0;
+
+ backend_connection_init( c );
+
+ pConn->c_send_ldap_result = internal_result_v3;
+ pConn->c_send_search_entry = internal_search_entry;
+ pConn->c_send_search_result = internal_search_result;
+ pConn->c_send_ldap_extended = internal_result_ext;
+ pConn->c_send_search_reference = internal_search_reference;
+
+ return pConn;
+}
+
+/*
+ * Function : values2obj
+ * Convert an array of strings into a BerVarray.
+ * the strings.
+ */
+static int
+values2obj(
+ char **ppValue,
+ BerVarray *bvobj)
+{
+ int rc = LDAP_SUCCESS;
+ int i;
+ BerVarray tmpberval;
+
+ if ( ppValue == NULL ) {
+ *bvobj = NULL;
+ return LDAP_SUCCESS;
+ }
+
+ for ( i = 0; ppValue[i] != NULL; i++ )
+ ;
+
+ tmpberval = (BerVarray)slapi_ch_malloc( (i+1) * (sizeof(struct berval)) );
+ if ( tmpberval == NULL ) {
+ return LDAP_NO_MEMORY;
+ }
+ for ( i = 0; ppValue[i] != NULL; i++ ) {
+ tmpberval[i].bv_val = ppValue[i];
+ tmpberval[i].bv_len = strlen( ppValue[i] );
+ }
+ tmpberval[i].bv_val = NULL;
+ tmpberval[i].bv_len = 0;
+
+ *bvobj = tmpberval;
+
+ return LDAP_SUCCESS;
+}
+
+static void
+freeMods( Modifications *ml )
+{
+ /*
+ * Free a modification list whose values have been
+ * set with bvptr2obj() or values2obj() (ie. they
+ * do not own the pointer to the underlying values)
+ */
+ Modifications *next;
+
+ for ( ; ml != NULL; ml = next ) {
+ next = ml->sml_next;
+
+ slapi_ch_free( (void **)&ml->sml_bvalues );
+ slapi_ch_free( (void **)&ml );
+ }
+}
+
+/*
+ * Function : LDAPModToEntry
+ * convert a dn plus an array of LDAPMod struct ptrs to an entry structure
+ * with a link list of the correspondent attributes.
+ * Return value : LDAP_SUCCESS
+ * LDAP_NO_MEMORY
+ * LDAP_OTHER
+*/
+Entry *
+LDAPModToEntry(
+ char *ldn,
+ LDAPMod **mods )
+{
+ struct berval dn = { 0, NULL };
+ Entry *pEntry=NULL;
+ LDAPMod *pMod;
+ struct berval *bv;
+ Backend *be;
+ Operation *op;
+
+ Modifications *modlist = NULL;
+ Modifications **modtail = &modlist;
+ Modifications tmp;
+
+ int rc = LDAP_SUCCESS;
+ int i;
+
+ const char *text = NULL;
+
+
+ op = (Operation *) slapi_ch_calloc(1, sizeof(Operation));
+ if ( pEntry == NULL) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+ op->o_tag = LDAP_REQ_ADD;
+
+ pEntry = (Entry *) ch_calloc( 1, sizeof(Entry) );
+ if ( pEntry == NULL) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ dn.bv_val = slapi_ch_strdup(ldn);
+ dn.bv_len = strlen(ldn);
+
+ rc = dnPrettyNormal( NULL, &dn, &pEntry->e_name, &pEntry->e_nname );
+ if (rc != LDAP_SUCCESS) goto cleanup;
+
+ if ( rc == LDAP_SUCCESS ) {
+ for ( i=0, pMod=mods[0]; rc == LDAP_SUCCESS && pMod != NULL; pMod=mods[++i]) {
+ Modifications *mod;
+ if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
+ /* attr values are in berval format */
+ /* convert an array of pointers to bervals to an array of bervals */
+ rc = bvptr2obj(pMod->mod_bvalues, &bv);
+ if (rc != LDAP_SUCCESS) goto cleanup;
+ tmp.sml_type.bv_val = pMod->mod_type;
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );
+ tmp.sml_bvalues = bv;
+
+ mod = (Modifications *) ch_malloc( sizeof(Modifications) );
+
+ mod->sml_op = LDAP_MOD_ADD;
+ mod->sml_next = NULL;
+ mod->sml_desc = NULL;
+ mod->sml_type = tmp.sml_type;
+ mod->sml_bvalues = tmp.sml_bvalues;
+
+ *modtail = mod;
+ modtail = &mod->sml_next;
+
+ } else {
+ /* attr values are in string format, need to be converted */
+ /* to an array of bervals */
+ if ( pMod->mod_values == NULL ) {
+ rc = LDAP_OTHER;
+ } else {
+ rc = values2obj( pMod->mod_values, &bv );
+ if (rc != LDAP_SUCCESS) goto cleanup;
+ tmp.sml_type.bv_val = pMod->mod_type;
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );
+ tmp.sml_bvalues = bv;
+
+ mod = (Modifications *) ch_malloc( sizeof(Modifications) );
+
+ mod->sml_op = LDAP_MOD_ADD;
+ mod->sml_next = NULL;
+ mod->sml_desc = NULL;
+ mod->sml_type = tmp.sml_type;
+ mod->sml_bvalues = tmp.sml_bvalues;
+
+ *modtail = mod;
+ modtail = &mod->sml_next;
+ }
+ }
+ } /* for each LDAPMod */
+ }
+
+ be = select_backend(&pEntry->e_nname, 0, 0);
+ if ( be == NULL ) {
+ rc = LDAP_PARTIAL_RESULTS;
+ goto cleanup;
+ }
+
+ if ( be ) {
+ int repl_user = be_isupdate(be, &be->be_rootdn );
+ if ( !be->be_update_ndn.bv_len || repl_user ) {
+ int update = be->be_update_ndn.bv_len;
+ char textbuf[SLAP_TEXT_BUFLEN];
+ size_t textlen = sizeof textbuf;
+
+ rc = slap_mods_check( modlist, update, &text,
+ textbuf, textlen );
+ if ( rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+
+ if ( !repl_user ) {
+ rc = slap_mods_opattrs( be, op,
+ modlist, modtail, &text,
+ textbuf, textlen );
+ if ( rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+ }
+
+ /*
+ * FIXME: slap_mods2entry is declared static
+ * in servers/slapd/add.c
+ */
+ rc = slap_mods2entry( modlist, &pEntry, repl_user,
+ &text, textbuf, textlen );
+ if (rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+
+ } else {
+ rc = LDAP_REFERRAL;
+ }
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+
+ if ( dn.bv_val ) slapi_ch_free( (void **)&dn.bv_val );
+ if ( op ) slapi_ch_free( (void **)&op );
+ if ( modlist != NULL ) freeMods( modlist );
+ if ( rc != LDAP_SUCCESS ) {
+ if ( pEntry != NULL ) {
+ slapi_entry_free( pEntry );
+ }
+ pEntry = NULL;
+ }
+
+ return( pEntry );
+}
+
+/* Function : slapi_delete_internal
+ *
+ * Description : Plugin functions call this routine to delete an entry
+ * in the backend directly
+ * Return values : LDAP_SUCCESS
+ * LDAP_PARAM_ERROR
+ * LDAP_NO_MEMORY
+ * LDAP_OTHER
+ * LDAP_UNWILLING_TO_PERFORM
+*/
+Slapi_PBlock *
+slapi_delete_internal(
+ char *ldn,
+ LDAPControl **controls,
+ int log_change )
+{
+#if defined(LDAP_SLAPI)
+ Backend *be;
+ Connection *pConn = NULL;
+ Operation *op = NULL;
+ Slapi_PBlock *pPB = NULL;
+ Slapi_PBlock *pSavePB = NULL;
+
+ struct berval dn = { 0, NULL };
+ struct berval pdn = { 0, NULL };
+ struct berval ndn = { 0, NULL };
+
+ int rc=LDAP_SUCCESS;
+ int manageDsaIt = 0;
+ int isCritical;
+
+ if ( ldn == NULL ) {
+ rc = LDAP_PARAM_ERROR;
+ goto cleanup;
+ }
+
+ pConn = fakeConnection( NULL, LDAP_REQ_DELETE );
+ if (pConn == NULL) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ op = (Operation *)pConn->c_pending_ops.stqh_first;
+ pPB = (Slapi_PBlock *)op->o_pb;
+ op->o_ctrls = controls;
+
+ dn.bv_val = slapi_ch_strdup(ldn);
+ dn.bv_len = slapi_strlen(ldn);
+ rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+
+ if ( slapi_control_present( controls,
+ SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical) ) {
+ manageDsaIt = 1;
+ }
+
+ be = select_backend( &ndn, manageDsaIt, 0 );
+ if ( be == NULL ) {
+ rc = LDAP_PARTIAL_RESULTS;
+ goto cleanup;
+ }
+
+ op->o_dn = pConn->c_dn = be->be_rootdn;
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;
+
+ suffix_alias( be, &ndn );
+
+ if ( be->be_delete ) {
+ int repl_user = be_isupdate( be, &op->o_ndn );
+ if ( !be->be_update_ndn.bv_len || repl_user ) {
+ rc = (*be->be_delete)( be, pConn, op, &pdn, &ndn );
+ if ( rc == 0 ) {
+ if (log_change) {
+ replog( be, op, &pdn, &ndn, NULL );
+ }
+ rc = LDAP_SUCCESS;
+ } else {
+ rc = LDAP_OPERATIONS_ERROR;
+ }
+ } else {
+ rc = LDAP_REFERRAL;
+ }
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+ if (pPB != NULL)
+ slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+
+ if (dn.bv_val) slapi_ch_free( (void **)&dn.bv_val );
+ if (pdn.bv_val) slapi_ch_free( (void **)&pdn.bv_val );
+ if (ndn.bv_val) slapi_ch_free( (void **)&ndn.bv_val );
+
+ if ( pConn != NULL ) {
+ if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
+ if ( op ) slapi_ch_free( (void **)&op );
+ pSavePB = pPB;
+ free( pConn );
+ }
+
+ return (pSavePB);
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+Slapi_PBlock *
+slapi_add_entry_internal(
+ Slapi_Entry *e,
+ LDAPControl **controls,
+ int log_changes )
+{
+#if defined(LDAP_SLAPI)
+ Connection *pConn = NULL;
+ Operation *op = NULL;
+ Slapi_PBlock *pPB = NULL, *pSavePB = NULL;
+ Backend *be;
+
+ int manageDsaIt = 0;
+ int isCritical;
+ int rc = LDAP_SUCCESS;
+
+ if ( e == NULL ) {
+ rc = LDAP_PARAM_ERROR;
+ goto cleanup;
+ }
+
+ pConn = fakeConnection( NULL, LDAP_REQ_ADD );
+ if ( pConn == NULL ) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ if ( slapi_control_present( controls, LDAP_CONTROL_MANAGEDSAIT,
+ NULL, &isCritical ) ) {
+ manageDsaIt = 1;
+ }
+
+ op = (Operation *)pConn->c_pending_ops.stqh_first;
+ pPB = (Slapi_PBlock *)op->o_pb;
+ op->o_ctrls = controls;
+
+ be = select_backend( &e->e_nname, manageDsaIt, 0 );
+ if ( be == NULL ) {
+ rc = LDAP_PARTIAL_RESULTS;
+ goto cleanup;
+ }
+
+ op->o_dn = pConn->c_dn = be->be_rootdn;
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;
+
+ if ( be->be_add ) {
+ int repl_user = be_isupdate( be, &op->o_ndn );
+ if ( !be->be_update_ndn.bv_len || repl_user ){
+ if ( (*be->be_add)( be, pConn, op, e ) == 0 ) {
+ if ( log_changes ) {
+ replog( be, op, &e->e_name,
+ &e->e_nname, e );
+ }
+ rc = LDAP_SUCCESS;
+ }
+ } else {
+ rc = LDAP_REFERRAL;
+ }
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+
+ if ( pPB != NULL ) {
+ slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+ }
+
+ if ( pConn != NULL ) {
+ if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
+ if ( op != NULL ) slapi_ch_free( (void **)&op );
+ pSavePB = pPB;
+ free( pConn );
+ }
+ return( pSavePB );
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+
+Slapi_PBlock *
+slapi_add_internal(
+ char *dn,
+ LDAPMod **mods,
+ LDAPControl **controls,
+ int log_changes )
+{
+#if defined(LDAP_SLAPI)
+ LDAPMod *pMod = NULL;
+ Slapi_PBlock *pb = NULL;
+ Entry *pEntry = NULL;
+ int i, rc=LDAP_SUCCESS;
+
+ if ( mods == NULL || *mods == NULL || dn == NULL || *dn == '\0' ) {
+ rc = LDAP_PARAM_ERROR ;
+ }
+
+ if ( rc == LDAP_SUCCESS ) {
+ for ( i = 0, pMod = mods[0]; pMod != NULL; pMod = mods[++i] ) {
+ if ( (pMod->mod_op & ~LDAP_MOD_BVALUES) != LDAP_MOD_ADD ) {
+ rc = LDAP_OTHER;
+ break;
+ }
+ }
+ }
+
+ if ( rc == LDAP_SUCCESS ) {
+ if((pEntry = LDAPModToEntry( dn, mods )) == NULL) {
+ rc = LDAP_OTHER;
+ }
+ }
+
+ if ( rc != LDAP_SUCCESS ) {
+ pb = slapi_pblock_new();
+ slapi_pblock_set( pb, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+ } else {
+ pb = slapi_add_entry_internal( pEntry, controls, log_changes );
+ }
+
+ if ( pEntry ) {
+ slapi_entry_free(pEntry);
+ }
+
+ return(pb);
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+/* Function : slapi_modrdn_internal
+ *
+ * Description : Plugin functions call this routine to modify the rdn
+ * of an entry in the backend directly
+ * Return values : LDAP_SUCCESS
+ * LDAP_PARAM_ERROR
+ * LDAP_OPERATIONS_ERROR
+ * LDAP_NO_MEMORY
+ * LDAP_OTHER
+ * LDAP_UNWILLING_TO_PERFORM
+ *
+ * NOTE: This function does not support the "newSuperior" option from LDAP V3.
+ */
+Slapi_PBlock *
+slapi_modrdn_internal(
+ char *olddn,
+ char *lnewrdn,
+ int deloldrdn,
+ LDAPControl **controls,
+ int log_change )
+{
+#if defined(LDAP_SLAPI)
+ int rc = LDAP_SUCCESS;
+
+ struct berval dn = { 0, NULL };
+ struct berval pdn = { 0, NULL };
+ struct berval ndn = { 0, NULL };
+
+ struct berval newrdn = { 0, NULL };
+ struct berval pnewrdn = { 0, NULL };
+ struct berval nnewrdn = { 0, NULL };
+
+#if 0 /* currently unused */
+ struct berval newSuperior = { 0, NULL };
+#endif
+ struct berval pnewSuperior = { 0, NULL };
+#if 0 /* currently unused */
+ struct berval nnewSuperior = { 0, NULL };
+#endif
+
+ struct berval *pnewS = NULL;
+ struct berval *nnewS = NULL;
+
+ Connection *pConn = NULL;
+ Operation *op = NULL;
+ Slapi_PBlock *pPB = NULL;
+ Slapi_PBlock *pSavePB = NULL;
+
+ Backend *be;
+#if 0 /* currently unused */
+ Backend *newSuperior_be = NULL;
+#endif
+
+ int manageDsaIt = 0;
+ int isCritical;
+#if 0 /* currently unused */
+ const char *text = NULL;
+#endif
+
+ dn.bv_val = slapi_ch_strdup(olddn);
+ dn.bv_len = slapi_ch_stlen(olddn);
+
+ rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
+
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+
+ if ( ndn.bv_len == 0 ) {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ goto cleanup;
+ }
+
+ newrdn.bv_val = slapi_ch_strdup( lnewrdn );
+ newrdn.bv_len = slapi_ch_stlen( lnewrdn );
+
+ rc = dnPrettyNormal( NULL, &newrdn, &pnewrdn, &nnewrdn );
+
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+
+ if ( rdnValidate( &pnewrdn ) != LDAP_SUCCESS ) goto cleanup;
+
+ pConn = fakeConnection( NULL, LDAP_REQ_MODRDN);
+ if ( pConn == NULL) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ op = (Operation *)pConn->c_pending_ops.stqh_first;
+ pPB = (Slapi_PBlock *)op->o_pb;
+ op->o_ctrls = controls;
+
+ if ( slapi_control_present( controls,
+ SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
+ manageDsaIt = 1;
+ }
+
+ be = select_backend( &ndn, manageDsaIt, 0 );
+ if ( be == NULL ) {
+ rc = LDAP_PARTIAL_RESULTS;
+ goto cleanup;
+ }
+
+ op->o_dn = pConn->c_dn = be->be_rootdn;
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;
+
+ suffix_alias( be, &ndn );
+
+ if ( be->be_modrdn ) {
+ int repl_user = be_isupdate( be, &op->o_ndn );
+ if ( !be->be_update_ndn.bv_len || repl_user ) {
+ rc = (*be->be_modrdn)( be, pConn, op, &pdn, &ndn,
+ &pnewrdn, &nnewrdn, deloldrdn, pnewS,
+ nnewS );
+ if ( rc == 0 ) {
+ struct slap_replog_moddn moddn;
+ moddn.newrdn = &pnewrdn;
+ moddn.deloldrdn = deloldrdn;
+ moddn.newsup = &pnewSuperior;
+ if ( log_change ) {
+ replog( be, op, &pdn, &ndn, &moddn );
+ }
+ rc = LDAP_SUCCESS;
+
+ } else {
+ rc = LDAP_OPERATIONS_ERROR;
+ }
+
+ } else {
+ rc = LDAP_REFERRAL;
+ }
+
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+
+ if ( pPB != NULL ) {
+ slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+ }
+
+ if ( dn.bv_val ) ch_free( dn.bv_val );
+ if ( pdn.bv_val ) ch_free( pdn.bv_val );
+ if ( ndn.bv_val ) ch_free( ndn.bv_val );
+
+ if ( newrdn.bv_val ) ch_free( newrdn.bv_val );
+ if ( pnewrdn.bv_val ) ch_free( newrdn.bv_val );
+ if ( nnewrdn.bv_val ) ch_free( newrdn.bv_val );
+
+ if ( pConn != NULL ) {
+ if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
+ if ( op != NULL ) slapi_ch_free( (void **)&op );
+ pSavePB = pPB;
+ free( pConn );
+ }
+
+ return( pSavePB );
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+/* Function : slapi_modify_internal
+ *
+ * Description: Plugin functions call this routine to modify an entry
+ * in the backend directly
+ * Return values : LDAP_SUCCESS
+ * LDAP_PARAM_ERROR
+ * LDAP_NO_MEMORY
+ * LDAP_OPERATIONS_ERROR
+ * LDAP_OTHER
+ * LDAP_UNWILLING_TO_PERFORM
+*/
+Slapi_PBlock *
+slapi_modify_internal(
+ char *ldn,
+ LDAPMod **mods,
+ LDAPControl **controls,
+ int log_change )
+{
+#if defined(LDAP_SLAPI)
+ int i, rc = LDAP_SUCCESS;
+ Connection *pConn = NULL;
+ Operation *op = NULL;
+ Slapi_PBlock *pPB = NULL;
+ Slapi_PBlock *pSavePB = NULL;
+
+ struct berval dn = { 0, NULL };
+ struct berval pdn = { 0, NULL };
+ struct berval ndn = { 0, NULL };
+
+ int manageDsaIt = 0;
+ int isCritical;
+ Backend *be;
+ struct berval *bv;
+ LDAPMod *pMod;
+
+ Modifications *modlist = NULL;
+ Modifications **modtail = &modlist;
+ Modifications tmp;
+
+ if ( mods == NULL || *mods == NULL || ldn == NULL ) {
+ rc = LDAP_PARAM_ERROR ;
+ goto cleanup;
+ }
+
+ pConn = fakeConnection( NULL, LDAP_REQ_MODIFY );
+ if ( pConn == NULL ) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ op = (Operation *)pConn->c_pending_ops.stqh_first;
+ pPB = (Slapi_PBlock *)op->o_pb;
+ op->o_ctrls = controls;
+
+ dn.bv_val = slapi_ch_strdup( ldn );
+ dn.bv_len = slapi_strlen( ldn );
+ rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+
+ if ( slapi_control_present( controls,
+ SLAPI_CONTROL_MANAGEDSAIT_OID, NULL, &isCritical ) ) {
+ manageDsaIt = 1;
+ }
+
+ be = select_backend( &ndn, manageDsaIt, 0 );
+ if ( be == NULL ) {
+ rc = LDAP_PARTIAL_RESULTS;
+ goto cleanup;
+ }
+
+ op->o_dn = pConn->c_dn = be->be_rootdn;
+ op->o_ndn = pConn->c_ndn = be->be_rootndn;
+
+ suffix_alias( be, &ndn );
+
+ for ( i = 0, pMod = mods[0]; rc == LDAP_SUCCESS && pMod != NULL;
+ pMod = mods[++i] ) {
+ Modifications *mod;
+ if ( (pMod->mod_op & LDAP_MOD_BVALUES) != 0 ) {
+ /*
+ * attr values are in berval format
+ * convert an array of pointers to bervals
+ * to an array of bervals
+ */
+ rc = bvptr2obj( pMod->mod_bvalues, &bv );
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+ tmp.sml_type.bv_val = pMod->mod_type;
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );
+ tmp.sml_bvalues = bv;
+
+ mod = (Modifications *)ch_malloc( sizeof(Modifications) );
+
+ mod->sml_op = pMod->mod_op;
+ mod->sml_next = NULL;
+ mod->sml_desc = NULL;
+ mod->sml_type = tmp.sml_type;
+ mod->sml_bvalues = tmp.sml_bvalues;
+ } else {
+ rc = values2obj( pMod->mod_values, &bv );
+ if ( rc != LDAP_SUCCESS ) goto cleanup;
+ tmp.sml_type.bv_val = pMod->mod_type;
+ tmp.sml_type.bv_len = strlen( pMod->mod_type );
+ tmp.sml_bvalues = bv;
+
+ mod = (Modifications *) ch_malloc( sizeof(Modifications) );
+
+ mod->sml_op = pMod->mod_op;
+ mod->sml_next = NULL;
+ mod->sml_desc = NULL;
+ mod->sml_type = tmp.sml_type;
+ mod->sml_bvalues = tmp.sml_bvalues;
+ }
+ *modtail = mod;
+ modtail = &mod->sml_next;
+
+ switch( pMod->mod_op ) {
+ case LDAP_MOD_ADD:
+ if ( mod->sml_bvalues == NULL ) {
+ rc = LDAP_PROTOCOL_ERROR;
+ goto cleanup;
+ }
+
+ /* fall through */
+ case LDAP_MOD_DELETE:
+ case LDAP_MOD_REPLACE:
+ break;
+
+ default:
+ rc = LDAP_PROTOCOL_ERROR;
+ goto cleanup;
+ }
+ }
+ *modtail = NULL;
+
+ if ( ndn.bv_len == 0 ) {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ goto cleanup;
+ }
+
+ if ( be->be_modify ) {
+ int repl_user = be_isupdate( be, &op->o_ndn );
+ if ( !be->be_update_ndn.bv_len || repl_user ) {
+ int update = be->be_update_ndn.bv_len;
+ const char *text = NULL;
+ char textbuf[SLAP_TEXT_BUFLEN];
+ size_t textlen = sizeof( textbuf );
+
+ rc = slap_mods_check( modlist, update,
+ &text, textbuf, textlen );
+ if (rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+
+ if ( !repl_user ) {
+ rc = slap_mods_opattrs( be, op, modlist,
+ modtail, &text, textbuf,
+ textlen );
+ if (rc != LDAP_SUCCESS) {
+ goto cleanup;
+ }
+ }
+ rc = (*be->be_modify)( be, pConn, op,
+ &pdn, &ndn, modlist );
+ if ( rc == 0 ) {
+ if ( log_change ) {
+ replog( be, op, &pdn, &ndn, modlist );
+ }
+ rc = LDAP_SUCCESS;
+ } else {
+ rc = LDAP_OPERATIONS_ERROR;
+ }
+ } else {
+ rc = LDAP_REFERRAL;
+ }
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+
+ if ( pPB != NULL )
+ slapi_pblock_set( pPB, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+
+ if ( dn.bv_val ) ch_free( dn.bv_val );
+ if ( pdn.bv_val ) ch_free( pdn.bv_val );
+ if ( ndn.bv_val ) ch_free( ndn.bv_val );
+
+ if ( modlist != NULL ) freeMods( modlist );
+
+ if ( pConn != NULL ) {
+ if ( pConn->c_sb != NULL ) ber_sockbuf_free( pConn->c_sb );
+ if ( op != NULL ) slapi_ch_free( (void **)&op );
+ pSavePB = pPB;
+ free( pConn );
+ }
+
+ return ( pSavePB );
+
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+Slapi_PBlock *
+slapi_search_internal_bind(
+ char *bindDN,
+ char *ldn,
+ int scope,
+ char *filStr,
+ LDAPControl **controls,
+ char **attrs,
+ int attrsonly )
+{
+#if defined(LDAP_SLAPI)
+ Backend *be;
+ Connection *c;
+ Operation *op = NULL;
+ Slapi_PBlock *ptr = NULL;
+ Slapi_PBlock *pSavePB = NULL;
+ struct berval dn = { 0, NULL };
+ struct berval pdn = { 0, NULL };
+ struct berval ndn = { 0, NULL };
+ Filter *filter=NULL;
+ struct berval fstr = { 0, NULL };
+ AttributeName *an = NULL;
+ const char *text = NULL;
+
+ int deref=0;
+ int sizelimit=-1, timelimit=-1;
+
+ int manageDsaIt = 0;
+ int isCritical;
+
+ int i, rc = LDAP_SUCCESS;
+
+ c = fakeConnection( NULL, LDAP_REQ_SEARCH );
+ if (c == NULL) {
+ rc = LDAP_NO_MEMORY;
+ goto cleanup;
+ }
+
+ op = (Operation *)c->c_pending_ops.stqh_first;
+ ptr = (Slapi_PBlock *)op->o_pb;
+ op->o_ctrls = controls;
+
+ dn.bv_val = slapi_ch_strdup(ldn);
+ dn.bv_len = slapi_strlen(ldn);
+
+ rc = dnPrettyNormal( NULL, &dn, &pdn, &ndn );
+ if (rc != LDAP_SUCCESS) goto cleanup;
+
+ if ( scope != LDAP_SCOPE_BASE &&
+ scope != LDAP_SCOPE_ONELEVEL &&
+ scope != LDAP_SCOPE_SUBTREE ) {
+ rc = LDAP_PROTOCOL_ERROR;
+ goto cleanup;
+ }
+
+ filter = slapi_str2filter(filStr);
+ if ( filter == NULL ) {
+ rc = LDAP_PROTOCOL_ERROR;
+ goto cleanup;
+ }
+
+ filter2bv( filter, &fstr );
+
+ for ( i = 0; attrs != NULL && attrs[i] != NULL; i++ ) {
+ ; /* count the number of attributes */
+ }
+
+ if (i > 0) {
+ an = (AttributeName *)slapi_ch_calloc( (i + 1), sizeof(AttributeName) );
+ for (i = 0; attrs[i] != 0; i++) {
+ an[i].an_desc = NULL;
+ an[i].an_oc = NULL;
+ an[i].an_name.bv_val = slapi_ch_strdup(attrs[i]);
+ an[i].an_name.bv_len = slapi_strlen(attrs[i]);
+ slap_bv2ad( &an[i].an_name, &an[i].an_desc, &text );
+ }
+ an[i].an_name.bv_val = NULL;
+ }
+
+ if ( scope == LDAP_SCOPE_BASE ) {
+ Entry *entry = NULL;
+
+ if ( ndn.bv_len == 0 ) {
+ rc = root_dse_info( c, &entry, &text );
+ }
+
+ if( rc != LDAP_SUCCESS ) {
+ send_ldap_result( c, op, rc, NULL, text, NULL, NULL );
+ goto cleanup;
+ } else if ( entry != NULL ) {
+ rc = test_filter( NULL, c, op, entry, filter );
+
+ if( rc == LDAP_COMPARE_TRUE ) {
+ send_search_entry( NULL, c, op, entry,
+ an, attrsonly, NULL );
+ }
+
+ entry_free( entry );
+
+ send_ldap_result( c, op, LDAP_SUCCESS,
+ NULL, NULL, NULL, NULL );
+
+ rc = LDAP_SUCCESS;
+
+ goto cleanup;
+ }
+ }
+
+ if ( !ndn.bv_len && default_search_nbase.bv_len ) {
+ ch_free( pdn.bv_val );
+ ch_free( ndn.bv_val );
+
+ ber_dupbv( &pdn, &default_search_base );
+ ber_dupbv( &ndn, &default_search_nbase );
+ }
+
+ if ( slapi_control_present( controls,
+ LDAP_CONTROL_MANAGEDSAIT, NULL, &isCritical ) ) {
+ manageDsaIt = 1;
+ }
+
+ be = select_backend( &ndn, manageDsaIt, 0 );
+ if ( be == NULL ) {
+ if ( manageDsaIt == 1 ) {
+ rc = LDAP_NO_SUCH_OBJECT;
+ } else {
+ rc = LDAP_PARTIAL_RESULTS;
+ }
+ goto cleanup;
+ }
+
+ op->o_dn = c->c_dn = be->be_rootdn;
+ op->o_ndn = c->c_ndn = be->be_rootndn;
+
+ if ( be->be_search ) {
+ rc = (*be->be_search)( be, c, op, &pdn, &ndn,
+ scope, deref, sizelimit, timelimit,
+ filter, &fstr, an, attrsonly );
+ if ( rc == 0 ) {
+ rc = LDAP_SUCCESS;
+ } else {
+ rc = LDAP_OPERATIONS_ERROR;
+ }
+ } else {
+ rc = LDAP_UNWILLING_TO_PERFORM;
+ }
+
+cleanup:
+
+ if ( ptr != NULL )
+ slapi_pblock_set( ptr, SLAPI_PLUGIN_INTOP_RESULT, (void *)rc );
+
+ if ( dn.bv_val ) free( dn.bv_val );
+ if ( ndn.bv_val ) free( ndn.bv_val );
+ if ( pdn.bv_val ) free( pdn.bv_val );
+
+ if ( filter ) slapi_filter_free( filter, 1 );
+ if ( fstr.bv_val ) free ( fstr.bv_val );
+
+ if ( an != NULL ) free( an );
+
+ if ( c != NULL ) {
+ if ( c->c_sb != NULL ) ber_sockbuf_free( c->c_sb );
+ if ( op != NULL ) slapi_ch_free( (void **)&op );
+ pSavePB = ptr;
+ free( c );
+ }
+ return( pSavePB );
+#endif /* LDAP_SLAPI */
+ return NULL;
+}
+
+Slapi_PBlock *
+slapi_search_internal(
+ char *base,
+ int scope,
+ char *filStr,
+ LDAPControl **controls,
+ char **attrs,
+ int attrsonly )
+{
+#if defined(LDAP_SLAPI)
+ return slapi_search_internal_bind( NULL, base, scope, filStr,
+ controls, attrs, attrsonly );
+#else
+ return NULL;
+#endif /* LDAP_SLAPI */
+}
+