2 * Unix SMB/CIFS implementation.
4 * Winbind rpc backend functions
6 * Copyright (c) 2000-2003 Tim Potter
7 * Copyright (c) 2001 Andrew Tridgell
8 * Copyright (c) 2005 Volker Lendecke
9 * Copyright (c) 2008 Guenther Deschner (pidl conversion)
10 * Copyright (c) 2010 Andreas Schneider <asn@samba.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "winbindd_rpc.h"
30 #include "librpc/gen_ndr/cli_samr.h"
31 #include "librpc/gen_ndr/srv_samr.h"
32 #include "librpc/gen_ndr/cli_lsa.h"
33 #include "librpc/gen_ndr/srv_lsa.h"
34 #include "rpc_client/cli_samr.h"
35 #include "rpc_client/cli_lsarpc.h"
37 /* Query display info for a domain */
38 NTSTATUS
rpc_query_user_list(TALLOC_CTX
*mem_ctx
,
39 struct rpc_pipe_client
*samr_pipe
,
40 struct policy_handle
*samr_policy
,
41 const struct dom_sid
*domain_sid
,
43 struct wbint_userinfo
**pinfo
)
45 struct wbint_userinfo
*info
= NULL
;
46 uint32_t num_info
= 0;
47 uint32_t loop_count
= 0;
48 uint32_t start_idx
= 0;
56 uint32_t num_dom_users
;
57 uint32_t max_entries
, max_size
;
58 uint32_t total_size
, returned_size
;
59 union samr_DispInfo disp_info
;
61 get_query_dispinfo_params(loop_count
,
65 status
= rpccli_samr_QueryDisplayInfo(samr_pipe
,
75 if (!NT_STATUS_IS_OK(status
)) {
76 if (!NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
81 /* increment required start query values */
82 start_idx
+= disp_info
.info1
.count
;
84 num_dom_users
= disp_info
.info1
.count
;
86 num_info
+= num_dom_users
;
88 info
= TALLOC_REALLOC_ARRAY(mem_ctx
,
90 struct wbint_userinfo
,
93 return NT_STATUS_NO_MEMORY
;
96 for (j
= 0; j
< num_dom_users
; i
++, j
++) {
97 uint32_t rid
= disp_info
.info1
.entries
[j
].rid
;
98 struct samr_DispEntryGeneral
*src
;
99 struct wbint_userinfo
*dst
;
101 src
= &(disp_info
.info1
.entries
[j
]);
104 dst
->acct_name
= talloc_strdup(info
,
105 src
->account_name
.string
);
106 if (dst
->acct_name
== NULL
) {
107 return NT_STATUS_NO_MEMORY
;
110 dst
->full_name
= talloc_strdup(info
, src
->full_name
.string
);
111 if (dst
->full_name
== NULL
) {
112 return NT_STATUS_NO_MEMORY
;
118 sid_compose(&dst
->user_sid
, domain_sid
, rid
);
120 /* For the moment we set the primary group for
121 every user to be the Domain Users group.
122 There are serious problems with determining
123 the actual primary group for large domains.
124 This should really be made into a 'winbind
125 force group' smb.conf parameter or
126 something like that. */
127 sid_compose(&dst
->group_sid
, domain_sid
,
130 } while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
));
132 *pnum_info
= num_info
;
138 /* List all domain groups */
139 NTSTATUS
rpc_enum_dom_groups(TALLOC_CTX
*mem_ctx
,
140 struct rpc_pipe_client
*samr_pipe
,
141 struct policy_handle
*samr_policy
,
143 struct acct_info
**pinfo
)
145 struct acct_info
*info
= NULL
;
147 uint32_t num_info
= 0;
153 struct samr_SamArray
*sam_array
= NULL
;
157 /* start is updated by this call. */
158 status
= rpccli_samr_EnumDomainGroups(samr_pipe
,
163 0xFFFF, /* buffer size? */
165 if (!NT_STATUS_IS_OK(status
)) {
166 if (!NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
)) {
167 DEBUG(2,("query_user_list: failed to enum domain groups: %s\n",
173 info
= TALLOC_REALLOC_ARRAY(mem_ctx
,
178 return NT_STATUS_NO_MEMORY
;
181 for (g
= 0; g
< count
; g
++) {
182 fstrcpy(info
[num_info
+ g
].acct_name
,
183 sam_array
->entries
[g
].name
.string
);
185 info
[num_info
+ g
].rid
= sam_array
->entries
[g
].idx
;
189 } while (NT_STATUS_EQUAL(status
, STATUS_MORE_ENTRIES
));
191 *pnum_info
= num_info
;