2 Unix SMB/Netbios implementation.
5 Winbind status program.
7 Copyright (C) Tim Potter 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "winbind_nss_config.h"
29 /* Prototypes from common.h - only needed #if TNG */
31 enum nss_status
winbindd_request(int req_type
,
32 struct winbindd_request
*request
,
33 struct winbindd_response
*response
);
35 /* List groups a user is a member of */
37 static BOOL
wbinfo_get_usergroups(char *user
)
39 struct winbindd_request request
;
40 struct winbindd_response response
;
43 ZERO_STRUCT(response
);
47 fstrcpy(request
.data
.username
, user
);
49 result
= winbindd_request(WINBINDD_GETGROUPS
, &request
, &response
);
51 if (result
!= NSS_STATUS_SUCCESS
) {
55 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
56 printf("%d\n", ((gid_t
*)response
.extra_data
)[i
]);
62 /* List trusted domains */
64 static BOOL
wbinfo_list_domains(void)
66 struct winbindd_response response
;
69 ZERO_STRUCT(response
);
73 if (winbindd_request(WINBINDD_LIST_TRUSTDOM
, NULL
, &response
) ==
78 /* Display response */
80 if (response
.extra_data
) {
81 while(next_token((char **)&response
.extra_data
, name
, ",",
90 /* Check trust account password */
92 static BOOL
wbinfo_check_secret(void)
94 struct winbindd_response response
;
97 ZERO_STRUCT(response
);
99 result
= winbindd_request(WINBINDD_CHECK_MACHACC
, NULL
, &response
) ==
104 if (response
.data
.num_entries
) {
105 printf("Secret is good\n");
107 printf("Secret is bad\n");
116 /* Convert uid to sid */
118 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
120 struct winbindd_request request
;
121 struct winbindd_response response
;
123 ZERO_STRUCT(request
);
124 ZERO_STRUCT(response
);
128 request
.data
.uid
= uid
;
129 if (winbindd_request(WINBINDD_UID_TO_SID
, &request
, &response
) ==
134 /* Display response */
136 printf("%s\n", response
.data
.sid
.sid
);
141 /* Convert gid to sid */
143 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
145 struct winbindd_request request
;
146 struct winbindd_response response
;
148 ZERO_STRUCT(request
);
149 ZERO_STRUCT(response
);
153 request
.data
.gid
= gid
;
154 if (winbindd_request(WINBINDD_GID_TO_SID
, &request
, &response
) ==
159 /* Display response */
161 printf("%s\n", response
.data
.sid
.sid
);
166 /* Convert sid to uid */
168 static BOOL
wbinfo_sid_to_uid(char *sid
)
170 struct winbindd_request request
;
171 struct winbindd_response response
;
173 ZERO_STRUCT(request
);
174 ZERO_STRUCT(response
);
178 fstrcpy(request
.data
.sid
, sid
);
179 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) ==
184 /* Display response */
186 printf("%d\n", response
.data
.uid
);
191 static BOOL
wbinfo_sid_to_gid(char *sid
)
193 struct winbindd_request request
;
194 struct winbindd_response response
;
196 ZERO_STRUCT(request
);
197 ZERO_STRUCT(response
);
201 fstrcpy(request
.data
.sid
, sid
);
202 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) ==
207 /* Display response */
209 printf("%d\n", response
.data
.gid
);
214 /* Convert sid to string */
216 static BOOL
wbinfo_lookupsid(char *sid
)
218 struct winbindd_request request
;
219 struct winbindd_response response
;
221 ZERO_STRUCT(request
);
222 ZERO_STRUCT(response
);
224 /* Send off request */
226 fstrcpy(request
.data
.sid
, sid
);
227 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) ==
232 /* Display response */
234 printf("%s %d\n", response
.data
.name
.name
, response
.data
.name
.type
);
239 /* Convert string to sid */
241 static BOOL
wbinfo_lookupname(char *name
)
243 struct winbindd_request request
;
244 struct winbindd_response response
;
246 /* Send off request */
248 ZERO_STRUCT(request
);
249 ZERO_STRUCT(response
);
251 fstrcpy(request
.data
.name
, name
);
252 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) ==
257 /* Display response */
259 printf("%s %d\n", response
.data
.sid
.sid
, response
.data
.sid
.type
);
264 /* Print domain users */
266 static BOOL
print_domain_users(void)
268 struct winbindd_response response
;
271 /* Send request to winbind daemon */
273 ZERO_STRUCT(response
);
275 if (winbindd_request(WINBINDD_LIST_USERS
, NULL
, &response
) ==
280 /* Look through extra data */
282 if (!response
.extra_data
) {
286 while(next_token((char **)&response
.extra_data
, name
, ",",
288 printf("%s\n", name
);
294 /* Print domain groups */
296 static BOOL
print_domain_groups(void)
298 struct winbindd_response response
;
301 ZERO_STRUCT(response
);
303 if (winbindd_request(WINBINDD_LIST_GROUPS
, NULL
, &response
) ==
308 /* Look through extra data */
310 if (!response
.extra_data
) {
314 while(next_token((char **)&response
.extra_data
, name
, ",",
316 printf("%s\n", name
);
322 /* Print program usage */
324 static void usage(void)
326 printf("Usage: wbinfo -ug | -n name | -sSY sid | -UG uid/gid | -tm\n");
327 printf("\t-u\tlists all domain users\n");
328 printf("\t-g\tlists all domain groups\n");
329 printf("\t-n name\tconverts name to sid\n");
330 printf("\t-s sid\tconverts sid to name\n");
331 printf("\t-U uid\tconverts uid to sid\n");
332 printf("\t-G gid\tconverts gid to sid\n");
333 printf("\t-S sid\tconverts sid to uid\n");
334 printf("\t-Y sid\tconverts sid to gid\n");
335 printf("\t-t\tcheck shared secret\n");
336 printf("\t-m\tlist trusted domains\n");
337 printf("\t-r user\tget user groups\n");
342 int main(int argc
, char **argv
)
344 extern pstring global_myname
;
347 /* Samba client initialisation */
349 if (!*global_myname
) {
352 fstrcpy(global_myname
, myhostname());
353 p
= strchr(global_myname
, '.');
360 charset_initialise();
362 if (!lp_load(CONFIGFILE
, True
, False
, False
)) {
363 DEBUG(0, ("error opening config file\n"));
367 codepage_initialise(lp_client_code_page());
370 /* Parse command line options */
377 while ((opt
= getopt(argc
, argv
, "ugs:n:U:G:S:Y:tmr:")) != EOF
) {
380 if (!print_domain_users()) {
381 printf("Error looking up domain users\n");
386 if (!print_domain_groups()) {
387 printf("Error looking up domain groups\n");
392 if (!wbinfo_lookupsid(optarg
)) {
393 printf("Could not lookup sid %s\n", optarg
);
398 if (!wbinfo_lookupname(optarg
)) {
399 printf("Could not lookup name %s\n", optarg
);
404 if (!wbinfo_uid_to_sid(atoi(optarg
))) {
405 printf("Could not convert uid %s to sid\n",
411 if (!wbinfo_gid_to_sid(atoi(optarg
))) {
412 printf("Could not convert gid %s to sid\n",
418 if (!wbinfo_sid_to_uid(optarg
)) {
419 printf("Could not convert sid %s to uid\n",
425 if (!wbinfo_sid_to_gid(optarg
)) {
426 printf("Could not convert sid %s to gid\n",
432 if (!wbinfo_check_secret()) {
433 printf("Could not check secret\n");
438 if (!wbinfo_list_domains()) {
439 printf("Could not list trusted domains\n");
444 if (!wbinfo_get_usergroups(optarg
)) {
445 printf("Could not get groups for user %s\n",