~ubuntu-branches/ubuntu/raring/389-ds-base/raring

« back to all changes in this revision

Viewing changes to ldap/servers/slapd/dse.c

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-02-06 18:06:31 UTC
  • mfrom: (11.1.1 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20130206180631-h6ldv3k506hmm46e
Tags: 1.3.0.2-0ubuntu2
debian/*: Fix time stamps due to clock skew (FTBFS).

Show diffs side-by-side

added added

removed removed

Lines of Context:
651
651
        slapi_sdn_done(&parent);
652
652
}
653
653
 
 
654
/* check if a file is valid, or if a provided backup file can be used.
 
655
 * there is no way to determine if the file contents is usable, the only
 
656
 * checks that can be done is that the file exists and that it is not size 0
 
657
 */
 
658
int
 
659
dse_check_file(char *filename, char *backupname)
 
660
{
 
661
    int rc= 0; /* Fail */
 
662
    PRFileInfo prfinfo;
 
663
 
 
664
    if (PR_GetFileInfo( filename, &prfinfo ) == PR_SUCCESS) {
 
665
        if ( prfinfo.size > 0)
 
666
                return (1);
 
667
        else {
 
668
                rc = PR_Delete (filename);
 
669
        }
 
670
    }
 
671
 
 
672
    if (backupname) 
 
673
        rc = PR_Rename (backupname, filename);
 
674
    else 
 
675
        return (0);
 
676
 
 
677
    if ( PR_GetFileInfo( filename, &prfinfo ) == PR_SUCCESS && prfinfo.size > 0 ) {
 
678
        slapi_log_error(SLAPI_LOG_FATAL, "dse",
 
679
             "The configuration file %s was restored from backup %s\n", filename, backupname);
 
680
        return (1);
 
681
    } else {
 
682
        slapi_log_error(SLAPI_LOG_FATAL, "dse",
 
683
              "The configuration file %s was not restored from backup %s, error %d\n",
 
684
                                    filename, backupname, rc);
 
685
        return (0);
 
686
   }
 
687
}
654
688
static int
655
689
dse_read_one_file(struct dse *pdse, const char *filename, Slapi_PBlock *pb,
656
690
        int primary_file )
669
703
 
670
704
    if ( (NULL != pdse) && (NULL != filename) )
671
705
    {
672
 
        if ( (rc = PR_GetFileInfo( filename, &prfinfo )) != PR_SUCCESS )
673
 
        {
674
 
            /* the "real" file does not exist; see if there is a tmpfile */
675
 
            if ( pdse->dse_tmpfile &&
676
 
                 PR_GetFileInfo( pdse->dse_tmpfile, &prfinfo ) == PR_SUCCESS ) {
677
 
                rc = PR_Rename(pdse->dse_tmpfile, filename);
678
 
                if (rc == PR_SUCCESS) {
679
 
                    slapi_log_error(SLAPI_LOG_FATAL, "dse",
680
 
                                    "The configuration file %s was restored from backup %s\n",
681
 
                                    filename, pdse->dse_tmpfile);
682
 
                    rc = 1;
683
 
                } else {
684
 
                    slapi_log_error(SLAPI_LOG_FATAL, "dse",
685
 
                                    "The configuration file %s was not restored from backup %s, error %d\n",
686
 
                                    filename, pdse->dse_tmpfile, rc);
687
 
                    rc = 0;
688
 
                }
689
 
            } else {
690
 
                rc = 0; /* fail */
691
 
            }
692
 
        }
 
706
        /* check if the "real" file exists and cam be used, if not try tmp as backup */
 
707
        rc = dse_check_file((char *)filename, pdse->dse_tmpfile);
 
708
        if (!rc) 
 
709
            rc = dse_check_file((char *)filename, pdse->dse_fileback);
 
710
 
693
711
        if ( (rc = PR_GetFileInfo( filename, &prfinfo )) != PR_SUCCESS )
694
712
        {
695
713
            slapi_log_error(SLAPI_LOG_FATAL, "dse",
1967
1985
        /* next, give the betxn plugins a crack at it */
1968
1986
        slapi_pblock_set(pb, SLAPI_RESULT_CODE, &returncode);
1969
1987
        slapi_pblock_set(pb, SLAPI_MODIFY_EXISTING_ENTRY, ecc);
1970
 
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN);
1971
 
        if (!returncode) {
1972
 
            slapi_pblock_get(pb, SLAPI_RESULT_CODE, &returncode);
1973
 
        }
1974
 
        if (returncode && !returntext[0]) {
1975
 
            char *ldap_result_message = NULL;
1976
 
            slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
1977
 
            if (ldap_result_message && ldap_result_message[0]) {
1978
 
                PL_strncpyz(returntext, ldap_result_message, sizeof(returntext));
1979
 
            }
1980
 
        }
1981
1988
        if (need_be_postop) {
 
1989
            plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_MODIFY_FN);
 
1990
            if (!returncode) {
 
1991
                slapi_pblock_get(pb, SLAPI_RESULT_CODE, &returncode);
 
1992
            }
 
1993
            if (returncode && !returntext[0]) {
 
1994
                char *ldap_result_message = NULL;
 
1995
                slapi_pblock_get(pb, SLAPI_PB_RESULT_TEXT, &ldap_result_message);
 
1996
                if (ldap_result_message && ldap_result_message[0]) {
 
1997
                    PL_strncpyz(returntext, ldap_result_message, sizeof(returntext));
 
1998
                }
 
1999
            }
 
2000
 
1982
2001
            plugin_call_plugins(pb, SLAPI_PLUGIN_BE_POST_MODIFY_FN);
1983
2002
            if (!returncode) {
1984
2003
                slapi_pblock_get(pb, SLAPI_RESULT_CODE, &returncode);
2198
2217
            returncode = rc;
2199
2218
        }
2200
2219
    }
2201
 
    /* next, give the be txn plugins a crack at it */
2202
 
    slapi_pblock_set(pb, SLAPI_RESULT_CODE, &returncode);
2203
 
    plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN);
2204
2220
    if (need_be_postop) {
 
2221
        /* next, give the be txn plugins a crack at it */
 
2222
        slapi_pblock_set(pb, SLAPI_RESULT_CODE, &returncode);
 
2223
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_ADD_FN);
 
2224
 
2205
2225
        /* finally, give the be plugins a crack at it */
2206
2226
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_POST_ADD_FN);
2207
2227
        if (!returncode) {
2287
2307
    }
