selftest: Add test for failing chdir call in smbd
[Samba.git] / source3 / include / idmap_autorid_tdb.h
blob36a595ff83fcd335148d4be2e577265cb60146cf
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
6 * Copyright (C) Christian Ambach, 2010-2012
7 * Copyright (C) Atul Kulkarni, 2013
8 * Copyright (C) Michael Adam, 2012-2013
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.
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.
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/>.
25 #ifndef _IDMAP_AUTORID_H_
26 #define _IDMAP_AUTORID_H_
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"
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"
41 struct autorid_global_config {
42 uint32_t minvalue;
43 uint32_t rangesize;
44 uint32_t maxranges;
47 struct autorid_range_config {
48 fstring domsid;
49 uint32_t rangenum;
50 uint32_t domain_range_index;
51 uint32_t low_id;
52 uint32_t high_id;
55 /**
56 * Get the range for a pair consisting of the domain sid
57 * and a domain range. If there is no stored range for
58 * this pair and read_only == false, a new range is
59 * acquired by incrementing that range HWM counter in the
60 * database.
62 NTSTATUS idmap_autorid_get_domainrange(struct db_context *db,
63 struct autorid_range_config *range,
64 bool read_only);
66 /**
67 * get the domain range and low_id for the domain
68 * identified by domsid and domain_range_index
70 NTSTATUS idmap_autorid_getrange(struct db_context *db,
71 const char *domsid,
72 uint32_t domain_range_index,
73 uint32_t *rangenum,
74 uint32_t *low_id);
76 /**
77 * Set a range for a domain#index pair to a given
78 * number. Fail if a different range was already stored.
80 NTSTATUS idmap_autorid_setrange(struct db_context *db,
81 const char *domsid,
82 uint32_t domain_range_index,
83 uint32_t rangenum);
85 NTSTATUS idmap_autorid_acquire_range(struct db_context *db,
86 struct autorid_range_config *range);
88 /**
89 * Delete a domain#index <-> range maping from the database.
90 * The mapping is specified by the sid and index.
91 * If force == true, invalid mapping records are deleted as far
92 * as possible, otherwise they are left untouched.
94 NTSTATUS idmap_autorid_delete_range_by_sid(struct db_context *db,
95 const char *domsid,
96 uint32_t domain_range_index,
97 bool force);
99 /**
100 * Delete a domain#index <-> range maping from the database.
101 * The mapping is specified by the range number.
102 * If force == true, invalid mapping records are deleted as far
103 * as possible, otherwise they are left untouched.
105 NTSTATUS idmap_autorid_delete_range_by_num(struct db_context *db,
106 uint32_t rangenum,
107 bool force);
110 * Initialize a specified HWM value to 0 if it is not
111 * yet present in the database.
113 NTSTATUS idmap_autorid_init_hwm(struct db_context *db, const char *hwm);
116 * Open and possibly create the autorid database.
118 NTSTATUS idmap_autorid_db_open(const char *path,
119 TALLOC_CTX *mem_ctx,
120 struct db_context **db);
123 * Initialize the high watermark records in the database.
125 NTSTATUS idmap_autorid_init_hwms(struct db_context *db);
128 * Initialize an idmap_autorid database.
129 * After this function has successfully completed, the following are true:
130 * - the database exists
131 * - the required HWM keys exist (range, alloc-uid, alloc-gid)
133 NTSTATUS idmap_autorid_db_init(const char *path,
134 TALLOC_CTX *mem_ctx,
135 struct db_context **db);
138 * Load the configuration stored in the autorid database.
140 NTSTATUS idmap_autorid_loadconfig(struct db_context *db,
141 struct autorid_global_config *result);
144 * Save the global autorid configuration into the autorid database.
145 * The stored configuration consists of:
146 * - the low value of the idmap range
147 * - the rangesize
148 * - the maximum number of ranges
150 NTSTATUS idmap_autorid_saveconfig(struct db_context *db,
151 struct autorid_global_config *cfg);
154 * get the range config string stored in the database
156 NTSTATUS idmap_autorid_getconfigstr(struct db_context *db, TALLOC_CTX *mem_ctx,
157 char **result);
160 * parse the handed in config string and fill the provided config structure.
161 * return false if the string could not be parsed.
163 bool idmap_autorid_parse_configstr(const char *configstr,
164 struct autorid_global_config *cfg);
168 * Save the global autorid configuration into the autorid database
169 * as provided in the config string.
170 * First parse the configstr and validate it.
172 NTSTATUS idmap_autorid_saveconfigstr(struct db_context *db,
173 const char *configstr);
177 * idmap_autorid_iterate_domain_ranges:
178 * perform an action on all domain range mappings for a given domain
179 * specified by domain sid.
181 NTSTATUS idmap_autorid_iterate_domain_ranges(struct db_context *db,
182 const char *domsid,
183 NTSTATUS (*fn)(struct db_context *db,
184 const char *domsid,
185 uint32_t index,
186 uint32_t rangenum,
187 void *private_data),
188 void *private_data,
189 int *count);
192 * idmap_autorid_iterate_domain_ranges_read:
193 * perform a read only action on all domain range mappings for a given domain
194 * specified by domain sid.
196 NTSTATUS idmap_autorid_iterate_domain_ranges_read(struct db_context *db,
197 const char *domsid,
198 NTSTATUS (*fn)(struct db_context *db,
199 const char *domsid,
200 uint32_t index,
201 uint32_t rangenum,
202 void *private_data),
203 void *private_data,
204 int *count);
207 * delete all range mappings for a given domain
209 NTSTATUS idmap_autorid_delete_domain_ranges(struct db_context *db,
210 const char *domsid,
211 bool force,
212 int *count);
214 #endif /* _IDMAP_AUTORID_H_ */