2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002
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.
29 #define DBGC_CLASS DBGC_WINBIND
31 extern int winbindd_fd;
33 static char winbind_separator_int(BOOL strict)
35 struct winbindd_response response;
42 ZERO_STRUCT(response);
44 /* Send off request */
46 if (winbindd_request_response(WINBINDD_INFO, NULL, &response) !=
48 d_fprintf(stderr, "could not obtain winbind separator!\n");
52 /* HACK: (this module should not call lp_ funtions) */
53 return *lp_winbind_separator();
56 sep = response.data.info.winbind_separator;
60 d_fprintf(stderr, "winbind separator was NULL!\n");
64 /* HACK: (this module should not call lp_ funtions) */
65 sep = *lp_winbind_separator();
71 static char winbind_separator(void)
73 return winbind_separator_int(False);
76 static const char *get_winbind_domain(void)
78 struct winbindd_response response;
79 static fstring winbind_domain;
81 ZERO_STRUCT(response);
83 /* Send off request */
85 if (winbindd_request_response(WINBINDD_DOMAIN_NAME, NULL, &response) !=
87 d_fprintf(stderr, "could not obtain winbind domain name!\n");
89 /* HACK: (this module should not call lp_ funtions) */
90 return lp_workgroup();
93 fstrcpy(winbind_domain, response.data.domain_name);
95 return winbind_domain;
99 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
100 form DOMAIN/user into a domain and a user */
102 static BOOL parse_wbinfo_domain_user(const char *domuser, fstring domain,
106 char *p = strchr(domuser,winbind_separator());
109 fstrcpy(user, domuser);
110 fstrcpy(domain, get_winbind_domain());
115 fstrcpy(domain, domuser);
116 domain[PTR_DIFF(p, domuser)] = 0;
122 /* List groups a user is a member of */
124 static BOOL wbinfo_get_usergroups(char *user)
126 struct winbindd_request request;
127 struct winbindd_response response;
131 ZERO_STRUCT(request);
132 ZERO_STRUCT(response);
136 fstrcpy(request.data.username, user);
138 result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
140 if (result != NSS_STATUS_SUCCESS)
143 for (i = 0; i < response.data.num_entries; i++)
144 d_printf("%d\n", (int)((gid_t *)response.extra_data)[i]);
146 SAFE_FREE(response.extra_data);
152 /* List group SIDs a user SID is a member of */
153 static BOOL wbinfo_get_usersids(char *user_sid)
155 struct winbindd_request request;
156 struct winbindd_response response;
161 ZERO_STRUCT(request);
162 ZERO_STRUCT(response);
165 fstrcpy(request.data.sid, user_sid);
167 result = winbindd_request_response(WINBINDD_GETUSERSIDS, &request, &response);
169 if (result != NSS_STATUS_SUCCESS)
172 s = response.extra_data;
173 for (i = 0; i < response.data.num_entries; i++) {
178 SAFE_FREE(response.extra_data);
183 static BOOL wbinfo_get_userdomgroups(const char *user_sid)
185 struct winbindd_request request;
186 struct winbindd_response response;
189 ZERO_STRUCT(request);
190 ZERO_STRUCT(response);
193 fstrcpy(request.data.sid, user_sid);
195 result = winbindd_request_response(WINBINDD_GETUSERDOMGROUPS, &request,
198 if (result != NSS_STATUS_SUCCESS)
201 if (response.data.num_entries != 0)
202 d_printf("%s", (char *)response.extra_data);
204 SAFE_FREE(response.extra_data);
209 /* Convert NetBIOS name to IP */
211 static BOOL wbinfo_wins_byname(char *name)
213 struct winbindd_request request;
214 struct winbindd_response response;
216 ZERO_STRUCT(request);
217 ZERO_STRUCT(response);
221 fstrcpy(request.data.winsreq, name);
223 if (winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response) !=
224 NSS_STATUS_SUCCESS) {
228 /* Display response */
230 d_printf("%s\n", response.data.winsresp);
235 /* Convert IP to NetBIOS name */
237 static BOOL wbinfo_wins_byip(char *ip)
239 struct winbindd_request request;
240 struct winbindd_response response;
242 ZERO_STRUCT(request);
243 ZERO_STRUCT(response);
247 fstrcpy(request.data.winsreq, ip);
249 if (winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response) !=
250 NSS_STATUS_SUCCESS) {
254 /* Display response */
256 d_printf("%s\n", response.data.winsresp);
261 /* List trusted domains */
263 static BOOL wbinfo_list_domains(void)
265 struct winbindd_response response;
267 ZERO_STRUCT(response);
271 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, NULL, &response) !=
275 /* Display response */
277 if (response.extra_data) {
278 const char *extra_data = (char *)response.extra_data;
282 while(next_token(&extra_data, name, "\n", sizeof(fstring))) {
283 p = strchr(name, '\\');
285 d_fprintf(stderr, "Got invalid response: %s\n",
290 d_printf("%s\n", name);
293 SAFE_FREE(response.extra_data);
300 /* show sequence numbers */
301 static BOOL wbinfo_show_sequence(const char *domain)
303 struct winbindd_request request;
304 struct winbindd_response response;
306 ZERO_STRUCT(response);
307 ZERO_STRUCT(request);
310 fstrcpy( request.domain_name, domain );
314 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
318 /* Display response */
320 if (response.extra_data) {
321 char *extra_data = (char *)response.extra_data;
322 d_printf("%s", extra_data);
323 SAFE_FREE(response.extra_data);
329 /* Show domain info */
331 static BOOL wbinfo_domain_info(const char *domain_name)
333 struct winbindd_request request;
334 struct winbindd_response response;
336 ZERO_STRUCT(request);
337 ZERO_STRUCT(response);
339 fstrcpy(request.domain_name, domain_name);
343 if (winbindd_request_response(WINBINDD_DOMAIN_INFO, &request, &response) !=
347 /* Display response */
349 d_printf("Name : %s\n", response.data.domain_info.name);
350 d_printf("Alt_Name : %s\n", response.data.domain_info.alt_name);
352 d_printf("SID : %s\n", response.data.domain_info.sid);
354 d_printf("Active Directory : %s\n",
355 response.data.domain_info.active_directory ? "Yes" : "No");
356 d_printf("Native : %s\n",
357 response.data.domain_info.native_mode ? "Yes" : "No");
359 d_printf("Primary : %s\n",
360 response.data.domain_info.primary ? "Yes" : "No");
362 d_printf("Sequence : %d\n", response.data.domain_info.sequence_number);
367 /* Get a foreign DC's name */
368 static BOOL wbinfo_getdcname(const char *domain_name)
370 struct winbindd_request request;
371 struct winbindd_response response;
373 ZERO_STRUCT(request);
374 ZERO_STRUCT(response);
376 fstrcpy(request.domain_name, domain_name);
380 if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) !=
381 NSS_STATUS_SUCCESS) {
382 d_fprintf(stderr, "Could not get dc name for %s\n", domain_name);
386 /* Display response */
388 d_printf("%s\n", response.data.dc_name);
393 /* Check trust account password */
395 static BOOL wbinfo_check_secret(void)
397 struct winbindd_response response;
400 ZERO_STRUCT(response);
402 result = winbindd_request_response(WINBINDD_CHECK_MACHACC, NULL, &response);
404 d_printf("checking the trust secret via RPC calls %s\n",
405 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
407 if (result != NSS_STATUS_SUCCESS)
408 d_fprintf(stderr, "error code was %s (0x%x)\n",
409 response.data.auth.nt_status_string,
410 response.data.auth.nt_status);
412 return result == NSS_STATUS_SUCCESS;
415 /* Convert uid to sid */
417 static BOOL wbinfo_uid_to_sid(uid_t uid)
419 struct winbindd_request request;
420 struct winbindd_response response;
422 ZERO_STRUCT(request);
423 ZERO_STRUCT(response);
427 request.data.uid = uid;
429 if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) !=
433 /* Display response */
435 d_printf("%s\n", response.data.sid.sid);
440 /* Convert gid to sid */
442 static BOOL wbinfo_gid_to_sid(gid_t gid)
444 struct winbindd_request request;
445 struct winbindd_response response;
447 ZERO_STRUCT(request);
448 ZERO_STRUCT(response);
452 request.data.gid = gid;
454 if (winbindd_request_response(WINBINDD_GID_TO_SID, &request, &response) !=
458 /* Display response */
460 d_printf("%s\n", response.data.sid.sid);
465 /* Convert sid to uid */
467 static BOOL wbinfo_sid_to_uid(char *sid)
469 struct winbindd_request request;
470 struct winbindd_response response;
472 ZERO_STRUCT(request);
473 ZERO_STRUCT(response);
477 fstrcpy(request.data.sid, sid);
479 if (winbindd_request_response(WINBINDD_SID_TO_UID, &request, &response) !=
483 /* Display response */
485 d_printf("%d\n", (int)response.data.uid);
490 static BOOL wbinfo_sid_to_gid(char *sid)
492 struct winbindd_request request;
493 struct winbindd_response response;
495 ZERO_STRUCT(request);
496 ZERO_STRUCT(response);
500 fstrcpy(request.data.sid, sid);
502 if (winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response) !=
506 /* Display response */
508 d_printf("%d\n", (int)response.data.gid);
513 static BOOL wbinfo_allocate_rid(void)
517 if (!winbind_allocate_rid(&rid))
520 d_printf("New rid: %d\n", rid);
525 /* Convert sid to string */
527 static BOOL wbinfo_lookupsid(char *sid)
529 struct winbindd_request request;
530 struct winbindd_response response;
532 ZERO_STRUCT(request);
533 ZERO_STRUCT(response);
535 /* Send off request */
537 fstrcpy(request.data.sid, sid);
539 if (winbindd_request_response(WINBINDD_LOOKUPSID, &request, &response) !=
543 /* Display response */
545 d_printf("%s%c%s %d\n", response.data.name.dom_name,
546 winbind_separator(), response.data.name.name,
547 response.data.name.type);
552 /* Convert string to sid */
554 static BOOL wbinfo_lookupname(char *name)
556 struct winbindd_request request;
557 struct winbindd_response response;
559 /* Send off request */
561 ZERO_STRUCT(request);
562 ZERO_STRUCT(response);
564 parse_wbinfo_domain_user(name, request.data.name.dom_name,
565 request.data.name.name);
567 if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
571 /* Display response */
573 d_printf("%s %s (%d)\n", response.data.sid.sid, sid_type_lookup(response.data.sid.type), response.data.sid.type);
578 /* Authenticate a user with a plaintext password */
580 static BOOL wbinfo_auth(char *username)
582 struct winbindd_request request;
583 struct winbindd_response response;
587 /* Send off request */
589 ZERO_STRUCT(request);
590 ZERO_STRUCT(response);
592 p = strchr(username, '%');
596 fstrcpy(request.data.auth.user, username);
597 fstrcpy(request.data.auth.pass, p + 1);
600 fstrcpy(request.data.auth.user, username);
602 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
604 /* Display response */
606 d_printf("plaintext password authentication %s\n",
607 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
609 if (response.data.auth.nt_status)
610 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
611 response.data.auth.nt_status_string,
612 response.data.auth.nt_status,
613 response.data.auth.error_string);
615 return result == NSS_STATUS_SUCCESS;
618 /* Authenticate a user with a challenge/response */
620 static BOOL wbinfo_auth_crap(char *username)
622 struct winbindd_request request;
623 struct winbindd_response response;
630 /* Send off request */
632 ZERO_STRUCT(request);
633 ZERO_STRUCT(response);
635 p = strchr(username, '%');
639 fstrcpy(pass, p + 1);
642 parse_wbinfo_domain_user(username, name_domain, name_user);
644 request.data.auth_crap.logon_parameters = MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT | MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
646 fstrcpy(request.data.auth_crap.user, name_user);
648 fstrcpy(request.data.auth_crap.domain,
651 generate_random_buffer(request.data.auth_crap.chal, 8);
653 if (lp_client_ntlmv2_auth()) {
654 DATA_BLOB server_chal;
655 DATA_BLOB names_blob;
657 DATA_BLOB lm_response;
658 DATA_BLOB nt_response;
660 server_chal = data_blob(request.data.auth_crap.chal, 8);
662 /* Pretend this is a login to 'us', for blob purposes */
663 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
665 if (!SMBNTLMv2encrypt(name_user, name_domain, pass, &server_chal,
667 &lm_response, &nt_response, NULL)) {
668 data_blob_free(&names_blob);
669 data_blob_free(&server_chal);
672 data_blob_free(&names_blob);
673 data_blob_free(&server_chal);
675 memcpy(request.data.auth_crap.nt_resp, nt_response.data,
676 MIN(nt_response.length,
677 sizeof(request.data.auth_crap.nt_resp)));
678 request.data.auth_crap.nt_resp_len = nt_response.length;
680 memcpy(request.data.auth_crap.lm_resp, lm_response.data,
681 MIN(lm_response.length,
682 sizeof(request.data.auth_crap.lm_resp)));
683 request.data.auth_crap.lm_resp_len = lm_response.length;
685 data_blob_free(&nt_response);
686 data_blob_free(&lm_response);
689 if (lp_client_lanman_auth()
690 && SMBencrypt(pass, request.data.auth_crap.chal,
691 (uchar *)request.data.auth_crap.lm_resp)) {
692 request.data.auth_crap.lm_resp_len = 24;
694 request.data.auth_crap.lm_resp_len = 0;
696 SMBNTencrypt(pass, request.data.auth_crap.chal,
697 (uchar *)request.data.auth_crap.nt_resp);
699 request.data.auth_crap.nt_resp_len = 24;
702 result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);
704 /* Display response */
706 d_printf("challenge/response password authentication %s\n",
707 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
709 if (response.data.auth.nt_status)
710 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
711 response.data.auth.nt_status_string,
712 response.data.auth.nt_status,
713 response.data.auth.error_string);
715 return result == NSS_STATUS_SUCCESS;
718 /* Authenticate a user with a plaintext password and set a token */
720 static BOOL wbinfo_klog(char *username)
722 struct winbindd_request request;
723 struct winbindd_response response;
727 /* Send off request */
729 ZERO_STRUCT(request);
730 ZERO_STRUCT(response);
732 p = strchr(username, '%');
736 fstrcpy(request.data.auth.user, username);
737 fstrcpy(request.data.auth.pass, p + 1);
740 fstrcpy(request.data.auth.user, username);
741 fstrcpy(request.data.auth.pass, getpass("Password: "));
744 request.flags |= WBFLAG_PAM_AFS_TOKEN;
746 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
748 /* Display response */
750 d_printf("plaintext password authentication %s\n",
751 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
753 if (response.data.auth.nt_status)
754 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
755 response.data.auth.nt_status_string,
756 response.data.auth.nt_status,
757 response.data.auth.error_string);
759 if (result != NSS_STATUS_SUCCESS)
762 if (response.extra_data == NULL) {
763 d_fprintf(stderr, "Did not get token data\n");
767 if (!afs_settoken_str((char *)response.extra_data)) {
768 d_fprintf(stderr, "Could not set token\n");
772 d_printf("Successfully created AFS token\n");
776 /* Print domain users */
778 static BOOL print_domain_users(const char *domain)
780 struct winbindd_request request;
781 struct winbindd_response response;
782 const char *extra_data;
785 /* Send request to winbind daemon */
787 ZERO_STRUCT(request);
788 ZERO_STRUCT(response);
791 /* '.' is the special sign for our own domwin */
792 if ( strequal(domain, ".") )
793 fstrcpy( request.domain_name, lp_workgroup() );
795 fstrcpy( request.domain_name, domain );
798 if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
802 /* Look through extra data */
804 if (!response.extra_data)
807 extra_data = (const char *)response.extra_data;
809 while(next_token(&extra_data, name, ",", sizeof(fstring)))
810 d_printf("%s\n", name);
812 SAFE_FREE(response.extra_data);
817 /* Print domain groups */
819 static BOOL print_domain_groups(const char *domain)
821 struct winbindd_request request;
822 struct winbindd_response response;
823 const char *extra_data;
826 ZERO_STRUCT(request);
827 ZERO_STRUCT(response);
830 if ( strequal(domain, ".") )
831 fstrcpy( request.domain_name, lp_workgroup() );
833 fstrcpy( request.domain_name, domain );
836 if (winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response) !=
840 /* Look through extra data */
842 if (!response.extra_data)
845 extra_data = (const char *)response.extra_data;
847 while(next_token(&extra_data, name, ",", sizeof(fstring)))
848 d_printf("%s\n", name);
850 SAFE_FREE(response.extra_data);
855 /* Set the authorised user for winbindd access in secrets.tdb */
857 static BOOL wbinfo_set_auth_user(char *username)
859 const char *password;
861 fstring user, domain;
863 /* Separate into user and password */
865 parse_wbinfo_domain_user(username, domain, user);
867 p = strchr(user, '%');
873 char *thepass = getpass("Password: ");
880 /* Store or remove DOMAIN\username%password in secrets.tdb */
886 if (!secrets_store(SECRETS_AUTH_USER, user,
888 d_fprintf(stderr, "error storing username\n");
892 /* We always have a domain name added by the
893 parse_wbinfo_domain_user() function. */
895 if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
896 strlen(domain) + 1)) {
897 d_fprintf(stderr, "error storing domain name\n");
902 secrets_delete(SECRETS_AUTH_USER);
903 secrets_delete(SECRETS_AUTH_DOMAIN);
908 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
909 strlen(password) + 1)) {
910 d_fprintf(stderr, "error storing password\n");
915 secrets_delete(SECRETS_AUTH_PASSWORD);
920 static void wbinfo_get_auth_user(void)
922 char *user, *domain, *password;
924 /* Lift data from secrets file */
926 secrets_fetch_ipc_userpass(&user, &domain, &password);
928 if ((!user || !*user) && (!domain || !*domain ) && (!password || !*password)){
933 d_printf("No authorised user configured\n");
937 /* Pretty print authorised user info */
939 d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? lp_winbind_separator(): "",
940 user, password ? "%" : "", password ? password : "");
947 static BOOL wbinfo_ping(void)
951 result = winbindd_request_response(WINBINDD_PING, NULL, NULL);
953 /* Display response */
955 d_printf("Ping to winbindd %s on fd %d\n",
956 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", winbindd_fd);
958 return result == NSS_STATUS_SUCCESS;
964 OPT_SET_AUTH_USER = 1000,
974 int main(int argc, char **argv)
979 static char *string_arg;
980 static char *opt_domain_name;
984 struct poptOption long_options[] = {
987 /* longName, shortName, argInfo, argPtr, value, descrip,
990 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
991 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
992 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
993 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
994 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
995 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
996 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
997 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
998 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
999 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1000 { "allocate-rid", 'A', POPT_ARG_NONE, 0, 'A', "Get a new RID out of idmap" },
1001 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1002 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1003 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1004 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1005 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1006 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1007 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1008 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1009 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1010 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1011 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1012 "Get a DC name for a foreign domain", "domainname" },
1013 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1014 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1015 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1016 #ifdef WITH_FAKE_KASERVER
1017 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1019 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1024 /* Samba client initialisation */
1027 if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
1028 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
1029 dyn_CONFIGFILE, strerror(errno));
1040 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
1042 /* Parse command line options */
1045 poptPrintHelp(pc, stderr, 0);
1049 while((opt = poptGetNextOpt(pc)) != -1) {
1050 /* get the generic configuration parameters like --domain */
1053 poptFreeContext(pc);
1055 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1056 POPT_CONTEXT_KEEP_FIRST);
1058 while((opt = poptGetNextOpt(pc)) != -1) {
1061 if (!print_domain_users(opt_domain_name)) {
1062 d_fprintf(stderr, "Error looking up domain users\n");
1067 if (!print_domain_groups(opt_domain_name)) {
1068 d_fprintf(stderr, "Error looking up domain groups\n");
1073 if (!wbinfo_lookupsid(string_arg)) {
1074 d_fprintf(stderr, "Could not lookup sid %s\n", string_arg);
1079 if (!wbinfo_lookupname(string_arg)) {
1080 d_fprintf(stderr, "Could not lookup name %s\n", string_arg);
1085 if (!wbinfo_wins_byname(string_arg)) {
1086 d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg);
1091 if (!wbinfo_wins_byip(string_arg)) {
1092 d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg);
1097 if (!wbinfo_uid_to_sid(int_arg)) {
1098 d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg);
1103 if (!wbinfo_gid_to_sid(int_arg)) {
1104 d_fprintf(stderr, "Could not convert gid %d to sid\n",
1110 if (!wbinfo_sid_to_uid(string_arg)) {
1111 d_fprintf(stderr, "Could not convert sid %s to uid\n",
1117 if (!wbinfo_sid_to_gid(string_arg)) {
1118 d_fprintf(stderr, "Could not convert sid %s to gid\n",
1124 if (!wbinfo_allocate_rid()) {
1125 d_fprintf(stderr, "Could not allocate a RID\n");
1130 if (!wbinfo_check_secret()) {
1131 d_fprintf(stderr, "Could not check secret\n");
1136 if (!wbinfo_list_domains()) {
1137 d_fprintf(stderr, "Could not list trusted domains\n");
1142 if (!wbinfo_show_sequence(opt_domain_name)) {
1143 d_fprintf(stderr, "Could not show sequence numbers\n");
1148 if (!wbinfo_domain_info(string_arg)) {
1149 d_fprintf(stderr, "Could not get domain info\n");
1154 if (!wbinfo_get_usergroups(string_arg)) {
1155 d_fprintf(stderr, "Could not get groups for user %s\n",
1161 if (!wbinfo_get_usersids(string_arg)) {
1162 d_fprintf(stderr, "Could not get group SIDs for user SID %s\n",
1167 case OPT_USERDOMGROUPS:
1168 if (!wbinfo_get_userdomgroups(string_arg)) {
1169 d_fprintf(stderr, "Could not get user's domain groups "
1170 "for user SID %s\n", string_arg);
1175 BOOL got_error = False;
1177 if (!wbinfo_auth(string_arg)) {
1178 d_fprintf(stderr, "Could not authenticate user %s with "
1179 "plaintext password\n", string_arg);
1183 if (!wbinfo_auth_crap(string_arg)) {
1184 d_fprintf(stderr, "Could not authenticate user %s with "
1185 "challenge/response\n", string_arg);
1194 if (!wbinfo_klog(string_arg)) {
1195 d_fprintf(stderr, "Could not klog user\n");
1200 if (!wbinfo_ping()) {
1201 d_fprintf(stderr, "Could not ping winbindd!\n");
1205 case OPT_SET_AUTH_USER:
1206 if (!wbinfo_set_auth_user(string_arg)) {
1210 case OPT_GET_AUTH_USER:
1211 wbinfo_get_auth_user();
1214 if (!wbinfo_getdcname(string_arg)) {
1218 case OPT_SEPARATOR: {
1219 const char sep = winbind_separator_int(True);
1223 d_printf("%c\n", sep);
1226 /* generic configuration options */
1227 case OPT_DOMAIN_NAME:
1230 d_fprintf(stderr, "Invalid option\n");
1231 poptPrintHelp(pc, stderr, 0);
1241 poptFreeContext(pc);