idmap_autorid: add a comment explaining idmap_autorid_init_hwm()
[amitay/samba.git] / source3 / include / idmap_autorid_tdb.h
1 /*
2  *  idmap_autorid: static map between Active Directory/NT RIDs
3  *  and RFC 2307 accounts. This file contains common functions
4  *  and structures used by idmap_autorid and net idmap autorid utilities
5  *
6  *  Copyright (C) Christian Ambach, 2010-2012
7  *  Copyright (C) Atul Kulkarni, 2013
8  *  Copyright (C) Michael Adam, 2012-2013
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 3 of the License, or
13  *  (at your option) any later version.
14  *
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 #ifndef _IDMAP_AUTORID_H_
26 #define _IDMAP_AUTORID_H_
27
28 #include "includes.h"
29 #include "system/filesys.h"
30 #include "dbwrap/dbwrap.h"
31 #include "dbwrap/dbwrap_open.h"
32 #include "../lib/util/util_tdb.h"
33 #include "winbindd/idmap_tdb_common.h"
34
35 #define HWM "NEXT RANGE"
36 #define ALLOC_HWM_UID "NEXT ALLOC UID"
37 #define ALLOC_HWM_GID "NEXT ALLOC GID"
38 #define ALLOC_RANGE "ALLOC"
39 #define CONFIGKEY "CONFIG"
40
41 struct autorid_global_config {
42         uint32_t minvalue;
43         uint32_t rangesize;
44         uint32_t maxranges;
45 };
46
47 struct autorid_range_config {
48         fstring domsid;
49         uint32_t rangenum;
50         uint32_t domain_range_index;
51         uint32_t low_id;
52 };
53
54 /**
55  * Get the range for a pair consisting of the domain sid
56  * and a domain range. If there is no stored range for
57  * this pair and read_only == false, a new range is
58  * acquired by incrementing that range HWM counter in the
59  * database.
60  */
61 NTSTATUS idmap_autorid_get_domainrange(struct db_context *db,
62                                        struct autorid_range_config *range,
63                                        bool read_only);
64
65 /**
66  * get the domain range and low_id for the domain
67  * identified by domsid and domain_range_index
68  */
69 NTSTATUS idmap_autorid_getrange(struct db_context *db,
70                                 const char *domsid,
71                                 uint32_t domain_range_index,
72                                 uint32_t *rangenum,
73                                 uint32_t *low_id);
74
75 /**
76  * Set a range for a domain#index pair to a given
77  * number. Fail if a different range was already stored.
78  */
79 NTSTATUS idmap_autorid_setrange(struct db_context *db,
80                                 const char *domsid,
81                                 uint32_t domain_range_index,
82                                 uint32_t rangenum);
83
84 /**
85  * Initialize a specified HWM value to 0 if it is not
86  * yet present in the database.
87  */
88 NTSTATUS idmap_autorid_init_hwm(struct db_context *db, const char *hwm);
89
90 NTSTATUS idmap_autorid_db_init(const char *path,
91                                TALLOC_CTX *mem_ctx,
92                                struct db_context **db);
93
94 NTSTATUS idmap_autorid_loadconfig(struct db_context *db,
95                                   TALLOC_CTX *ctx,
96                                   struct autorid_global_config **result);
97
98 NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
99                                   struct autorid_global_config *cfg);
100
101 /**
102  * get the range config string stored in the database
103  */
104 NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
105                                     char **result);
106
107 /**
108  * parse the handed in config string and fill the provided config structure.
109  * return false if the string could not be parsed.
110  */
111 bool idmap_autorid_parse_configstr(const char *configstr,
112                                    struct autorid_global_config *cfg);
113
114 #endif /* _IDMAP_AUTORID_H_ */