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 /* pull pwent info for a given user */
124 static BOOL wbinfo_get_userinfo(char *user)
126 struct winbindd_request request;
127 struct winbindd_response response;
130 ZERO_STRUCT(request);
131 ZERO_STRUCT(response);
135 fstrcpy(request.data.username, user);
137 result = winbindd_request_response(WINBINDD_GETPWNAM, &request, &response);
139 if (result != NSS_STATUS_SUCCESS)
142 d_printf( "%s:%s:%d:%d:%s:%s:%s\n",
143 response.data.pw.pw_name,
144 response.data.pw.pw_passwd,
145 response.data.pw.pw_uid,
146 response.data.pw.pw_gid,
147 response.data.pw.pw_gecos,
148 response.data.pw.pw_dir,
149 response.data.pw.pw_shell );
154 /* List groups a user is a member of */
156 static BOOL wbinfo_get_usergroups(char *user)
158 struct winbindd_request request;
159 struct winbindd_response response;
163 ZERO_STRUCT(request);
164 ZERO_STRUCT(response);
168 fstrcpy(request.data.username, user);
170 result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
172 if (result != NSS_STATUS_SUCCESS)
175 for (i = 0; i < response.data.num_entries; i++)
176 d_printf("%d\n", (int)((gid_t *)response.extra_data.data)[i]);
178 SAFE_FREE(response.extra_data.data);
184 /* List group SIDs a user SID is a member of */
185 static BOOL wbinfo_get_usersids(char *user_sid)
187 struct winbindd_request request;
188 struct winbindd_response response;
193 ZERO_STRUCT(request);
194 ZERO_STRUCT(response);
197 fstrcpy(request.data.sid, user_sid);
199 result = winbindd_request_response(WINBINDD_GETUSERSIDS, &request, &response);
201 if (result != NSS_STATUS_SUCCESS)
204 s = response.extra_data.data;
205 for (i = 0; i < response.data.num_entries; i++) {
210 SAFE_FREE(response.extra_data.data);
215 static BOOL wbinfo_get_userdomgroups(const char *user_sid)
217 struct winbindd_request request;
218 struct winbindd_response response;
221 ZERO_STRUCT(request);
222 ZERO_STRUCT(response);
225 fstrcpy(request.data.sid, user_sid);
227 result = winbindd_request_response(WINBINDD_GETUSERDOMGROUPS, &request,
230 if (result != NSS_STATUS_SUCCESS)
233 if (response.data.num_entries != 0)
234 printf("%s", (char *)response.extra_data.data);
236 SAFE_FREE(response.extra_data.data);
241 /* Convert NetBIOS name to IP */
243 static BOOL wbinfo_wins_byname(char *name)
245 struct winbindd_request request;
246 struct winbindd_response response;
248 ZERO_STRUCT(request);
249 ZERO_STRUCT(response);
253 fstrcpy(request.data.winsreq, name);
255 if (winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response) !=
256 NSS_STATUS_SUCCESS) {
260 /* Display response */
262 d_printf("%s\n", response.data.winsresp);
267 /* Convert IP to NetBIOS name */
269 static BOOL wbinfo_wins_byip(char *ip)
271 struct winbindd_request request;
272 struct winbindd_response response;
274 ZERO_STRUCT(request);
275 ZERO_STRUCT(response);
279 fstrcpy(request.data.winsreq, ip);
281 if (winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response) !=
282 NSS_STATUS_SUCCESS) {
286 /* Display response */
288 d_printf("%s\n", response.data.winsresp);
293 /* List trusted domains */
295 static BOOL wbinfo_list_domains(BOOL list_all_domains)
297 struct winbindd_request request;
298 struct winbindd_response response;
300 ZERO_STRUCT(request);
301 ZERO_STRUCT(response);
305 request.data.list_all_domains = list_all_domains;
307 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, &request, &response) !=
311 /* Display response */
313 if (response.extra_data.data) {
314 const char *extra_data = (char *)response.extra_data.data;
318 while(next_token(&extra_data, name, "\n", sizeof(fstring))) {
319 p = strchr(name, '\\');
321 d_fprintf(stderr, "Got invalid response: %s\n",
326 d_printf("%s\n", name);
329 SAFE_FREE(response.extra_data.data);
335 /* List own domain */
337 static BOOL wbinfo_list_own_domain(void)
339 d_printf("%s\n", get_winbind_domain());
344 /* show sequence numbers */
345 static BOOL wbinfo_show_sequence(const char *domain)
347 struct winbindd_request request;
348 struct winbindd_response response;
350 ZERO_STRUCT(response);
351 ZERO_STRUCT(request);
354 fstrcpy( request.domain_name, domain );
358 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
362 /* Display response */
364 if (response.extra_data.data) {
365 char *extra_data = (char *)response.extra_data.data;
366 d_printf("%s", extra_data);
367 SAFE_FREE(response.extra_data.data);
373 /* Show domain info */
375 static BOOL wbinfo_domain_info(const char *domain_name)
377 struct winbindd_request request;
378 struct winbindd_response response;
380 ZERO_STRUCT(request);
381 ZERO_STRUCT(response);
383 if ((strequal(domain_name, ".")) || (domain_name[0] == '\0'))
384 fstrcpy(request.domain_name, get_winbind_domain());
386 fstrcpy(request.domain_name, domain_name);
390 if (winbindd_request_response(WINBINDD_DOMAIN_INFO, &request, &response) !=
394 /* Display response */
396 d_printf("Name : %s\n", response.data.domain_info.name);
397 d_printf("Alt_Name : %s\n", response.data.domain_info.alt_name);
399 d_printf("SID : %s\n", response.data.domain_info.sid);
401 d_printf("Active Directory : %s\n",
402 response.data.domain_info.active_directory ? "Yes" : "No");
403 d_printf("Native : %s\n",
404 response.data.domain_info.native_mode ? "Yes" : "No");
406 d_printf("Primary : %s\n",
407 response.data.domain_info.primary ? "Yes" : "No");
409 d_printf("Sequence : %d\n", response.data.domain_info.sequence_number);
414 /* Get a foreign DC's name */
415 static BOOL wbinfo_getdcname(const char *domain_name)
417 struct winbindd_request request;
418 struct winbindd_response response;
420 ZERO_STRUCT(request);
421 ZERO_STRUCT(response);
423 fstrcpy(request.domain_name, domain_name);
427 if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) !=
428 NSS_STATUS_SUCCESS) {
429 d_fprintf(stderr, "Could not get dc name for %s\n", domain_name);
433 /* Display response */
435 d_printf("%s\n", response.data.dc_name);
440 /* Check trust account password */
442 static BOOL wbinfo_check_secret(void)
444 struct winbindd_response response;
447 ZERO_STRUCT(response);
449 result = winbindd_request_response(WINBINDD_CHECK_MACHACC, NULL, &response);
451 d_printf("checking the trust secret via RPC calls %s\n",
452 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
454 if (result != NSS_STATUS_SUCCESS)
455 d_fprintf(stderr, "error code was %s (0x%x)\n",
456 response.data.auth.nt_status_string,
457 response.data.auth.nt_status);
459 return result == NSS_STATUS_SUCCESS;
462 /* Convert uid to sid */
464 static BOOL wbinfo_uid_to_sid(uid_t uid)
466 struct winbindd_request request;
467 struct winbindd_response response;
469 ZERO_STRUCT(request);
470 ZERO_STRUCT(response);
474 request.data.uid = uid;
476 if (winbindd_request_response(WINBINDD_UID_TO_SID, &request, &response) !=
480 /* Display response */
482 d_printf("%s\n", response.data.sid.sid);
487 /* Convert gid to sid */
489 static BOOL wbinfo_gid_to_sid(gid_t gid)
491 struct winbindd_request request;
492 struct winbindd_response response;
494 ZERO_STRUCT(request);
495 ZERO_STRUCT(response);
499 request.data.gid = gid;
501 if (winbindd_request_response(WINBINDD_GID_TO_SID, &request, &response) !=
505 /* Display response */
507 d_printf("%s\n", response.data.sid.sid);
512 /* Convert sid to uid */
514 static BOOL wbinfo_sid_to_uid(char *sid)
516 struct winbindd_request request;
517 struct winbindd_response response;
519 ZERO_STRUCT(request);
520 ZERO_STRUCT(response);
524 fstrcpy(request.data.sid, sid);
526 if (winbindd_request_response(WINBINDD_SID_TO_UID, &request, &response) !=
530 /* Display response */
532 d_printf("%d\n", (int)response.data.uid);
537 static BOOL wbinfo_sid_to_gid(char *sid)
539 struct winbindd_request request;
540 struct winbindd_response response;
542 ZERO_STRUCT(request);
543 ZERO_STRUCT(response);
547 fstrcpy(request.data.sid, sid);
549 if (winbindd_request_response(WINBINDD_SID_TO_GID, &request, &response) !=
553 /* Display response */
555 d_printf("%d\n", (int)response.data.gid);
560 static BOOL wbinfo_allocate_uid(void)
564 if (!winbind_allocate_uid(&uid))
567 d_printf("New uid: %d\n", uid);
572 static BOOL wbinfo_allocate_gid(void)
576 if (!winbind_allocate_gid(&gid))
579 d_printf("New gid: %d\n", gid);
584 /* Convert sid to string */
586 static BOOL wbinfo_lookupsid(char *sid)
588 struct winbindd_request request;
589 struct winbindd_response response;
591 ZERO_STRUCT(request);
592 ZERO_STRUCT(response);
594 /* Send off request */
596 fstrcpy(request.data.sid, sid);
598 if (winbindd_request_response(WINBINDD_LOOKUPSID, &request, &response) !=
602 /* Display response */
604 d_printf("%s%c%s %d\n", response.data.name.dom_name,
605 winbind_separator(), response.data.name.name,
606 response.data.name.type);
611 /* Convert string to sid */
613 static BOOL wbinfo_lookupname(char *name)
615 struct winbindd_request request;
616 struct winbindd_response response;
618 /* Send off request */
620 ZERO_STRUCT(request);
621 ZERO_STRUCT(response);
623 parse_wbinfo_domain_user(name, request.data.name.dom_name,
624 request.data.name.name);
626 if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
630 /* Display response */
632 d_printf("%s %s (%d)\n", response.data.sid.sid, sid_type_lookup(response.data.sid.type), response.data.sid.type);
637 /* Authenticate a user with a plaintext password */
639 static BOOL wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
641 struct winbindd_request request;
642 struct winbindd_response response;
646 /* Send off request */
648 ZERO_STRUCT(request);
649 ZERO_STRUCT(response);
651 p = strchr(username, '%');
655 fstrcpy(request.data.auth.user, username);
656 fstrcpy(request.data.auth.pass, p + 1);
659 fstrcpy(request.data.auth.user, username);
661 request.flags = flags;
663 fstrcpy(request.data.auth.krb5_cc_type, cctype);
665 request.data.auth.uid = geteuid();
667 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
669 /* Display response */
671 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
672 username, (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", cctype);
674 if (response.data.auth.nt_status)
675 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
676 response.data.auth.nt_status_string,
677 response.data.auth.nt_status,
678 response.data.auth.error_string);
680 if (result == NSS_STATUS_SUCCESS) {
682 if (request.flags & WBFLAG_PAM_INFO3_TEXT) {
683 if (response.data.auth.info3.user_flgs & LOGON_CACHED_ACCOUNT) {
684 d_printf("user_flgs: LOGON_CACHED_ACCOUNT\n");
688 if (response.data.auth.krb5ccname[0] != '\0') {
689 d_printf("credentials were put in: %s\n", response.data.auth.krb5ccname);
691 d_printf("no credentials cached\n");
695 return result == NSS_STATUS_SUCCESS;
698 /* Authenticate a user with a plaintext password */
700 static BOOL wbinfo_auth(char *username)
702 struct winbindd_request request;
703 struct winbindd_response response;
707 /* Send off request */
709 ZERO_STRUCT(request);
710 ZERO_STRUCT(response);
712 p = strchr(username, '%');
716 fstrcpy(request.data.auth.user, username);
717 fstrcpy(request.data.auth.pass, p + 1);
720 fstrcpy(request.data.auth.user, username);
722 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
724 /* Display response */
726 d_printf("plaintext password authentication %s\n",
727 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
729 if (response.data.auth.nt_status)
730 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
731 response.data.auth.nt_status_string,
732 response.data.auth.nt_status,
733 response.data.auth.error_string);
735 return result == NSS_STATUS_SUCCESS;
738 /* Authenticate a user with a challenge/response */
740 static BOOL wbinfo_auth_crap(char *username)
742 struct winbindd_request request;
743 struct winbindd_response response;
750 /* Send off request */
752 ZERO_STRUCT(request);
753 ZERO_STRUCT(response);
755 p = strchr(username, '%');
759 fstrcpy(pass, p + 1);
762 parse_wbinfo_domain_user(username, name_domain, name_user);
764 request.data.auth_crap.logon_parameters = MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT | MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
766 fstrcpy(request.data.auth_crap.user, name_user);
768 fstrcpy(request.data.auth_crap.domain,
771 generate_random_buffer(request.data.auth_crap.chal, 8);
773 if (lp_client_ntlmv2_auth()) {
774 DATA_BLOB server_chal;
775 DATA_BLOB names_blob;
777 DATA_BLOB lm_response;
778 DATA_BLOB nt_response;
780 server_chal = data_blob(request.data.auth_crap.chal, 8);
782 /* Pretend this is a login to 'us', for blob purposes */
783 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
785 if (!SMBNTLMv2encrypt(name_user, name_domain, pass, &server_chal,
787 &lm_response, &nt_response, NULL)) {
788 data_blob_free(&names_blob);
789 data_blob_free(&server_chal);
792 data_blob_free(&names_blob);
793 data_blob_free(&server_chal);
795 memcpy(request.data.auth_crap.nt_resp, nt_response.data,
796 MIN(nt_response.length,
797 sizeof(request.data.auth_crap.nt_resp)));
798 request.data.auth_crap.nt_resp_len = nt_response.length;
800 memcpy(request.data.auth_crap.lm_resp, lm_response.data,
801 MIN(lm_response.length,
802 sizeof(request.data.auth_crap.lm_resp)));
803 request.data.auth_crap.lm_resp_len = lm_response.length;
805 data_blob_free(&nt_response);
806 data_blob_free(&lm_response);
809 if (lp_client_lanman_auth()
810 && SMBencrypt(pass, request.data.auth_crap.chal,
811 (uchar *)request.data.auth_crap.lm_resp)) {
812 request.data.auth_crap.lm_resp_len = 24;
814 request.data.auth_crap.lm_resp_len = 0;
816 SMBNTencrypt(pass, request.data.auth_crap.chal,
817 (uchar *)request.data.auth_crap.nt_resp);
819 request.data.auth_crap.nt_resp_len = 24;
822 result = winbindd_request_response(WINBINDD_PAM_AUTH_CRAP, &request, &response);
824 /* Display response */
826 d_printf("challenge/response password authentication %s\n",
827 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
829 if (response.data.auth.nt_status)
830 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
831 response.data.auth.nt_status_string,
832 response.data.auth.nt_status,
833 response.data.auth.error_string);
835 return result == NSS_STATUS_SUCCESS;
838 /* Authenticate a user with a plaintext password and set a token */
840 static BOOL wbinfo_klog(char *username)
842 struct winbindd_request request;
843 struct winbindd_response response;
847 /* Send off request */
849 ZERO_STRUCT(request);
850 ZERO_STRUCT(response);
852 p = strchr(username, '%');
856 fstrcpy(request.data.auth.user, username);
857 fstrcpy(request.data.auth.pass, p + 1);
860 fstrcpy(request.data.auth.user, username);
861 fstrcpy(request.data.auth.pass, getpass("Password: "));
864 request.flags |= WBFLAG_PAM_AFS_TOKEN;
866 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
868 /* Display response */
870 d_printf("plaintext password authentication %s\n",
871 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
873 if (response.data.auth.nt_status)
874 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
875 response.data.auth.nt_status_string,
876 response.data.auth.nt_status,
877 response.data.auth.error_string);
879 if (result != NSS_STATUS_SUCCESS)
882 if (response.extra_data.data == NULL) {
883 d_fprintf(stderr, "Did not get token data\n");
887 if (!afs_settoken_str((char *)response.extra_data.data)) {
888 d_fprintf(stderr, "Could not set token\n");
892 d_printf("Successfully created AFS token\n");
896 /* Print domain users */
898 static BOOL print_domain_users(const char *domain)
900 struct winbindd_request request;
901 struct winbindd_response response;
902 const char *extra_data;
905 /* Send request to winbind daemon */
907 ZERO_STRUCT(request);
908 ZERO_STRUCT(response);
911 /* '.' is the special sign for our own domain */
912 if ( strequal(domain, ".") )
913 fstrcpy( request.domain_name, get_winbind_domain() );
915 fstrcpy( request.domain_name, domain );
918 if (winbindd_request_response(WINBINDD_LIST_USERS, &request, &response) !=
922 /* Look through extra data */
924 if (!response.extra_data.data)
927 extra_data = (const char *)response.extra_data.data;
929 while(next_token(&extra_data, name, ",", sizeof(fstring)))
930 d_printf("%s\n", name);
932 SAFE_FREE(response.extra_data.data);
937 /* Print domain groups */
939 static BOOL print_domain_groups(const char *domain)
941 struct winbindd_request request;
942 struct winbindd_response response;
943 const char *extra_data;
946 ZERO_STRUCT(request);
947 ZERO_STRUCT(response);
950 if ( strequal(domain, ".") )
951 fstrcpy( request.domain_name, get_winbind_domain() );
953 fstrcpy( request.domain_name, domain );
956 if (winbindd_request_response(WINBINDD_LIST_GROUPS, &request, &response) !=
960 /* Look through extra data */
962 if (!response.extra_data.data)
965 extra_data = (const char *)response.extra_data.data;
967 while(next_token(&extra_data, name, ",", sizeof(fstring)))
968 d_printf("%s\n", name);
970 SAFE_FREE(response.extra_data.data);
975 /* Set the authorised user for winbindd access in secrets.tdb */
977 static BOOL wbinfo_set_auth_user(char *username)
979 const char *password;
981 fstring user, domain;
983 /* Separate into user and password */
985 parse_wbinfo_domain_user(username, domain, user);
987 p = strchr(user, '%');
993 char *thepass = getpass("Password: ");
1000 /* Store or remove DOMAIN\username%password in secrets.tdb */
1006 if (!secrets_store(SECRETS_AUTH_USER, user,
1007 strlen(user) + 1)) {
1008 d_fprintf(stderr, "error storing username\n");
1012 /* We always have a domain name added by the
1013 parse_wbinfo_domain_user() function. */
1015 if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
1016 strlen(domain) + 1)) {
1017 d_fprintf(stderr, "error storing domain name\n");
1022 secrets_delete(SECRETS_AUTH_USER);
1023 secrets_delete(SECRETS_AUTH_DOMAIN);
1028 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
1029 strlen(password) + 1)) {
1030 d_fprintf(stderr, "error storing password\n");
1035 secrets_delete(SECRETS_AUTH_PASSWORD);
1040 static void wbinfo_get_auth_user(void)
1042 char *user, *domain, *password;
1044 /* Lift data from secrets file */
1046 secrets_fetch_ipc_userpass(&user, &domain, &password);
1048 if ((!user || !*user) && (!domain || !*domain ) && (!password || !*password)){
1052 SAFE_FREE(password);
1053 d_printf("No authorised user configured\n");
1057 /* Pretty print authorised user info */
1059 d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? lp_winbind_separator(): "",
1060 user, password ? "%" : "", password ? password : "");
1064 SAFE_FREE(password);
1067 static BOOL wbinfo_ping(void)
1071 result = winbindd_request_response(WINBINDD_PING, NULL, NULL);
1073 /* Display response */
1075 d_printf("Ping to winbindd %s on fd %d\n",
1076 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", winbindd_fd);
1078 return result == NSS_STATUS_SUCCESS;
1084 OPT_SET_AUTH_USER = 1000,
1094 OPT_LIST_ALL_DOMAINS,
1098 int main(int argc, char **argv)
1103 static char *string_arg;
1104 static char *opt_domain_name;
1108 struct poptOption long_options[] = {
1111 /* longName, shortName, argInfo, argPtr, value, descrip,
1114 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1115 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1116 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1117 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1118 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1119 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1120 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1121 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1122 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1123 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1124 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1125 "Get a new UID out of idmap" },
1126 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1127 "Get a new GID out of idmap" },
1128 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1129 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1130 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1131 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1132 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1133 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1134 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1135 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1136 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1137 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1138 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1139 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1140 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1141 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1142 "Get a DC name for a foreign domain", "domainname" },
1143 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1144 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1145 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1146 #ifdef WITH_FAKE_KASERVER
1147 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1150 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1151 /* destroys wbinfo --help output */
1152 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1154 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1159 /* Samba client initialisation */
1162 if (!lp_load(dyn_CONFIGFILE, True, False, False, True)) {
1163 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
1164 dyn_CONFIGFILE, strerror(errno));
1175 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
1177 /* Parse command line options */
1180 poptPrintHelp(pc, stderr, 0);
1184 while((opt = poptGetNextOpt(pc)) != -1) {
1185 /* get the generic configuration parameters like --domain */
1188 poptFreeContext(pc);
1190 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1191 POPT_CONTEXT_KEEP_FIRST);
1193 while((opt = poptGetNextOpt(pc)) != -1) {
1196 if (!print_domain_users(opt_domain_name)) {
1197 d_fprintf(stderr, "Error looking up domain users\n");
1202 if (!print_domain_groups(opt_domain_name)) {
1203 d_fprintf(stderr, "Error looking up domain groups\n");
1208 if (!wbinfo_lookupsid(string_arg)) {
1209 d_fprintf(stderr, "Could not lookup sid %s\n", string_arg);
1214 if (!wbinfo_lookupname(string_arg)) {
1215 d_fprintf(stderr, "Could not lookup name %s\n", string_arg);
1220 if (!wbinfo_wins_byname(string_arg)) {
1221 d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg);
1226 if (!wbinfo_wins_byip(string_arg)) {
1227 d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg);
1232 if (!wbinfo_uid_to_sid(int_arg)) {
1233 d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg);
1238 if (!wbinfo_gid_to_sid(int_arg)) {
1239 d_fprintf(stderr, "Could not convert gid %d to sid\n",
1245 if (!wbinfo_sid_to_uid(string_arg)) {
1246 d_fprintf(stderr, "Could not convert sid %s to uid\n",
1252 if (!wbinfo_sid_to_gid(string_arg)) {
1253 d_fprintf(stderr, "Could not convert sid %s to gid\n",
1258 case OPT_ALLOCATE_UID:
1259 if (!wbinfo_allocate_uid()) {
1260 d_fprintf(stderr, "Could not allocate a uid\n");
1264 case OPT_ALLOCATE_GID:
1265 if (!wbinfo_allocate_gid()) {
1266 d_fprintf(stderr, "Could not allocate a gid\n");
1271 if (!wbinfo_check_secret()) {
1272 d_fprintf(stderr, "Could not check secret\n");
1277 if (!wbinfo_list_domains(False)) {
1278 d_fprintf(stderr, "Could not list trusted domains\n");
1283 if (!wbinfo_show_sequence(opt_domain_name)) {
1284 d_fprintf(stderr, "Could not show sequence numbers\n");
1289 if (!wbinfo_domain_info(string_arg)) {
1290 d_fprintf(stderr, "Could not get domain info\n");
1295 if (!wbinfo_get_userinfo(string_arg)) {
1296 d_fprintf(stderr, "Could not get info for user %s\n",
1302 if (!wbinfo_get_usergroups(string_arg)) {
1303 d_fprintf(stderr, "Could not get groups for user %s\n",
1309 if (!wbinfo_get_usersids(string_arg)) {
1310 d_fprintf(stderr, "Could not get group SIDs for user SID %s\n",
1315 case OPT_USERDOMGROUPS:
1316 if (!wbinfo_get_userdomgroups(string_arg)) {
1317 d_fprintf(stderr, "Could not get user's domain groups "
1318 "for user SID %s\n", string_arg);
1323 BOOL got_error = False;
1325 if (!wbinfo_auth(string_arg)) {
1326 d_fprintf(stderr, "Could not authenticate user %s with "
1327 "plaintext password\n", string_arg);
1331 if (!wbinfo_auth_crap(string_arg)) {
1332 d_fprintf(stderr, "Could not authenticate user %s with "
1333 "challenge/response\n", string_arg);
1342 BOOL got_error = False;
1343 uint32 flags = WBFLAG_PAM_KRB5 |
1344 WBFLAG_PAM_CACHED_LOGIN |
1345 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
1346 WBFLAG_PAM_INFO3_TEXT;
1349 const char *arg[] = { NULL, NULL };
1350 const char *cctypes[] = { "FILE",
1357 arg[0] = string_arg;
1359 while (next_token(arg, tok, LIST_SEP, sizeof(tok))) {
1361 for (i=0; i < ARRAY_SIZE(cctypes); i++) {
1362 if (!wbinfo_auth_krb5(tok, cctypes[i], flags)) {
1363 d_fprintf(stderr, "Could not authenticate user [%s] with "
1364 "Kerberos (ccache: %s)\n", tok, cctypes[i]);
1376 if (!wbinfo_klog(string_arg)) {
1377 d_fprintf(stderr, "Could not klog user\n");
1382 if (!wbinfo_ping()) {
1383 d_fprintf(stderr, "could not ping winbindd!\n");
1387 case OPT_SET_AUTH_USER:
1388 if (!wbinfo_set_auth_user(string_arg)) {
1392 case OPT_GET_AUTH_USER:
1393 wbinfo_get_auth_user();
1396 if (!wbinfo_getdcname(string_arg)) {
1400 case OPT_SEPARATOR: {
1401 const char sep = winbind_separator_int(True);
1405 d_printf("%c\n", sep);
1408 case OPT_LIST_ALL_DOMAINS:
1409 if (!wbinfo_list_domains(True)) {
1413 case OPT_LIST_OWN_DOMAIN:
1414 if (!wbinfo_list_own_domain()) {
1418 /* generic configuration options */
1419 case OPT_DOMAIN_NAME:
1422 d_fprintf(stderr, "Invalid option\n");
1423 poptPrintHelp(pc, stderr, 0);
1433 poptFreeContext(pc);