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.
28 /* Prototypes from common.h - only needed #if TNG */
30 int winbindd_request(int req_type, struct winbindd_request *request,
31 struct winbindd_response *response);
33 /* List groups a user is a member of */
35 static BOOL wbinfo_get_usergroups(char *user)
37 struct winbindd_request request;
38 struct winbindd_response response;
41 ZERO_STRUCT(response);
45 fstrcpy(request.data.username, user);
47 result = winbindd_request(WINBINDD_GETGROUPS, &request, &response);
49 if (result != NSS_STATUS_SUCCESS) {
53 for (i = 0; i < response.data.num_entries; i++) {
54 printf("%d\n", (int)((gid_t *)response.extra_data)[i]);
60 /* List trusted domains */
62 static BOOL wbinfo_list_domains(void)
64 struct winbindd_response response;
67 ZERO_STRUCT(response);
71 if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) ==
76 /* Display response */
78 if (response.extra_data) {
79 while(next_token((char **)&response.extra_data, name, ",",
88 /* Check trust account password */
90 static BOOL wbinfo_check_secret(void)
92 struct winbindd_response response;
95 ZERO_STRUCT(response);
97 result = winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response) ==
102 if (response.data.num_entries == 0) {
103 printf("Secret is good\n");
105 printf("Secret is bad\n0x%08x\n",
106 response.data.num_entries);
115 /* Convert uid to sid */
117 static BOOL wbinfo_uid_to_sid(uid_t uid)
119 struct winbindd_request request;
120 struct winbindd_response response;
122 ZERO_STRUCT(request);
123 ZERO_STRUCT(response);
127 request.data.uid = uid;
128 if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) ==
133 /* Display response */
135 printf("%s\n", response.data.sid.sid);
140 /* Convert gid to sid */
142 static BOOL wbinfo_gid_to_sid(gid_t gid)
144 struct winbindd_request request;
145 struct winbindd_response response;
147 ZERO_STRUCT(request);
148 ZERO_STRUCT(response);
152 request.data.gid = gid;
153 if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) ==
158 /* Display response */
160 printf("%s\n", response.data.sid.sid);
165 /* Convert sid to uid */
167 static BOOL wbinfo_sid_to_uid(char *sid)
169 struct winbindd_request request;
170 struct winbindd_response response;
172 ZERO_STRUCT(request);
173 ZERO_STRUCT(response);
177 fstrcpy(request.data.sid, sid);
178 if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) ==
183 /* Display response */
185 printf("%d\n", (int)response.data.uid);
190 static BOOL wbinfo_sid_to_gid(char *sid)
192 struct winbindd_request request;
193 struct winbindd_response response;
195 ZERO_STRUCT(request);
196 ZERO_STRUCT(response);
200 fstrcpy(request.data.sid, sid);
201 if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) ==
206 /* Display response */
208 printf("%d\n", (int)response.data.gid);
213 /* Convert sid to string */
215 static BOOL wbinfo_lookupsid(char *sid)
217 struct winbindd_request request;
218 struct winbindd_response response;
220 ZERO_STRUCT(request);
221 ZERO_STRUCT(response);
223 /* Send off request */
225 fstrcpy(request.data.sid, sid);
226 if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) ==
231 /* Display response */
233 printf("%s %d\n", response.data.name.name, response.data.name.type);
238 /* Convert string to sid */
240 static BOOL wbinfo_lookupname(char *name)
242 struct winbindd_request request;
243 struct winbindd_response response;
245 /* Send off request */
247 ZERO_STRUCT(request);
248 ZERO_STRUCT(response);
250 fstrcpy(request.data.name, name);
251 if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) ==
256 /* Display response */
258 printf("%s %d\n", response.data.sid.sid, response.data.sid.type);
263 /* Print domain users */
265 static BOOL print_domain_users(void)
267 struct winbindd_response response;
270 /* Send request to winbind daemon */
272 ZERO_STRUCT(response);
274 if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) ==
279 /* Look through extra data */
281 if (!response.extra_data) {
285 while(next_token((char **)&response.extra_data, name, ",",
287 printf("%s\n", name);
293 /* Print domain groups */
295 static BOOL print_domain_groups(void)
297 struct winbindd_response response;
300 ZERO_STRUCT(response);
302 if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) ==
307 /* Look through extra data */
309 if (!response.extra_data) {
313 while(next_token((char **)&response.extra_data, name, ",",
315 printf("%s\n", name);
321 /* Print program usage */
323 static void usage(void)
325 printf("Usage: wbinfo -ug | -n name | -sSY sid | -UG uid/gid | -tm\n");
326 printf("\t-u\tlists all domain users\n");
327 printf("\t-g\tlists all domain groups\n");
328 printf("\t-n name\tconverts name to sid\n");
329 printf("\t-s sid\tconverts sid to name\n");
330 printf("\t-U uid\tconverts uid to sid\n");
331 printf("\t-G gid\tconverts gid to sid\n");
332 printf("\t-S sid\tconverts sid to uid\n");
333 printf("\t-Y sid\tconverts sid to gid\n");
334 printf("\t-t\tcheck shared secret\n");
335 printf("\t-m\tlist trusted domains\n");
336 printf("\t-r user\tget user groups\n");
341 int main(int argc, char **argv)
343 extern pstring global_myname;
346 /* Samba client initialisation */
348 if (!*global_myname) {
351 fstrcpy(global_myname, myhostname());
352 p = strchr(global_myname, '.');
359 charset_initialise();
361 if (!lp_load(CONFIGFILE, True, False, False)) {
362 DEBUG(0, ("error opening config file\n"));
366 codepage_initialise(lp_client_code_page());
369 /* Parse command line options */
376 while ((opt = getopt(argc, argv, "ugs:n:U:G:S:Y:tmr:")) != EOF) {
379 if (!print_domain_users()) {
380 printf("Error looking up domain users\n");
385 if (!print_domain_groups()) {
386 printf("Error looking up domain groups\n");
391 if (!wbinfo_lookupsid(optarg)) {
392 printf("Could not lookup sid %s\n", optarg);
397 if (!wbinfo_lookupname(optarg)) {
398 printf("Could not lookup name %s\n", optarg);
403 if (!wbinfo_uid_to_sid(atoi(optarg))) {
404 printf("Could not convert uid %s to sid\n",
410 if (!wbinfo_gid_to_sid(atoi(optarg))) {
411 printf("Could not convert gid %s to sid\n",
417 if (!wbinfo_sid_to_uid(optarg)) {
418 printf("Could not convert sid %s to uid\n",
424 if (!wbinfo_sid_to_gid(optarg)) {
425 printf("Could not convert sid %s to gid\n",
431 if (!wbinfo_check_secret()) {
432 printf("Could not check secret\n");
437 if (!wbinfo_list_domains()) {
438 printf("Could not list trusted domains\n");
443 if (!wbinfo_get_usergroups(optarg)) {
444 printf("Could not get groups for user %s\n",