1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/** BEGIN COPYRIGHT BLOCK
* Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
* Copyright (C) 2005 Red Hat, Inc.
* All rights reserved.
*
* License: GPL (version 3 or any later version).
* See LICENSE for details.
* END COPYRIGHT BLOCK **/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* 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.
*/
/* The functions in this file allow plugins to perform bulk import of data
comming over ldap connection. Note that the code will not work if
there is now active connection since import state is stored in the
connection extension */
#include "slap.h"
/* forward declarations */
static int process_bulk_import_op(Slapi_PBlock *pb, int state, Slapi_Entry *e);
/* This function initiates bulk import. The pblock must contain
SLAPI_LDIF2DB_GENERATE_UNIQUEID -- currently always set to TIME_BASED
SLAPI_CONNECTION -- connection over which bulk import is coming
SLAPI_BACKEND -- the backend being imported
or
SLAPI_TARGET_SDN that contains root of the imported area.
The function returns LDAP_SUCCESS or LDAP error code
*/
int
slapi_start_bulk_import(Slapi_PBlock *pb)
{
return (process_bulk_import_op(pb, SLAPI_BI_STATE_START, NULL));
}
/* This function stops bulk import. The pblock must contain
SLAPI_CONNECTION -- connection over which bulk import is coming
SLAPI_BACKEND -- the backend being imported
or
SLAPI_TARGET_SDN that contains root of the imported area.
The function returns LDAP_SUCCESS or LDAP error code
*/
int
slapi_stop_bulk_import(Slapi_PBlock *pb)
{
return (process_bulk_import_op(pb, SLAPI_BI_STATE_DONE, NULL));
}
/* This function adds an entry to the bulk import. The pblock must contain
SLAPI_CONNECTION -- connection over which bulk import is coming
SLAPI_BACKEND -- optional backend pointer; if missing computed based on entry dn
The function returns LDAP_SUCCESS or LDAP error code
*/
int
slapi_import_entry(Slapi_PBlock *pb, Slapi_Entry *e)
{
return (process_bulk_import_op(pb, SLAPI_BI_STATE_ADD, e));
}
static int
process_bulk_import_op(Slapi_PBlock *pb, int state, Slapi_Entry *e)
{
int rc;
Slapi_Backend *be = NULL;
Slapi_DN *target_sdn = NULL;
if (pb == NULL) {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op", "NULL pblock\n");
return LDAP_OPERATIONS_ERROR;
}
if (state == SLAPI_BI_STATE_ADD && e == NULL) {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op", "NULL entry\n");
return LDAP_OPERATIONS_ERROR;
}
slapi_pblock_get(pb, SLAPI_BACKEND, &be);
if (be == NULL) {
/* try to get dn to select backend */
if (e) {
target_sdn = slapi_entry_get_sdn(e);
} else {
slapi_pblock_get(pb, SLAPI_TARGET_SDN, &target_sdn);
if (NULL == target_sdn) {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op",
"NULL target sdn\n");
return LDAP_OPERATIONS_ERROR;
}
}
be = slapi_be_select(target_sdn);
if (be) {
if (state == SLAPI_BI_STATE_START && (!slapi_be_issuffix(be, target_sdn))) {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op",
"Wrong backend suffix\n");
return LDAP_OPERATIONS_ERROR;
}
slapi_pblock_set(pb, SLAPI_BACKEND, be);
} else {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op", "NULL backend\n");
return LDAP_OPERATIONS_ERROR;
}
}
if (be->be_wire_import == NULL) {
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op",
"Bulk import is not supported by this (%s) backend\n",
be->be_type);
return LDAP_NOT_SUPPORTED;
}
/* set required parameters */
slapi_pblock_set(pb, SLAPI_BULK_IMPORT_STATE, &state);
if (e)
slapi_pblock_set(pb, SLAPI_BULK_IMPORT_ENTRY, e);
rc = be->be_wire_import(pb);
if (rc != 0) {
/* The caller will free the entry (e), so we just
* leave it alone here. */
slapi_log_err(SLAPI_LOG_ERR, "process_bulk_import_op",
"Failed; error = %d\n", rc);
return LDAP_OPERATIONS_ERROR;
}
if (state == SLAPI_BI_STATE_DONE) {
slapi_be_set_flag(be, SLAPI_BE_FLAG_POST_IMPORT);
}
return LDAP_SUCCESS;
}
|