2288
2308
 
2289
2309
    if(dse_call_callback(pdse, pb, SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, ec, NULL, &returncode,returntext)==SLAPI_DSE_CALLBACK_OK) {
2290
 
        slapi_pblock_get(pb, SLAPI_DELETE_BEPREOP_ENTRY, &orig_entry);
2291
2310
        slapi_pblock_set(pb, SLAPI_DELETE_BEPREOP_ENTRY, ec);
2292
2311
        slapi_pblock_set(pb, SLAPI_RESULT_CODE, &returncode);
2293
2312
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN);
2306
2325
                }
2307
2326
            }
2308
2327
        }
2309
 
        slapi_pblock_set(pb, SLAPI_DELETE_BEPREOP_ENTRY, orig_entry);
 
2328
        /* Setting SLAPI_ENTRY_PRE_OP here,
 
2329
         * since some betxn postop may need the pre op entry. */
 
2330
        slapi_pblock_set(pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup(ec));
2310
2331
    } else {
2311
2332
        goto done;
2312
2333
    }
2313
2334
 
2314
2335
    dse_call_callback(pdse, pb, SLAPI_OPERATION_DELETE, DSE_FLAG_POSTOP, ec, NULL, &returncode, returntext);
2315
 
 done:
 
2336
done:
2316
2337
    slapi_pblock_get(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, &orig_entry);
2317
2338
    slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, ec);
2318
2339
    /* make sure OPRETURN and RESULT_CODE are set */
2325
2346
            returncode = rc;
2326
2347
        }
2327
2348
    }
2328
 
    plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN);
2329
 
    if (!returncode) {
2330
 
        slapi_pblock_get(pb, SLAPI_RESULT_CODE, &returncode);
2331
 
    }
2332
2349
    if (need_be_postop) {
 
2350
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_TXN_POST_DELETE_FN);
 
2351
        if (!returncode) {
 
2352
            slapi_pblock_get(pb, SLAPI_RESULT_CODE, &returncode);
 
2353
        }
 
2354
 
2333
2355
        /* finally, give the be plugins a crack at it */
2334
2356
        plugin_call_plugins(pb, SLAPI_PLUGIN_BE_POST_DELETE_FN);
2335
2357
        if (!returncode) {
2345
2367
    }
2346
2368
    slapi_pblock_set(pb, SLAPI_DELETE_BEPOSTOP_ENTRY, orig_entry);
2347
2369
    slapi_send_ldap_result( pb, returncode, NULL, returntext, 0, NULL );
2348
 
    if (ec) {
2349
 
        slapi_pblock_set( pb, SLAPI_ENTRY_PRE_OP, slapi_entry_dup( ec ));
2350
 
    }
2351
2370
    return dse_delete_return(returncode, ec);
2352
2371
}
2353
2372