auth: Explain why GSS_KRB5_CRED_NO_CI_FLAGS_X is needed
[Samba.git] / source3 / winbindd / idmap_rid.c
blob099f68c5ee31562c9f4756908e2aabde216df9d7
1 /*
2 * idmap_rid: static map between Active Directory/NT RIDs and RFC 2307 accounts
3 * Copyright (C) Guenther Deschner, 2004
4 * Copyright (C) Sumit Bose, 2004
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "winbindd.h"
23 #include "idmap.h"
24 #include "../libcli/security/dom_sid.h"
26 #undef DBGC_CLASS
27 #define DBGC_CLASS DBGC_IDMAP
29 struct idmap_rid_context {
30 uint32_t base_rid;
33 /******************************************************************************
34 compat params can't be used because of the completely different way
35 we support multiple domains in the new idmap
36 *****************************************************************************/
38 static NTSTATUS idmap_rid_initialize(struct idmap_domain *dom)
40 NTSTATUS ret;
41 struct idmap_rid_context *ctx;
42 char *config_option = NULL;
44 ctx = talloc_zero(dom, struct idmap_rid_context);
45 if (ctx == NULL) {
46 DEBUG(0, ("Out of memory!\n"));
47 return NT_STATUS_NO_MEMORY;
50 config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
51 if ( ! config_option) {
52 DEBUG(0, ("Out of memory!\n"));
53 ret = NT_STATUS_NO_MEMORY;
54 goto failed;
57 ctx->base_rid = lp_parm_int(-1, config_option, "base_rid", 0);
59 dom->private_data = ctx;
61 talloc_free(config_option);
62 return NT_STATUS_OK;
64 failed:
65 talloc_free(ctx);
66 return ret;
69 static NTSTATUS idmap_rid_id_to_sid(struct idmap_domain *dom, struct id_map *map)
71 struct winbindd_domain *domain;
72 struct idmap_rid_context *ctx;
74 ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
76 /* apply filters before checking */
77 if (!idmap_unix_id_is_in_range(map->xid.id, dom)) {
78 DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
79 map->xid.id, dom->low_id, dom->high_id));
80 return NT_STATUS_NONE_MAPPED;
83 domain = find_domain_from_name_noinit(dom->name);
84 if (domain == NULL ) {
85 return NT_STATUS_NO_SUCH_DOMAIN;
88 sid_compose(map->sid, &domain->sid, map->xid.id - dom->low_id + ctx->base_rid);
90 map->status = ID_MAPPED;
91 map->xid.type = ID_TYPE_BOTH;
93 return NT_STATUS_OK;
96 /**********************************
97 Single sid to id lookup function.
98 **********************************/
100 static NTSTATUS idmap_rid_sid_to_id(struct idmap_domain *dom, struct id_map *map)
102 uint32_t rid;
103 struct idmap_rid_context *ctx;
105 ctx = talloc_get_type(dom->private_data, struct idmap_rid_context);
107 sid_peek_rid(map->sid, &rid);
108 map->xid.id = rid - ctx->base_rid + dom->low_id;
109 map->xid.type = ID_TYPE_BOTH;
111 /* apply filters before returning result */
113 if (!idmap_unix_id_is_in_range(map->xid.id, dom)) {
114 DEBUG(5, ("Requested id (%u) out of range (%u - %u). Filtered!\n",
115 map->xid.id, dom->low_id, dom->high_id));
116 map->status = ID_UNMAPPED;
117 return NT_STATUS_NONE_MAPPED;
120 map->status = ID_MAPPED;
122 return NT_STATUS_OK;
125 /**********************************
126 lookup a set of unix ids.
127 **********************************/
129 static NTSTATUS idmap_rid_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
131 NTSTATUS ret;
132 int i;
134 /* initialize the status to avoid suprise */
135 for (i = 0; ids[i]; i++) {
136 ids[i]->status = ID_UNKNOWN;
139 for (i = 0; ids[i]; i++) {
141 ret = idmap_rid_id_to_sid(dom, ids[i]);
143 if (( ! NT_STATUS_IS_OK(ret)) &&
144 ( ! NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
145 /* some fatal error occurred, log it */
146 DEBUG(3, ("Unexpected error resolving an ID (%d)\n", ids[i]->xid.id));
150 return NT_STATUS_OK;
153 /**********************************
154 lookup a set of sids.
155 **********************************/
157 static NTSTATUS idmap_rid_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
159 NTSTATUS ret;
160 int i;
162 /* initialize the status to avoid suprise */
163 for (i = 0; ids[i]; i++) {
164 ids[i]->status = ID_UNKNOWN;
167 for (i = 0; ids[i]; i++) {
169 ret = idmap_rid_sid_to_id(dom, ids[i]);
171 if (( ! NT_STATUS_IS_OK(ret)) &&
172 ( ! NT_STATUS_EQUAL(ret, NT_STATUS_NONE_MAPPED))) {
173 /* some fatal error occurred, log it */
174 DEBUG(3, ("Unexpected error resolving a SID (%s)\n",
175 sid_string_dbg(ids[i]->sid)));
179 return NT_STATUS_OK;
182 static struct idmap_methods rid_methods = {
183 .init = idmap_rid_initialize,
184 .unixids_to_sids = idmap_rid_unixids_to_sids,
185 .sids_to_unixids = idmap_rid_sids_to_unixids,
188 NTSTATUS idmap_rid_init(void)
190 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "rid", &rid_methods);