2 Unix SMB/CIFS implementation.
4 Winbind daemon - sid related functions
6 Copyright (C) Tim Potter 2000
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DBGC_CLASS DBGC_WINBIND
28 /* Convert a string */
30 enum winbindd_result winbindd_lookupsid(struct winbindd_cli_state *state)
32 extern DOM_SID global_sid_Builtin;
33 enum SID_NAME_USE type;
39 DEBUG(3, ("[%5d]: lookupsid %s\n", state->pid,
40 state->request.data.sid));
42 /* Lookup sid from PDC using lsa_lookup_sids() */
44 if (!string_to_sid(&sid, state->request.data.sid)) {
45 DEBUG(5, ("%s not a SID\n", state->request.data.sid));
46 return WINBINDD_ERROR;
49 /* Don't look up BUILTIN sids */
51 sid_copy(&tmp_sid, &sid);
52 sid_split_rid(&tmp_sid, &rid);
54 if (sid_equal(&tmp_sid, &global_sid_Builtin)) {
55 return WINBINDD_ERROR;
60 if (!winbindd_lookup_name_by_sid(&sid, dom_name, name, &type)) {
61 return WINBINDD_ERROR;
64 fstrcpy(state->response.data.name.dom_name, dom_name);
65 fstrcpy(state->response.data.name.name, name);
67 state->response.data.name.type = type;
72 /* Convert a sid to a string */
74 enum winbindd_result winbindd_lookupname(struct winbindd_cli_state *state)
76 enum SID_NAME_USE type;
78 char *name_domain, *name_user;
80 struct winbindd_domain *domain;
82 DEBUG(3, ("[%5d]: lookupname %s%s%s\n", state->pid,
83 state->request.data.name.dom_name,
84 lp_winbind_separator(),
85 state->request.data.name.name));
87 name_domain = state->request.data.name.dom_name;
88 name_user = state->request.data.name.name;
90 if ((domain = find_domain_from_name(name_domain)) == NULL) {
91 DEBUG(0, ("could not find domain entry for domain %s\n",
93 return WINBINDD_ERROR;
96 /* Lookup name from PDC using lsa_lookup_names() */
97 if (!winbindd_lookup_sid_by_name(domain, name_user, &sid, &type)) {
98 return WINBINDD_ERROR;
101 sid_to_string(sid_str, &sid);
102 fstrcpy(state->response.data.sid.sid, sid_str);
103 state->response.data.sid.type = type;
108 /* Convert a sid to a uid. We assume we only have one rid attached to the
111 enum winbindd_result winbindd_sid_to_uid(struct winbindd_cli_state *state)
115 DEBUG(3, ("[%5d]: sid to uid %s\n", state->pid,
116 state->request.data.sid));
118 /* Split sid into domain sid and user rid */
119 if (!string_to_sid(&sid, state->request.data.sid)) {
120 DEBUG(1, ("Could not get convert sid %s from string\n",
121 state->request.data.sid));
122 return WINBINDD_ERROR;
125 /* Find uid for this sid and return it */
126 if (!winbindd_idmap_get_uid_from_sid(&sid, &state->response.data.uid)) {
127 DEBUG(1, ("Could not get uid for sid %s\n",
128 state->request.data.sid));
129 return WINBINDD_ERROR;
135 /* Convert a sid to a gid. We assume we only have one rid attached to the
138 enum winbindd_result winbindd_sid_to_gid(struct winbindd_cli_state *state)
142 DEBUG(3, ("[%5d]: sid to gid %s\n", state->pid,
143 state->request.data.sid));
145 if (!string_to_sid(&sid, state->request.data.sid)) {
146 DEBUG(1, ("Could not cvt string to sid %s\n",
147 state->request.data.sid));
148 return WINBINDD_ERROR;
151 /* Find gid for this sid and return it */
152 if (!winbindd_idmap_get_gid_from_sid(&sid, &state->response.data.gid)) {
153 DEBUG(1, ("Could not get gid for sid %s\n",
154 state->request.data.sid));
155 return WINBINDD_ERROR;
161 /* Convert a uid to a sid */
163 enum winbindd_result winbindd_uid_to_sid(struct winbindd_cli_state *state)
167 /* Bug out if the uid isn't in the winbind range */
169 if ((state->request.data.uid < server_state.uid_low ) ||
170 (state->request.data.uid > server_state.uid_high)) {
171 return WINBINDD_ERROR;
174 DEBUG(3, ("[%5d]: uid to sid %d\n", state->pid,
175 state->request.data.uid));
177 /* Lookup rid for this uid */
178 if (!winbindd_idmap_get_sid_from_uid(state->request.data.uid, &sid)) {
179 DEBUG(1, ("Could not convert uid %d to rid\n",
180 state->request.data.uid));
181 return WINBINDD_ERROR;
184 sid_to_string(state->response.data.sid.sid, &sid);
185 state->response.data.sid.type = SID_NAME_USER;
190 /* Convert a gid to a sid */
192 enum winbindd_result winbindd_gid_to_sid(struct winbindd_cli_state *state)
196 /* Bug out if the gid isn't in the winbind range */
198 if ((state->request.data.gid < server_state.gid_low) ||
199 (state->request.data.gid > server_state.gid_high)) {
200 return WINBINDD_ERROR;
203 DEBUG(3, ("[%5d]: gid to sid %d\n", state->pid,
204 state->request.data.gid));
206 /* Lookup sid for this uid */
207 if (!winbindd_idmap_get_sid_from_gid(state->request.data.gid, &sid)) {
208 DEBUG(1, ("Could not convert gid %d to sid\n",
209 state->request.data.gid));
210 return WINBINDD_ERROR;
213 /* Construct sid and return it */
214 sid_to_string(state->response.data.sid.sid, &sid);
215 state->response.data.sid.type = SID_NAME_DOM_GRP;