]> git.sur5r.net Git - openldap/blob - servers/slapd/back-mdb/nextid.c
Happy New Year!
[openldap] / servers / slapd / back-mdb / nextid.c
1 /* init.c - initialize mdb backend */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 2000-2012 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         int rc;
27         ID id = 0;
28         MDB_val key;
29
30         rc = mdb_cursor_get(mc, &key, NULL, MDB_LAST);
31
32         switch(rc) {
33         case MDB_NOTFOUND:
34                 rc = 0;
35                 *out = 1;
36                 break;
37         case 0:
38                 memcpy( &id, key.mv_data, sizeof( id ));
39                 *out = ++id;
40                 break;
41
42         default:
43                 Debug( LDAP_DEBUG_ANY,
44                         "=> mdb_next_id: get failed: %s (%d)\n",
45                         mdb_strerror(rc), rc, 0 );
46                 goto done;
47         }
48
49 done:
50         return rc;
51 }