2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
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 3 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, see <http://www.gnu.org/licenses/>.
25 #include "winbind_nss_config.h"
26 #include "winbindd_nss.h"
27 #include "winbind_client.h"
28 #include "librpc/gen_ndr/ndr_netlogon.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "libcli/security/security.h"
31 #include "lib/cmdline/popt_common.h"
32 #include "dynconfig.h"
34 extern int winbindd_fd;
36 static char winbind_separator_int(BOOL strict)
38 struct winbindd_response response;
45 ZERO_STRUCT(response);
47 /* Send off request */
49 if (winbindd_request(WINBINDD_INFO, NULL, &response) !=
51 d_fprintf(stderr, "could not obtain winbind separator!\n");
55 /* HACK: (this module should not call lp_ funtions) */
56 return *lp_winbind_separator();
59 sep = response.data.info.winbind_separator;
63 d_fprintf(stderr, "winbind separator was NULL!\n");
67 /* HACK: (this module should not call lp_ funtions) */
68 sep = *lp_winbind_separator();
74 static char winbind_separator(void)
76 return winbind_separator_int(False);
79 static const char *get_winbind_domain(void)
81 struct winbindd_response response;
82 static fstring winbind_domain;
84 ZERO_STRUCT(response);
86 /* Send off request */
88 if (winbindd_request(WINBINDD_DOMAIN_NAME, NULL, &response) !=
90 d_fprintf(stderr, "could not obtain winbind domain name!\n");
92 /* HACK: (this module should not call lp_ funtions) */
93 return lp_workgroup();
96 fstrcpy(winbind_domain, response.data.domain_name);
98 return winbind_domain;
102 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
103 form DOMAIN/user into a domain and a user */
105 static BOOL parse_wbinfo_domain_user(const char *domuser, fstring domain,
109 char *p = strchr(domuser,winbind_separator());
112 fstrcpy(user, domuser);
113 fstrcpy(domain, get_winbind_domain());
118 fstrcpy(domain, domuser);
119 domain[PTR_DIFF(p, domuser)] = 0;
125 /* pull pwent info for a given user */
127 static BOOL wbinfo_get_userinfo(char *user)
129 struct winbindd_request request;
130 struct winbindd_response response;
133 ZERO_STRUCT(request);
134 ZERO_STRUCT(response);
138 fstrcpy(request.data.username, user);
140 result = winbindd_request(WINBINDD_GETPWNAM, &request, &response);
142 if (result != NSS_STATUS_SUCCESS)
145 d_printf( "%s:%s:%d:%d:%s:%s:%s\n",
146 response.data.pw.pw_name,
147 response.data.pw.pw_passwd,
148 response.data.pw.pw_uid,
149 response.data.pw.pw_gid,
150 response.data.pw.pw_gecos,
151 response.data.pw.pw_dir,
152 response.data.pw.pw_shell );
157 /* pull pwent info for a given uid */
158 static BOOL wbinfo_get_uidinfo(int uid)
160 struct winbindd_request request;
161 struct winbindd_response response;
164 ZERO_STRUCT(request);
165 ZERO_STRUCT(response);
167 request.data.uid = uid;
169 result = winbindd_request(WINBINDD_GETPWUID, &request, &response);
171 if (result != NSS_STATUS_SUCCESS)
174 d_printf( "%s:%s:%d:%d:%s:%s:%s\n",
175 response.data.pw.pw_name,
176 response.data.pw.pw_passwd,
177 response.data.pw.pw_uid,
178 response.data.pw.pw_gid,
179 response.data.pw.pw_gecos,
180 response.data.pw.pw_dir,
181 response.data.pw.pw_shell );
186 /* pull grent for a given group */
187 static BOOL wbinfo_get_groupinfo(char *group)
189 struct winbindd_request request;
190 struct winbindd_response response;
193 ZERO_STRUCT(request);
194 ZERO_STRUCT(response);
198 fstrcpy(request.data.groupname, group);
200 result = winbindd_request(WINBINDD_GETGRNAM, &request,
203 if ( result != NSS_STATUS_SUCCESS)
206 d_printf( "%s:%s:%d\n",
207 response.data.gr.gr_name,
208 response.data.gr.gr_passwd,
209 response.data.gr.gr_gid );
214 /* List groups a user is a member of */
216 static BOOL wbinfo_get_usergroups(char *user)
218 struct winbindd_request request;
219 struct winbindd_response response;
223 ZERO_STRUCT(request);
224 ZERO_STRUCT(response);
228 fstrcpy(request.data.username, user);
230 result = winbindd_request(WINBINDD_GETGROUPS, &request, &response);
232 if (result != NSS_STATUS_SUCCESS)
235 for (i = 0; i < response.data.num_entries; i++)
236 d_printf("%d\n", (int)((gid_t *)response.extra_data.data)[i]);
238 SAFE_FREE(response.extra_data.data);
244 /* List group SIDs a user SID is a member of */
245 static BOOL wbinfo_get_usersids(char *user_sid)
247 struct winbindd_request request;
248 struct winbindd_response response;
253 ZERO_STRUCT(request);
254 ZERO_STRUCT(response);
257 fstrcpy(request.data.sid, user_sid);
259 result = winbindd_request(WINBINDD_GETUSERSIDS, &request, &response);
261 if (result != NSS_STATUS_SUCCESS)
264 s = (const char *)response.extra_data.data;
265 for (i = 0; i < response.data.num_entries; i++) {
270 SAFE_FREE(response.extra_data.data);
275 static BOOL wbinfo_get_userdomgroups(const char *user_sid)
277 struct winbindd_request request;
278 struct winbindd_response response;
281 ZERO_STRUCT(request);
282 ZERO_STRUCT(response);
285 fstrcpy(request.data.sid, user_sid);
287 result = winbindd_request(WINBINDD_GETUSERDOMGROUPS, &request,
290 if (result != NSS_STATUS_SUCCESS)
293 if (response.data.num_entries != 0)
294 printf("%s", (char *)response.extra_data.data);
296 SAFE_FREE(response.extra_data.data);
301 /* Convert NetBIOS name to IP */
303 static BOOL wbinfo_wins_byname(char *name)
305 struct winbindd_request request;
306 struct winbindd_response response;
308 ZERO_STRUCT(request);
309 ZERO_STRUCT(response);
313 fstrcpy(request.data.winsreq, name);
315 if (winbindd_request(WINBINDD_WINS_BYNAME, &request, &response) !=
316 NSS_STATUS_SUCCESS) {
320 /* Display response */
322 d_printf("%s\n", response.data.winsresp);
327 /* Convert IP to NetBIOS name */
329 static BOOL wbinfo_wins_byip(char *ip)
331 struct winbindd_request request;
332 struct winbindd_response response;
334 ZERO_STRUCT(request);
335 ZERO_STRUCT(response);
339 fstrcpy(request.data.winsreq, ip);
341 if (winbindd_request(WINBINDD_WINS_BYIP, &request, &response) !=
342 NSS_STATUS_SUCCESS) {
346 /* Display response */
348 d_printf("%s\n", response.data.winsresp);
353 /* List trusted domains */
355 static BOOL wbinfo_list_domains(BOOL list_all_domains)
357 struct winbindd_request request;
358 struct winbindd_response response;
360 ZERO_STRUCT(request);
361 ZERO_STRUCT(response);
365 request.data.list_all_domains = list_all_domains;
367 if (winbindd_request(WINBINDD_LIST_TRUSTDOM, &request, &response) !=
371 /* Display response */
373 if (response.extra_data.data) {
374 const char *extra_data = (char *)response.extra_data.data;
378 while(next_token(&extra_data, name, "\n", sizeof(fstring))) {
379 p = strchr(name, '\\');
381 d_fprintf(stderr, "Got invalid response: %s\n",
386 d_printf("%s\n", name);
389 SAFE_FREE(response.extra_data.data);
395 /* List own domain */
397 static BOOL wbinfo_list_own_domain(void)
399 d_printf("%s\n", get_winbind_domain());
404 /* show sequence numbers */
405 static BOOL wbinfo_show_sequence(const char *domain)
407 struct winbindd_request request;
408 struct winbindd_response response;
410 ZERO_STRUCT(response);
411 ZERO_STRUCT(request);
414 fstrcpy( request.domain_name, domain );
418 if (winbindd_request(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
422 /* Display response */
424 if (response.extra_data.data) {
425 char *extra_data = (char *)response.extra_data.data;
426 d_printf("%s", extra_data);
427 SAFE_FREE(response.extra_data.data);
433 /* Show domain info */
435 static BOOL wbinfo_domain_info(const char *domain_name)
437 struct winbindd_request request;
438 struct winbindd_response response;
440 ZERO_STRUCT(request);
441 ZERO_STRUCT(response);
443 if ((strequal(domain_name, ".")) || (domain_name[0] == '\0'))
444 fstrcpy(request.domain_name, get_winbind_domain());
446 fstrcpy(request.domain_name, domain_name);
450 if (winbindd_request(WINBINDD_DOMAIN_INFO, &request, &response) !=
454 /* Display response */
456 d_printf("Name : %s\n", response.data.domain_info.name);
457 d_printf("Alt_Name : %s\n", response.data.domain_info.alt_name);
459 d_printf("SID : %s\n", response.data.domain_info.sid);
461 d_printf("Active Directory : %s\n",
462 response.data.domain_info.active_directory ? "Yes" : "No");
463 d_printf("Native : %s\n",
464 response.data.domain_info.native_mode ? "Yes" : "No");
466 d_printf("Primary : %s\n",
467 response.data.domain_info.primary ? "Yes" : "No");
469 d_printf("Sequence : %d\n", response.data.domain_info.sequence_number);
474 /* Get a foreign DC's name */
475 static BOOL wbinfo_getdcname(const char *domain_name)
477 struct winbindd_request request;
478 struct winbindd_response response;
480 ZERO_STRUCT(request);
481 ZERO_STRUCT(response);
483 fstrcpy(request.domain_name, domain_name);
487 if (winbindd_request(WINBINDD_GETDCNAME, &request, &response) !=
488 NSS_STATUS_SUCCESS) {
489 d_fprintf(stderr, "Could not get dc name for %s\n", domain_name);
493 /* Display response */
495 d_printf("%s\n", response.data.dc_name);
500 /* Check trust account password */
502 static BOOL wbinfo_check_secret(void)
504 struct winbindd_response response;
507 ZERO_STRUCT(response);
509 result = winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response);
511 d_printf("checking the trust secret via RPC calls %s\n",
512 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
514 if (result != NSS_STATUS_SUCCESS)
515 d_fprintf(stderr, "error code was %s (0x%x)\n",
516 response.data.auth.nt_status_string,
517 response.data.auth.nt_status);
519 return result == NSS_STATUS_SUCCESS;
522 /* Convert uid to sid */
524 static BOOL wbinfo_uid_to_sid(uid_t uid)
526 struct winbindd_request request;
527 struct winbindd_response response;
529 ZERO_STRUCT(request);
530 ZERO_STRUCT(response);
534 request.data.uid = uid;
536 if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) !=
540 /* Display response */
542 d_printf("%s\n", response.data.sid.sid);
547 /* Convert gid to sid */
549 static BOOL wbinfo_gid_to_sid(gid_t gid)
551 struct winbindd_request request;
552 struct winbindd_response response;
554 ZERO_STRUCT(request);
555 ZERO_STRUCT(response);
559 request.data.gid = gid;
561 if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) !=
565 /* Display response */
567 d_printf("%s\n", response.data.sid.sid);
572 /* Convert sid to uid */
574 static BOOL wbinfo_sid_to_uid(char *sid)
576 struct winbindd_request request;
577 struct winbindd_response response;
579 ZERO_STRUCT(request);
580 ZERO_STRUCT(response);
584 fstrcpy(request.data.sid, sid);
586 if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) !=
590 /* Display response */
592 d_printf("%d\n", (int)response.data.uid);
597 static BOOL wbinfo_sid_to_gid(char *sid)
599 struct winbindd_request request;
600 struct winbindd_response response;
602 ZERO_STRUCT(request);
603 ZERO_STRUCT(response);
607 fstrcpy(request.data.sid, sid);
609 if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) !=
613 /* Display response */
615 d_printf("%d\n", (int)response.data.gid);
620 /* Convert sid to string */
622 static BOOL wbinfo_lookupsid(char *sid)
624 struct winbindd_request request;
625 struct winbindd_response response;
627 ZERO_STRUCT(request);
628 ZERO_STRUCT(response);
630 /* Send off request */
632 fstrcpy(request.data.sid, sid);
634 if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) !=
638 /* Display response */
640 d_printf("%s%c%s %d\n", response.data.name.dom_name,
641 winbind_separator(), response.data.name.name,
642 response.data.name.type);
647 static const char *sid_type_lookup(enum lsa_SidType r)
650 case SID_NAME_USE_NONE: return "SID_NAME_USE_NONE"; break;
651 case SID_NAME_USER: return "SID_NAME_USER"; break;
652 case SID_NAME_DOM_GRP: return "SID_NAME_DOM_GRP"; break;
653 case SID_NAME_DOMAIN: return "SID_NAME_DOMAIN"; break;
654 case SID_NAME_ALIAS: return "SID_NAME_ALIAS"; break;
655 case SID_NAME_WKN_GRP: return "SID_NAME_WKN_GRP"; break;
656 case SID_NAME_DELETED: return "SID_NAME_DELETED"; break;
657 case SID_NAME_INVALID: return "SID_NAME_INVALID"; break;
658 case SID_NAME_UNKNOWN: return "SID_NAME_UNKNOWN"; break;
660 return "Invalid sid type\n";
663 /* Convert string to sid */
665 static BOOL wbinfo_lookupname(char *name)
667 struct winbindd_request request;
668 struct winbindd_response response;
670 /* Send off request */
672 ZERO_STRUCT(request);
673 ZERO_STRUCT(response);
675 parse_wbinfo_domain_user(name, request.data.name.dom_name,
676 request.data.name.name);
678 if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) !=
682 /* Display response */
684 d_printf("%s %s (%d)\n", response.data.sid.sid, sid_type_lookup(response.data.sid.type), response.data.sid.type);
689 /* Authenticate a user with a plaintext password */
691 static BOOL wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
693 struct winbindd_request request;
694 struct winbindd_response response;
698 /* Send off request */
700 ZERO_STRUCT(request);
701 ZERO_STRUCT(response);
703 p = strchr(username, '%');
707 fstrcpy(request.data.auth.user, username);
708 fstrcpy(request.data.auth.pass, p + 1);
711 fstrcpy(request.data.auth.user, username);
713 request.flags = flags;
715 fstrcpy(request.data.auth.krb5_cc_type, cctype);
717 request.data.auth.uid = geteuid();
719 result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);
721 /* Display response */
723 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
724 username, (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", cctype);
726 if (response.data.auth.nt_status)
727 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
728 response.data.auth.nt_status_string,
729 response.data.auth.nt_status,
730 response.data.auth.error_string);
732 if (result == NSS_STATUS_SUCCESS) {
734 if (request.flags & WBFLAG_PAM_INFO3_TEXT) {
735 if (response.data.auth.info3.user_flgs & NETLOGON_CACHED_ACCOUNT) {
736 d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
740 if (response.data.auth.krb5ccname[0] != '\0') {
741 d_printf("credentials were put in: %s\n", response.data.auth.krb5ccname);
743 d_printf("no credentials cached\n");
747 return result == NSS_STATUS_SUCCESS;
750 /* Authenticate a user with a plaintext password */
752 static BOOL wbinfo_auth(char *username)
754 struct winbindd_request request;
755 struct winbindd_response response;
759 /* Send off request */
761 ZERO_STRUCT(request);
762 ZERO_STRUCT(response);
764 p = strchr(username, '%');
768 fstrcpy(request.data.auth.user, username);
769 fstrcpy(request.data.auth.pass, p + 1);
772 fstrcpy(request.data.auth.user, username);
774 result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);
776 /* Display response */
778 d_printf("plaintext password authentication %s\n",
779 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
781 if (response.data.auth.nt_status)
782 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
783 response.data.auth.nt_status_string,
784 response.data.auth.nt_status,
785 response.data.auth.error_string);
787 return result == NSS_STATUS_SUCCESS;
790 /* Authenticate a user with a challenge/response */
792 static BOOL wbinfo_auth_crap(char *username)
794 struct winbindd_request request;
795 struct winbindd_response response;
802 /* Send off request */
804 ZERO_STRUCT(request);
805 ZERO_STRUCT(response);
807 p = strchr(username, '%');
811 fstrcpy(pass, p + 1);
814 parse_wbinfo_domain_user(username, name_domain, name_user);
816 request.data.auth_crap.logon_parameters = MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT | MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
818 fstrcpy(request.data.auth_crap.user, name_user);
820 fstrcpy(request.data.auth_crap.domain,
823 generate_random_buffer(request.data.auth_crap.chal, 8);
825 if (lp_client_ntlmv2_auth()) {
826 DATA_BLOB server_chal;
827 DATA_BLOB names_blob;
829 DATA_BLOB lm_response;
830 DATA_BLOB nt_response;
833 mem_ctx = talloc_new(NULL);
834 if (mem_ctx == NULL) {
835 d_printf("talloc_new failed\n");
839 server_chal = data_blob(request.data.auth_crap.chal, 8);
841 /* Pretend this is a login to 'us', for blob purposes */
842 names_blob = NTLMv2_generate_names_blob(mem_ctx, lp_netbios_name(), lp_workgroup());
844 if (!SMBNTLMv2encrypt(mem_ctx, name_user, name_domain, pass, &server_chal,
846 &lm_response, &nt_response, NULL, NULL)) {
847 data_blob_free(&names_blob);
848 data_blob_free(&server_chal);
851 data_blob_free(&names_blob);
852 data_blob_free(&server_chal);
854 memcpy(request.data.auth_crap.nt_resp, nt_response.data,
855 MIN(nt_response.length,
856 sizeof(request.data.auth_crap.nt_resp)));
857 request.data.auth_crap.nt_resp_len = nt_response.length;
859 memcpy(request.data.auth_crap.lm_resp, lm_response.data,
860 MIN(lm_response.length,
861 sizeof(request.data.auth_crap.lm_resp)));
862 request.data.auth_crap.lm_resp_len = lm_response.length;
864 data_blob_free(&nt_response);
865 data_blob_free(&lm_response);
868 if (lp_client_lanman_auth()
869 && SMBencrypt(pass, request.data.auth_crap.chal,
870 (unsigned char *)request.data.auth_crap.lm_resp)) {
871 request.data.auth_crap.lm_resp_len = 24;
873 request.data.auth_crap.lm_resp_len = 0;
875 SMBNTencrypt(pass, request.data.auth_crap.chal,
876 (unsigned char *)request.data.auth_crap.nt_resp);
878 request.data.auth_crap.nt_resp_len = 24;
881 result = winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response);
883 /* Display response */
885 d_printf("challenge/response password authentication %s\n",
886 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
888 if (response.data.auth.nt_status)
889 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
890 response.data.auth.nt_status_string,
891 response.data.auth.nt_status,
892 response.data.auth.error_string);
894 return result == NSS_STATUS_SUCCESS;
897 /* Print domain users */
899 static BOOL print_domain_users(const char *domain)
901 struct winbindd_request request;
902 struct winbindd_response response;
903 const char *extra_data;
906 /* Send request to winbind daemon */
908 ZERO_STRUCT(request);
909 ZERO_STRUCT(response);
912 /* '.' is the special sign for our own domain */
913 if ( strequal(domain, ".") )
914 fstrcpy( request.domain_name, get_winbind_domain() );
916 fstrcpy( request.domain_name, domain );
919 if (winbindd_request(WINBINDD_LIST_USERS, &request, &response) !=
923 /* Look through extra data */
925 if (!response.extra_data.data)
928 extra_data = (const char *)response.extra_data.data;
930 while(next_token(&extra_data, name, ",", sizeof(fstring)))
931 d_printf("%s\n", name);
933 SAFE_FREE(response.extra_data.data);
938 /* Print domain groups */
940 static BOOL print_domain_groups(const char *domain)
942 struct winbindd_request request;
943 struct winbindd_response response;
944 const char *extra_data;
947 ZERO_STRUCT(request);
948 ZERO_STRUCT(response);
951 if ( strequal(domain, ".") )
952 fstrcpy( request.domain_name, get_winbind_domain() );
954 fstrcpy( request.domain_name, domain );
957 if (winbindd_request(WINBINDD_LIST_GROUPS, &request, &response) !=
961 /* Look through extra data */
963 if (!response.extra_data.data)
966 extra_data = (const char *)response.extra_data.data;
968 while(next_token(&extra_data, name, ",", sizeof(fstring)))
969 d_printf("%s\n", name);
971 SAFE_FREE(response.extra_data.data);
976 static BOOL wbinfo_ping(void)
980 result = winbindd_request(WINBINDD_PING, NULL, NULL);
982 /* Display response */
984 d_printf("Ping to winbindd %s on fd %d\n",
985 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", winbindd_fd);
987 return result == NSS_STATUS_SUCCESS;
993 OPT_SET_AUTH_USER = 1000,
1003 OPT_LIST_ALL_DOMAINS,
1004 OPT_LIST_OWN_DOMAIN,
1009 int main(int argc, char **argv, char **envp)
1014 static char *string_arg;
1015 static char *opt_domain_name;
1019 struct poptOption long_options[] = {
1022 /* longName, shortName, argInfo, argPtr, value, descrip,
1025 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1026 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1027 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1028 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1029 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1030 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1031 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1032 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1033 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1034 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1035 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1036 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1037 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1038 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1039 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1040 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1041 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1042 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1043 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1044 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1045 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1046 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1047 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1048 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1049 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1050 "Get a DC name for a foreign domain", "domainname" },
1051 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1052 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1054 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1055 /* destroys wbinfo --help output */
1056 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1058 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1066 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
1068 /* Parse command line options */
1071 poptPrintHelp(pc, stderr, 0);
1075 while((opt = poptGetNextOpt(pc)) != -1) {
1076 /* get the generic configuration parameters like --domain */
1079 poptFreeContext(pc);
1081 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1082 POPT_CONTEXT_KEEP_FIRST);
1084 while((opt = poptGetNextOpt(pc)) != -1) {
1087 if (!print_domain_users(opt_domain_name)) {
1088 d_fprintf(stderr, "Error looking up domain users\n");
1093 if (!print_domain_groups(opt_domain_name)) {
1094 d_fprintf(stderr, "Error looking up domain groups\n");
1099 if (!wbinfo_lookupsid(string_arg)) {
1100 d_fprintf(stderr, "Could not lookup sid %s\n", string_arg);
1105 if (!wbinfo_lookupname(string_arg)) {
1106 d_fprintf(stderr, "Could not lookup name %s\n", string_arg);
1111 if (!wbinfo_wins_byname(string_arg)) {
1112 d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg);
1117 if (!wbinfo_wins_byip(string_arg)) {
1118 d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg);
1123 if (!wbinfo_uid_to_sid(int_arg)) {
1124 d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg);
1129 if (!wbinfo_gid_to_sid(int_arg)) {
1130 d_fprintf(stderr, "Could not convert gid %d to sid\n",
1136 if (!wbinfo_sid_to_uid(string_arg)) {
1137 d_fprintf(stderr, "Could not convert sid %s to uid\n",
1143 if (!wbinfo_sid_to_gid(string_arg)) {
1144 d_fprintf(stderr, "Could not convert sid %s to gid\n",
1150 if (!wbinfo_check_secret()) {
1151 d_fprintf(stderr, "Could not check secret\n");
1156 if (!wbinfo_list_domains(False)) {
1157 d_fprintf(stderr, "Could not list trusted domains\n");
1162 if (!wbinfo_show_sequence(opt_domain_name)) {
1163 d_fprintf(stderr, "Could not show sequence numbers\n");
1168 if (!wbinfo_domain_info(string_arg)) {
1169 d_fprintf(stderr, "Could not get domain info\n");
1174 if (!wbinfo_get_userinfo(string_arg)) {
1175 d_fprintf(stderr, "Could not get info for user %s\n",
1181 if ( !wbinfo_get_uidinfo(int_arg)) {
1182 d_fprintf(stderr, "Could not get info for uid "
1187 case OPT_GROUP_INFO:
1188 if ( !wbinfo_get_groupinfo(string_arg)) {
1189 d_fprintf(stderr, "Could not get info for "
1190 "group %s\n", string_arg);
1195 if (!wbinfo_get_usergroups(string_arg)) {
1196 d_fprintf(stderr, "Could not get groups for user %s\n",
1202 if (!wbinfo_get_usersids(string_arg)) {
1203 d_fprintf(stderr, "Could not get group SIDs for user SID %s\n",
1208 case OPT_USERDOMGROUPS:
1209 if (!wbinfo_get_userdomgroups(string_arg)) {
1210 d_fprintf(stderr, "Could not get user's domain groups "
1211 "for user SID %s\n", string_arg);
1216 BOOL got_error = False;
1218 if (!wbinfo_auth(string_arg)) {
1219 d_fprintf(stderr, "Could not authenticate user %s with "
1220 "plaintext password\n", string_arg);
1224 if (!wbinfo_auth_crap(string_arg)) {
1225 d_fprintf(stderr, "Could not authenticate user %s with "
1226 "challenge/response\n", string_arg);
1235 uint32 flags = WBFLAG_PAM_KRB5 |
1236 WBFLAG_PAM_CACHED_LOGIN |
1237 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
1238 WBFLAG_PAM_INFO3_TEXT;
1240 if (!wbinfo_auth_krb5(string_arg, "FILE", flags)) {
1241 d_fprintf(stderr, "Could not authenticate user [%s] with "
1242 "Kerberos (ccache: %s)\n", string_arg, "FILE");
1248 if (!wbinfo_ping()) {
1249 d_fprintf(stderr, "could not ping winbindd!\n");
1254 if (!wbinfo_getdcname(string_arg)) {
1258 case OPT_SEPARATOR: {
1259 const char sep = winbind_separator_int(True);
1263 d_printf("%c\n", sep);
1266 case OPT_LIST_ALL_DOMAINS:
1267 if (!wbinfo_list_domains(True)) {
1271 case OPT_LIST_OWN_DOMAIN:
1272 if (!wbinfo_list_own_domain()) {
1276 /* generic configuration options */
1277 case OPT_DOMAIN_NAME:
1280 d_fprintf(stderr, "Invalid option\n");
1281 poptPrintHelp(pc, stderr, 0);
1291 poptFreeContext(pc);