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 /* Convert a string */
28 enum winbindd_result
winbindd_lookupsid(struct winbindd_cli_state
*state
)
30 extern DOM_SID global_sid_Builtin
;
31 enum SID_NAME_USE type
;
37 DEBUG(3, ("[%5d]: lookupsid %s\n", state
->pid
,
38 state
->request
.data
.sid
));
40 /* Lookup sid from PDC using lsa_lookup_sids() */
42 if (!string_to_sid(&sid
, state
->request
.data
.sid
)) {
43 DEBUG(5, ("%s not a SID\n", state
->request
.data
.sid
));
44 return WINBINDD_ERROR
;
47 /* Don't look up BUILTIN sids */
49 sid_copy(&tmp_sid
, &sid
);
50 sid_split_rid(&tmp_sid
, &rid
);
52 if (sid_equal(&tmp_sid
, &global_sid_Builtin
)) {
53 return WINBINDD_ERROR
;
58 if (!winbindd_lookup_name_by_sid(&sid
, dom_name
, name
, &type
)) {
59 return WINBINDD_ERROR
;
62 fstrcpy(state
->response
.data
.name
.dom_name
, dom_name
);
63 fstrcpy(state
->response
.data
.name
.name
, name
);
65 state
->response
.data
.name
.type
= type
;
70 /* Convert a sid to a string */
72 enum winbindd_result
winbindd_lookupname(struct winbindd_cli_state
*state
)
74 enum SID_NAME_USE type
;
76 char *name_domain
, *name_user
;
78 struct winbindd_domain
*domain
;
80 DEBUG(3, ("[%5d]: lookupname %s%s%s\n", state
->pid
,
81 state
->request
.data
.name
.dom_name
,
82 lp_winbind_separator(),
83 state
->request
.data
.name
.name
));
85 name_domain
= state
->request
.data
.name
.dom_name
;
86 name_user
= state
->request
.data
.name
.name
;
88 if ((domain
= find_domain_from_name(name_domain
)) == NULL
) {
89 DEBUG(0, ("could not find domain entry for domain %s\n",
91 return WINBINDD_ERROR
;
94 /* Lookup name from PDC using lsa_lookup_names() */
95 if (!winbindd_lookup_sid_by_name(domain
, name_user
, &sid
, &type
)) {
96 return WINBINDD_ERROR
;
99 sid_to_string(sid_str
, &sid
);
100 fstrcpy(state
->response
.data
.sid
.sid
, sid_str
);
101 state
->response
.data
.sid
.type
= type
;
106 /* Convert a sid to a uid. We assume we only have one rid attached to the
109 enum winbindd_result
winbindd_sid_to_uid(struct winbindd_cli_state
*state
)
113 DEBUG(3, ("[%5d]: sid to uid %s\n", state
->pid
,
114 state
->request
.data
.sid
));
116 /* Split sid into domain sid and user rid */
117 if (!string_to_sid(&sid
, state
->request
.data
.sid
)) {
118 DEBUG(1, ("Could not get convert sid %s from string\n",
119 state
->request
.data
.sid
));
120 return WINBINDD_ERROR
;
123 /* Find uid for this sid and return it */
124 if (!winbindd_idmap_get_uid_from_sid(&sid
, &state
->response
.data
.uid
)) {
125 DEBUG(1, ("Could not get uid for sid %s\n",
126 state
->request
.data
.sid
));
127 return WINBINDD_ERROR
;
133 /* Convert a sid to a gid. We assume we only have one rid attached to the
136 enum winbindd_result
winbindd_sid_to_gid(struct winbindd_cli_state
*state
)
140 DEBUG(3, ("[%5d]: sid to gid %s\n", state
->pid
,
141 state
->request
.data
.sid
));
143 if (!string_to_sid(&sid
, state
->request
.data
.sid
)) {
144 DEBUG(1, ("Could not cvt string to sid %s\n",
145 state
->request
.data
.sid
));
146 return WINBINDD_ERROR
;
149 /* Find gid for this sid and return it */
150 if (!winbindd_idmap_get_gid_from_sid(&sid
, &state
->response
.data
.gid
)) {
151 DEBUG(1, ("Could not get gid for sid %s\n",
152 state
->request
.data
.sid
));
153 return WINBINDD_ERROR
;
159 /* Convert a uid to a sid */
161 enum winbindd_result
winbindd_uid_to_sid(struct winbindd_cli_state
*state
)
165 /* Bug out if the uid isn't in the winbind range */
167 if ((state
->request
.data
.uid
< server_state
.uid_low
) ||
168 (state
->request
.data
.uid
> server_state
.uid_high
)) {
169 return WINBINDD_ERROR
;
172 DEBUG(3, ("[%5d]: uid to sid %d\n", state
->pid
,
173 state
->request
.data
.uid
));
175 /* Lookup rid for this uid */
176 if (!winbindd_idmap_get_sid_from_uid(state
->request
.data
.uid
, &sid
)) {
177 DEBUG(1, ("Could not convert uid %d to rid\n",
178 state
->request
.data
.uid
));
179 return WINBINDD_ERROR
;
182 sid_to_string(state
->response
.data
.sid
.sid
, &sid
);
183 state
->response
.data
.sid
.type
= SID_NAME_USER
;
188 /* Convert a gid to a sid */
190 enum winbindd_result
winbindd_gid_to_sid(struct winbindd_cli_state
*state
)
194 /* Bug out if the gid isn't in the winbind range */
196 if ((state
->request
.data
.gid
< server_state
.gid_low
) ||
197 (state
->request
.data
.gid
> server_state
.gid_high
)) {
198 return WINBINDD_ERROR
;
201 DEBUG(3, ("[%5d]: gid to sid %d\n", state
->pid
,
202 state
->request
.data
.gid
));
204 /* Lookup sid for this uid */
205 if (!winbindd_idmap_get_sid_from_gid(state
->request
.data
.gid
, &sid
)) {
206 DEBUG(1, ("Could not convert gid %d to sid\n",
207 state
->request
.data
.gid
));
208 return WINBINDD_ERROR
;
211 /* Construct sid and return it */
212 sid_to_string(state
->response
.data
.sid
.sid
, &sid
);
213 state
->response
.data
.sid
.type
= SID_NAME_DOM_GRP
;