s3:winbindd add idmap_tdb_common file to store common code of TDB idmap backends
[kai/samba.git] / source3 / winbindd / idmap_tdb_common.h
1 /*
2    Unix SMB/CIFS implementation.
3
4    common functions for TDB based idmapping backends
5
6    Copyright (C) Christian Ambach 2012
7
8    These functions were initially copied over from idmap_tdb.c and idmap_tdb2.c
9    which are:
10
11    Copyright (C) Tim Potter 2000
12    Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
13    Copyright (C) Jeremy Allison 2006
14    Copyright (C) Simo Sorce 2003-2006
15    Copyright (C) Michael Adam 2009-2010
16    Copyright (C) Andrew Tridgell 2007
17
18    This program is free software; you can redistribute it and/or modify
19    it under the terms of the GNU General Public License as published by
20    the Free Software Foundation; either version 2 of the License, or
21    (at your option) any later version.
22
23    This program is distributed in the hope that it will be useful,
24    but WITHOUT ANY WARRANTY; without even the implied warranty of
25    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26    GNU General Public License for more details.
27
28    You should have received a copy of the GNU General Public License
29    along with this program; if not, write to the Free Software
30    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33 #ifndef _IDMAP_TDB_COMMON_H_
34 #define _IDMAP_TDB_COMMON_H_
35
36 #include "includes.h"
37 #include "idmap.h"
38 #include "dbwrap/dbwrap.h"
39
40 /*
41  * this must be stored in idmap_domain->private_data
42  * when using idmap_tdb_common_get_new_id and the
43  * mapping functions idmap_tdb_common_unixid(s)_to_sids
44  *
45  * private_data can be used for backend specific
46  * configuration data (e.g. idmap script in idmap_tdb2)
47  *
48  */
49 struct idmap_tdb_common_context {
50         struct db_context *db;
51         struct idmap_rw_ops *rw_ops;
52         /*
53          * what is the maximum xid to be allocated
54          * this is typically just dom->high_id
55          */
56         uint32_t max_id;
57         const char *hwmkey_uid;
58         const char *hwmkey_gid;
59         /**
60          * if not set, idmap_tdb_common_unixids_to_sid will be used by
61          * idmap_tdb_common_unixids_to_sids
62          */
63         NTSTATUS(*unixid_to_sid_fn) (struct idmap_domain *dom,
64                                      struct id_map * map);
65         /*
66          * if not set, idmap_tdb_common_sid_to_id will be used by
67          * idmap_tdb_common_sids_to_unixids
68          */
69         NTSTATUS(*sid_to_unixid_fn) (struct idmap_domain *dom,
70                                      struct id_map * map);
71         void *private_data;
72 };
73
74 /**
75  * Allocate a new unix-ID.
76  * For now this is for the default idmap domain only.
77  * Should be extended later on.
78  */
79 NTSTATUS idmap_tdb_common_get_new_id(struct idmap_domain *dom,
80                                      struct unixid *id);
81
82 /*
83  * store a mapping into the idmap database
84  *
85  * the entries that will be stored are
86  * UID map->xid.id => map->sid and map->sid => UID map->xid.id
87  * or
88  * GID map->xid.id => map->sid and map->sid => GID map->xid.id
89  *
90  * for example
91  * UID 12345 = S-1-5-21-297746067-1479432880-4056370663
92  * S-1-5-21-297746067-1479432880-4056370663 = UID 12345
93  *
94  */
95 NTSTATUS idmap_tdb_common_set_mapping(struct idmap_domain *dom,
96                                       const struct id_map *map);
97
98 /*
99  * Create a new mapping for an unmapped SID, also allocating a new ID.
100  * This should be run inside a transaction.
101  *
102  * TODO:
103  *  Properly integrate this with multi domain idmap config:
104  *  Currently, the allocator is default-config only.
105  */
106 NTSTATUS idmap_tdb_common_new_mapping(struct idmap_domain *dom,
107                                       struct id_map *map);
108
109 /*
110  * default multiple id to sid lookup function
111  *
112  * will call idmap_tdb_common_unixid_to_sid for each mapping
113  * if no other function to lookup unixid_to_sid was given in
114  * idmap_tdb_common_context
115  */
116 NTSTATUS idmap_tdb_common_unixids_to_sids(struct idmap_domain *dom,
117                                           struct id_map **ids);
118
119 /*
120  * default single id to sid lookup function
121  *
122  * will read the entries written by idmap_tdb_common_set_mapping
123  */
124 NTSTATUS idmap_tdb_common_unixid_to_sid(struct idmap_domain *dom,
125                                         struct id_map *map);
126
127 /**********************************
128  Single sid to id lookup function.
129 **********************************/
130
131 NTSTATUS idmap_tdb_common_sid_to_unixid(struct idmap_domain *dom,
132                                         struct id_map *map);
133
134 NTSTATUS idmap_tdb_common_sids_to_unixids(struct idmap_domain *dom,
135                                           struct id_map **ids);
136
137 #endif                          /* _IDMAP_TDB_COMMON_H_ */