| 1 |
/* init.c - initialize mdb backend */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2000-2024 The OpenLDAP Foundation. |
| 6 |
* All rights reserved. |
| 7 |
* |
| 8 |
* Redistribution and use in source and binary forms, with or without |
| 9 |
* modification, are permitted only as authorized by the OpenLDAP |
| 10 |
* Public License. |
| 11 |
* |
| 12 |
* A copy of this license is available in the file LICENSE in the |
| 13 |
* top-level directory of the distribution or, alternatively, at |
| 14 |
* <http://www.OpenLDAP.org/license.html>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#include "portable.h" |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <ac/string.h> |
| 21 |
|
| 22 |
#include "back-mdb.h" |
| 23 |
|
| 24 |
int mdb_next_id( BackendDB *be, MDB_cursor *mc, ID *out ) |
| 25 |
{ |
| 26 |
struct mdb_info *mdb = (struct mdb_info *) be->be_private; |
| 27 |
int rc; |
| 28 |
ID id = 0; |
| 29 |
MDB_val key; |
| 30 |
|
| 31 |
rc = mdb_cursor_get(mc, &key, NULL, MDB_LAST); |
| 32 |
|
| 33 |
switch(rc) { |
| 34 |
case MDB_NOTFOUND: |
| 35 |
rc = 0; |
| 36 |
*out = 1; |
| 37 |
break; |
| 38 |
case 0: |
| 39 |
memcpy( &id, key.mv_data, sizeof( id )); |
| 40 |
*out = ++id; |
| 41 |
break; |
| 42 |
|
| 43 |
default: |
| 44 |
Debug( LDAP_DEBUG_ANY, |
| 45 |
"=> mdb_next_id: get failed: %s (%d)\n", |
| 46 |
mdb_strerror(rc), rc ); |
| 47 |
goto done; |
| 48 |
} |
| 49 |
mdb->mi_nextid = *out; |
| 50 |
|
| 51 |
done: |
| 52 |
return rc; |
| 53 |
} |