2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "popt_common.h"
26 #include "winbind_client.h"
27 #include "libwbclient/wbclient.h"
28 #include "lib/popt/popt.h"
29 #include "../libcli/auth/libcli_auth.h"
30 #if (_SAMBA_BUILD_) >= 4
31 #include "lib/cmdline/popt_common.h"
36 #define DBGC_CLASS DBGC_WINBIND
39 static struct wbcInterfaceDetails *init_interface_details(void)
41 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
42 static struct wbcInterfaceDetails *details;
48 wbc_status = wbcInterfaceDetails(&details);
49 if (!WBC_ERROR_IS_OK(wbc_status)) {
50 d_fprintf(stderr, "could not obtain winbind interface "
51 "details: %s\n", wbcErrorString(wbc_status));
57 static char winbind_separator(void)
59 struct wbcInterfaceDetails *details;
66 details = init_interface_details();
69 d_fprintf(stderr, "could not obtain winbind separator!\n");
73 sep = details->winbind_separator;
77 d_fprintf(stderr, "winbind separator was NULL!\n");
84 static const char *get_winbind_domain(void)
86 static struct wbcInterfaceDetails *details;
88 details = init_interface_details();
91 d_fprintf(stderr, "could not obtain winbind domain name!\n");
95 return details->netbios_domain;
98 static const char *get_winbind_netbios_name(void)
100 static struct wbcInterfaceDetails *details;
102 details = init_interface_details();
105 d_fprintf(stderr, "could not obtain winbind netbios name!\n");
109 return details->netbios_name;
112 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
113 form DOMAIN/user into a domain and a user */
115 static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
119 char *p = strchr(domuser,winbind_separator());
122 /* Maybe it was a UPN? */
123 if ((p = strchr(domuser, '@')) != NULL) {
125 fstrcpy(user, domuser);
129 fstrcpy(user, domuser);
130 fstrcpy(domain, get_winbind_domain());
135 fstrcpy(domain, domuser);
136 domain[PTR_DIFF(p, domuser)] = 0;
142 /* pull pwent info for a given user */
144 static bool wbinfo_get_userinfo(char *user)
146 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
147 struct passwd *pwd = NULL;
149 wbc_status = wbcGetpwnam(user, &pwd);
150 if (!WBC_ERROR_IS_OK(wbc_status)) {
151 d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n",
152 wbcErrorString(wbc_status));
156 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
159 (unsigned int)pwd->pw_uid,
160 (unsigned int)pwd->pw_gid,
168 /* pull pwent info for a given uid */
169 static bool wbinfo_get_uidinfo(int uid)
171 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
172 struct passwd *pwd = NULL;
174 wbc_status = wbcGetpwuid(uid, &pwd);
175 if (!WBC_ERROR_IS_OK(wbc_status)) {
176 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
177 wbcErrorString(wbc_status));
181 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
184 (unsigned int)pwd->pw_uid,
185 (unsigned int)pwd->pw_gid,
193 static bool wbinfo_get_user_sidinfo(const char *sid_str)
195 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
196 struct passwd *pwd = NULL;
197 struct wbcDomainSid sid;
199 wbc_status = wbcStringToSid(sid_str, &sid);
200 wbc_status = wbcGetpwsid(&sid, &pwd);
201 if (!WBC_ERROR_IS_OK(wbc_status)) {
202 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
203 wbcErrorString(wbc_status));
207 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
210 (unsigned int)pwd->pw_uid,
211 (unsigned int)pwd->pw_gid,
220 /* pull grent for a given group */
221 static bool wbinfo_get_groupinfo(const char *group)
223 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
227 wbc_status = wbcGetgrnam(group, &grp);
228 if (!WBC_ERROR_IS_OK(wbc_status)) {
229 d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n",
230 wbcErrorString(wbc_status));
234 d_printf("%s:%s:%u:",
237 (unsigned int)grp->gr_gid);
240 while (*mem != NULL) {
241 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
251 /* pull grent for a given gid */
252 static bool wbinfo_get_gidinfo(int gid)
254 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
258 wbc_status = wbcGetgrgid(gid, &grp);
259 if (!WBC_ERROR_IS_OK(wbc_status)) {
260 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
261 wbcErrorString(wbc_status));
265 d_printf("%s:%s:%u:",
268 (unsigned int)grp->gr_gid);
271 while (*mem != NULL) {
272 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
282 /* List groups a user is a member of */
284 static bool wbinfo_get_usergroups(const char *user)
286 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
289 gid_t *groups = NULL;
293 wbc_status = wbcGetGroups(user, &num_groups, &groups);
294 if (!WBC_ERROR_IS_OK(wbc_status)) {
295 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
296 wbcErrorString(wbc_status));
300 for (i = 0; i < num_groups; i++) {
301 d_printf("%d\n", (int)groups[i]);
304 wbcFreeMemory(groups);
310 /* List group SIDs a user SID is a member of */
311 static bool wbinfo_get_usersids(const char *user_sid_str)
313 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
316 struct wbcDomainSid user_sid, *sids = NULL;
320 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
321 if (!WBC_ERROR_IS_OK(wbc_status)) {
322 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
323 wbcErrorString(wbc_status));
327 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
328 if (!WBC_ERROR_IS_OK(wbc_status)) {
329 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
330 wbcErrorString(wbc_status));
334 for (i = 0; i < num_sids; i++) {
336 wbc_status = wbcSidToString(&sids[i], &str);
337 if (!WBC_ERROR_IS_OK(wbc_status)) {
338 d_fprintf(stderr, "failed to call wbcSidToString: "
339 "%s\n", wbcErrorString(wbc_status));
343 d_printf("%s\n", str);
352 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
354 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
357 struct wbcDomainSid user_sid, *sids = NULL;
361 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
362 if (!WBC_ERROR_IS_OK(wbc_status)) {
363 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
364 wbcErrorString(wbc_status));
368 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
369 if (!WBC_ERROR_IS_OK(wbc_status)) {
370 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
371 wbcErrorString(wbc_status));
375 for (i = 0; i < num_sids; i++) {
377 wbc_status = wbcSidToString(&sids[i], &str);
378 if (!WBC_ERROR_IS_OK(wbc_status)) {
379 d_fprintf(stderr, "failed to call wbcSidToString: "
380 "%s\n", wbcErrorString(wbc_status));
384 d_printf("%s\n", str);
393 static bool wbinfo_get_sidaliases(const char *domain,
394 const char *user_sid_str)
396 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
397 struct wbcDomainInfo *dinfo = NULL;
399 struct wbcDomainSid user_sid;
400 uint32_t *alias_rids = NULL;
401 uint32_t num_alias_rids;
402 char *domain_sid_str = NULL;
405 if ((domain == NULL) || (strequal(domain, ".")) ||
406 (domain[0] == '\0')) {
407 domain = get_winbind_domain();
412 wbc_status = wbcDomainInfo(domain, &dinfo);
413 if (!WBC_ERROR_IS_OK(wbc_status)) {
414 d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain,
415 wbcErrorString(wbc_status));
418 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
419 if (!WBC_ERROR_IS_OK(wbc_status)) {
423 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
424 &alias_rids, &num_alias_rids);
425 if (!WBC_ERROR_IS_OK(wbc_status)) {
429 wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
430 if (!WBC_ERROR_IS_OK(wbc_status)) {
434 for (i = 0; i < num_alias_rids; i++) {
435 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
438 wbcFreeMemory(alias_rids);
441 if (domain_sid_str) {
442 wbcFreeMemory(domain_sid_str);
445 wbcFreeMemory(dinfo);
447 return (WBC_ERR_SUCCESS == wbc_status);
451 /* Convert NetBIOS name to IP */
453 static bool wbinfo_wins_byname(const char *name)
455 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
458 wbc_status = wbcResolveWinsByName(name, &ip);
459 if (!WBC_ERROR_IS_OK(wbc_status)) {
460 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
461 wbcErrorString(wbc_status));
465 /* Display response */
467 d_printf("%s\n", ip);
474 /* Convert IP to NetBIOS name */
476 static bool wbinfo_wins_byip(const char *ip)
478 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
481 wbc_status = wbcResolveWinsByIP(ip, &name);
482 if (!WBC_ERROR_IS_OK(wbc_status)) {
483 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
484 wbcErrorString(wbc_status));
488 /* Display response */
490 d_printf("%s\n", name);
497 /* List all/trusted domains */
499 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
501 struct wbcDomainInfo *domain_list = NULL;
503 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
504 bool print_all = !list_all_domains && verbose;
507 wbc_status = wbcListTrusts(&domain_list, &num_domains);
508 if (!WBC_ERROR_IS_OK(wbc_status)) {
509 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
510 wbcErrorString(wbc_status));
515 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
516 "Domain Name", "DNS Domain", "Trust Type",
517 "Transitive", "In", "Out");
520 for (i=0; i<num_domains; i++) {
522 d_printf("%-16s", domain_list[i].short_name);
524 d_printf("%s", domain_list[i].short_name);
529 d_printf("%-24s", domain_list[i].dns_name);
531 switch(domain_list[i].trust_type) {
532 case WBC_DOMINFO_TRUSTTYPE_NONE:
535 case WBC_DOMINFO_TRUSTTYPE_FOREST:
538 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL:
539 d_printf("External ");
541 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST:
542 d_printf("In-Forest ");
546 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_TRANSITIVE) {
552 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_INCOMING) {
558 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_OUTGOING) {
570 /* List own domain */
572 static bool wbinfo_list_own_domain(void)
574 d_printf("%s\n", get_winbind_domain());
579 /* show sequence numbers */
580 static bool wbinfo_show_sequence(const char *domain)
582 d_printf("This command has been deprecated. Please use the "
583 "--online-status option instead.\n");
587 /* show sequence numbers */
588 static bool wbinfo_show_onlinestatus(const char *domain)
590 struct wbcDomainInfo *domain_list = NULL;
592 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
595 wbc_status = wbcListTrusts(&domain_list, &num_domains);
596 if (!WBC_ERROR_IS_OK(wbc_status)) {
597 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
598 wbcErrorString(wbc_status));
602 for (i=0; i<num_domains; i++) {
606 if (!strequal(domain_list[i].short_name, domain)) {
611 is_offline = (domain_list[i].domain_flags &
612 WBC_DOMINFO_DOMAIN_OFFLINE);
614 d_printf("%s : %s\n",
615 domain_list[i].short_name,
616 is_offline ? "offline" : "online" );
623 /* Show domain info */
625 static bool wbinfo_domain_info(const char *domain)
627 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
628 struct wbcDomainInfo *dinfo = NULL;
629 char *sid_str = NULL;
631 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
632 domain = get_winbind_domain();
637 wbc_status = wbcDomainInfo(domain, &dinfo);
638 if (!WBC_ERROR_IS_OK(wbc_status)) {
639 d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n",
640 wbcErrorString(wbc_status));
644 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
645 if (!WBC_ERROR_IS_OK(wbc_status)) {
646 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
647 wbcErrorString(wbc_status));
648 wbcFreeMemory(dinfo);
652 /* Display response */
654 d_printf("Name : %s\n", dinfo->short_name);
655 d_printf("Alt_Name : %s\n", dinfo->dns_name);
657 d_printf("SID : %s\n", sid_str);
659 d_printf("Active Directory : %s\n",
660 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No");
661 d_printf("Native : %s\n",
662 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ?
665 d_printf("Primary : %s\n",
666 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
669 wbcFreeMemory(sid_str);
670 wbcFreeMemory(dinfo);
675 /* Get a foreign DC's name */
676 static bool wbinfo_getdcname(const char *domain_name)
678 struct winbindd_request request;
679 struct winbindd_response response;
681 ZERO_STRUCT(request);
682 ZERO_STRUCT(response);
684 fstrcpy(request.domain_name, domain_name);
688 if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
689 &response) != NSS_STATUS_SUCCESS) {
690 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
694 /* Display response */
696 d_printf("%s\n", response.data.dc_name);
702 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
704 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
705 struct wbcDomainControllerInfoEx *dc_info;
708 wbc_status = wbcLookupDomainControllerEx(domain_name, NULL, NULL,
709 flags | DS_DIRECTORY_SERVICE_REQUIRED,
711 if (!WBC_ERROR_IS_OK(wbc_status)) {
712 printf("Could not find dc for %s\n", domain_name);
716 wbcGuidToString(dc_info->domain_guid, &str);
718 d_printf("%s\n", dc_info->dc_unc);
719 d_printf("%s\n", dc_info->dc_address);
720 d_printf("%d\n", dc_info->dc_address_type);
721 d_printf("%s\n", str);
722 d_printf("%s\n", dc_info->domain_name);
723 d_printf("%s\n", dc_info->forest_name);
724 d_printf("0x%08x\n", dc_info->dc_flags);
725 d_printf("%s\n", dc_info->dc_site_name);
726 d_printf("%s\n", dc_info->client_site_name);
731 /* Check trust account password */
733 static bool wbinfo_check_secret(const char *domain)
735 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
736 struct wbcAuthErrorInfo *error = NULL;
737 const char *domain_name;
740 domain_name = domain;
742 domain_name = get_winbind_domain();
745 wbc_status = wbcCheckTrustCredentials(domain_name, &error);
747 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
749 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
751 if (wbc_status == WBC_ERR_AUTH_ERROR) {
752 d_fprintf(stderr, "error code was %s (0x%x)\n",
753 error->nt_string, error->nt_status);
754 wbcFreeMemory(error);
756 if (!WBC_ERROR_IS_OK(wbc_status)) {
757 d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: "
758 "%s\n", wbcErrorString(wbc_status));
765 /* Find the currently connected DCs */
767 static bool wbinfo_dc_info(const char *domain_name)
769 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
771 const char **dc_names, **dc_ips;
773 wbc_status = wbcDcInfo(domain_name, &num_dcs,
775 if (!WBC_ERROR_IS_OK(wbc_status)) {
776 printf("Could not find dc info %s\n",
777 domain_name ? domain_name : "our domain");
781 for (i=0; i<num_dcs; i++) {
782 printf("%s (%s)\n", dc_names[i], dc_ips[i]);
784 wbcFreeMemory(dc_names);
785 wbcFreeMemory(dc_ips);
790 /* Change trust account password */
792 static bool wbinfo_change_secret(const char *domain)
794 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
795 struct wbcAuthErrorInfo *error = NULL;
796 const char *domain_name;
799 domain_name = domain;
801 domain_name = get_winbind_domain();
804 wbc_status = wbcChangeTrustCredentials(domain_name, &error);
806 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
808 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
810 if (wbc_status == WBC_ERR_AUTH_ERROR) {
811 d_fprintf(stderr, "error code was %s (0x%x)\n",
812 error->nt_string, error->nt_status);
813 wbcFreeMemory(error);
815 if (!WBC_ERROR_IS_OK(wbc_status)) {
816 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
817 "%s\n", wbcErrorString(wbc_status));
824 /* Check DC connection */
826 static bool wbinfo_ping_dc(void)
828 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
829 struct wbcAuthErrorInfo *error = NULL;
831 wbc_status = wbcPingDc(NULL, &error);
833 d_printf("checking the NETLOGON dc connection %s\n",
834 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
836 if (wbc_status == WBC_ERR_AUTH_ERROR) {
837 d_fprintf(stderr, "error code was %s (0x%x)\n",
838 error->nt_string, error->nt_status);
839 wbcFreeMemory(error);
841 if (!WBC_ERROR_IS_OK(wbc_status)) {
842 d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
843 wbcErrorString(wbc_status));
850 /* Convert uid to sid */
852 static bool wbinfo_uid_to_sid(uid_t uid)
854 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
855 struct wbcDomainSid sid;
856 char *sid_str = NULL;
860 wbc_status = wbcUidToSid(uid, &sid);
861 if (!WBC_ERROR_IS_OK(wbc_status)) {
862 d_fprintf(stderr, "failed to call wbcUidToSid: %s\n",
863 wbcErrorString(wbc_status));
867 wbc_status = wbcSidToString(&sid, &sid_str);
868 if (!WBC_ERROR_IS_OK(wbc_status)) {
869 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
870 wbcErrorString(wbc_status));
874 /* Display response */
876 d_printf("%s\n", sid_str);
878 wbcFreeMemory(sid_str);
883 /* Convert gid to sid */
885 static bool wbinfo_gid_to_sid(gid_t gid)
887 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
888 struct wbcDomainSid sid;
889 char *sid_str = NULL;
893 wbc_status = wbcGidToSid(gid, &sid);
894 if (!WBC_ERROR_IS_OK(wbc_status)) {
895 d_fprintf(stderr, "failed to call wbcGidToSid: %s\n",
896 wbcErrorString(wbc_status));
900 wbc_status = wbcSidToString(&sid, &sid_str);
901 if (!WBC_ERROR_IS_OK(wbc_status)) {
902 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
903 wbcErrorString(wbc_status));
907 /* Display response */
909 d_printf("%s\n", sid_str);
911 wbcFreeMemory(sid_str);
916 /* Convert sid to uid */
918 static bool wbinfo_sid_to_uid(const char *sid_str)
920 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
921 struct wbcDomainSid sid;
926 wbc_status = wbcStringToSid(sid_str, &sid);
927 if (!WBC_ERROR_IS_OK(wbc_status)) {
928 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
929 wbcErrorString(wbc_status));
933 wbc_status = wbcSidToUid(&sid, &uid);
934 if (!WBC_ERROR_IS_OK(wbc_status)) {
935 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
936 wbcErrorString(wbc_status));
940 /* Display response */
942 d_printf("%d\n", (int)uid);
947 static bool wbinfo_sid_to_gid(const char *sid_str)
949 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
950 struct wbcDomainSid sid;
955 wbc_status = wbcStringToSid(sid_str, &sid);
956 if (!WBC_ERROR_IS_OK(wbc_status)) {
957 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
958 wbcErrorString(wbc_status));
962 wbc_status = wbcSidToGid(&sid, &gid);
963 if (!WBC_ERROR_IS_OK(wbc_status)) {
964 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
965 wbcErrorString(wbc_status));
969 /* Display response */
971 d_printf("%d\n", (int)gid);
976 static bool wbinfo_allocate_uid(void)
978 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
983 wbc_status = wbcAllocateUid(&uid);
984 if (!WBC_ERROR_IS_OK(wbc_status)) {
985 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
986 wbcErrorString(wbc_status));
990 /* Display response */
992 d_printf("New uid: %u\n", (unsigned int)uid);
997 static bool wbinfo_allocate_gid(void)
999 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1004 wbc_status = wbcAllocateGid(&gid);
1005 if (!WBC_ERROR_IS_OK(wbc_status)) {
1006 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
1007 wbcErrorString(wbc_status));
1011 /* Display response */
1013 d_printf("New gid: %u\n", (unsigned int)gid);
1018 /* Convert sid to string */
1020 static bool wbinfo_lookupsid(const char *sid_str)
1022 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1023 struct wbcDomainSid sid;
1026 enum wbcSidType type;
1028 /* Send off request */
1030 wbc_status = wbcStringToSid(sid_str, &sid);
1031 if (!WBC_ERROR_IS_OK(wbc_status)) {
1032 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1033 wbcErrorString(wbc_status));
1037 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1038 if (!WBC_ERROR_IS_OK(wbc_status)) {
1039 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
1040 wbcErrorString(wbc_status));
1044 /* Display response */
1046 d_printf("%s%c%s %d\n",
1047 domain, winbind_separator(), name, type);
1052 /* Convert sid to fullname */
1054 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1056 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1057 struct wbcDomainSid sid;
1060 enum wbcSidType type;
1062 /* Send off request */
1064 wbc_status = wbcStringToSid(sid_str, &sid);
1065 if (!WBC_ERROR_IS_OK(wbc_status)) {
1066 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1067 wbcErrorString(wbc_status));
1071 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1072 if (!WBC_ERROR_IS_OK(wbc_status)) {
1073 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
1074 wbcErrorString(wbc_status));
1078 /* Display response */
1080 d_printf("%s%c%s %d\n",
1081 domain, winbind_separator(), name, type);
1086 /* Lookup a list of RIDs */
1088 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1090 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1091 struct wbcDomainInfo *dinfo = NULL;
1092 char *domain_name = NULL;
1093 const char **names = NULL;
1094 enum wbcSidType *types = NULL;
1097 uint32_t *rids = NULL;
1100 TALLOC_CTX *mem_ctx = NULL;
1103 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1104 domain = get_winbind_domain();
1109 wbc_status = wbcDomainInfo(domain, &dinfo);
1110 if (!WBC_ERROR_IS_OK(wbc_status)) {
1111 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1112 wbcErrorString(wbc_status));
1116 mem_ctx = talloc_new(NULL);
1117 if (mem_ctx == NULL) {
1118 d_printf("talloc_new failed\n");
1126 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1127 uint32_t rid = strtoul(ridstr, NULL, 10);
1128 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1130 d_printf("talloc_realloc failed\n");
1132 rids[num_rids] = rid;
1137 d_printf("no rids\n");
1141 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
1142 (const char **)&domain_name, &names, &types);
1143 if (!WBC_ERROR_IS_OK(wbc_status)) {
1144 d_printf("winbind_lookup_rids failed: %s\n",
1145 wbcErrorString(wbc_status));
1149 d_printf("Domain: %s\n", domain_name);
1151 for (i=0; i<num_rids; i++) {
1152 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1153 wbcSidTypeString(types[i]));
1159 wbcFreeMemory(dinfo);
1162 wbcFreeMemory(domain_name);
1165 wbcFreeMemory(names);
1168 wbcFreeMemory(types);
1170 TALLOC_FREE(mem_ctx);
1174 /* Convert string to sid */
1176 static bool wbinfo_lookupname(const char *full_name)
1178 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1179 struct wbcDomainSid sid;
1181 enum wbcSidType type;
1182 fstring domain_name;
1183 fstring account_name;
1185 /* Send off request */
1187 parse_wbinfo_domain_user(full_name, domain_name,
1190 wbc_status = wbcLookupName(domain_name, account_name,
1192 if (!WBC_ERROR_IS_OK(wbc_status)) {
1193 d_fprintf(stderr, "failed to call wbcLookupName: %s\n",
1194 wbcErrorString(wbc_status));
1198 wbc_status = wbcSidToString(&sid, &sid_str);
1199 if (!WBC_ERROR_IS_OK(wbc_status)) {
1200 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
1201 wbcErrorString(wbc_status));
1205 /* Display response */
1207 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
1209 wbcFreeMemory(sid_str);
1214 static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
1216 const char *username)
1219 const char *ret = NULL;
1221 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1226 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1231 prompt = talloc_asprintf_append(prompt, "password: ");
1236 ret = getpass(prompt);
1237 TALLOC_FREE(prompt);
1239 return talloc_strdup(mem_ctx, ret);
1242 /* Authenticate a user with a plaintext password */
1244 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1246 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1249 char *password = NULL;
1251 char *local_cctype = NULL;
1253 struct wbcLogonUserParams params;
1254 struct wbcLogonUserInfo *info;
1255 struct wbcAuthErrorInfo *error;
1256 struct wbcUserPasswordPolicyInfo *policy;
1257 TALLOC_CTX *frame = talloc_tos();
1259 if ((s = talloc_strdup(frame, username)) == NULL) {
1263 if ((p = strchr(s, '%')) != NULL) {
1266 password = talloc_strdup(frame, p);
1268 password = wbinfo_prompt_pass(frame, NULL, username);
1271 local_cctype = talloc_strdup(frame, cctype);
1277 params.username = name;
1278 params.password = password;
1279 params.num_blobs = 0;
1280 params.blobs = NULL;
1282 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1288 if (!WBC_ERROR_IS_OK(wbc_status)) {
1289 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1290 wbcErrorString(wbc_status));
1294 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1300 if (!WBC_ERROR_IS_OK(wbc_status)) {
1301 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1302 wbcErrorString(wbc_status));
1306 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1310 (uint8_t *)local_cctype,
1312 if (!WBC_ERROR_IS_OK(wbc_status)) {
1313 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1314 wbcErrorString(wbc_status));
1318 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1320 d_printf("plaintext kerberos password authentication for [%s] %s "
1321 "(requesting cctype: %s)\n",
1322 username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1327 "error code was %s (0x%x)\nerror message was: %s\n",
1330 error->display_string);
1333 if (WBC_ERROR_IS_OK(wbc_status)) {
1334 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1335 if (info && info->info && info->info->user_flags &
1336 NETLOGON_CACHED_ACCOUNT) {
1337 d_printf("user_flgs: "
1338 "NETLOGON_CACHED_ACCOUNT\n");
1344 for (i=0; i < info->num_blobs; i++) {
1345 if (strequal(info->blobs[i].name,
1347 d_printf("credentials were put "
1350 info->blobs[i].blob.data);
1355 d_printf("no credentials cached\n");
1360 wbcFreeMemory(params.blobs);
1362 return WBC_ERROR_IS_OK(wbc_status);
1365 /* Authenticate a user with a plaintext password */
1367 static bool wbinfo_auth(char *username)
1369 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1372 char *password = NULL;
1374 TALLOC_CTX *frame = talloc_tos();
1376 if ((s = talloc_strdup(frame, username)) == NULL) {
1380 if ((p = strchr(s, '%')) != NULL) {
1383 password = talloc_strdup(frame, p);
1385 password = wbinfo_prompt_pass(frame, NULL, username);
1390 wbc_status = wbcAuthenticateUser(name, password);
1392 d_printf("plaintext password authentication %s\n",
1393 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1396 if (response.data.auth.nt_status)
1398 "error code was %s (0x%x)\nerror message was: %s\n",
1399 response.data.auth.nt_status_string,
1400 response.data.auth.nt_status,
1401 response.data.auth.error_string);
1404 return WBC_ERROR_IS_OK(wbc_status);
1407 /* Authenticate a user with a challenge/response */
1409 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1411 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1412 struct wbcAuthUserParams params;
1413 struct wbcAuthUserInfo *info = NULL;
1414 struct wbcAuthErrorInfo *err = NULL;
1415 DATA_BLOB lm = data_blob_null;
1416 DATA_BLOB nt = data_blob_null;
1418 fstring name_domain;
1421 TALLOC_CTX *frame = talloc_tos();
1423 p = strchr(username, '%');
1427 pass = talloc_strdup(frame, p + 1);
1429 pass = wbinfo_prompt_pass(frame, NULL, username);
1432 parse_wbinfo_domain_user(username, name_domain, name_user);
1434 params.account_name = name_user;
1435 params.domain_name = name_domain;
1436 params.workstation_name = NULL;
1439 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1440 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1442 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1444 generate_random_buffer(params.password.response.challenge, 8);
1447 DATA_BLOB server_chal;
1448 DATA_BLOB names_blob;
1450 server_chal = data_blob(params.password.response.challenge, 8);
1452 /* Pretend this is a login to 'us', for blob purposes */
1453 names_blob = NTLMv2_generate_names_blob(NULL,
1454 get_winbind_netbios_name(),
1455 get_winbind_domain());
1457 if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1460 &lm, &nt, NULL, NULL)) {
1461 data_blob_free(&names_blob);
1462 data_blob_free(&server_chal);
1466 data_blob_free(&names_blob);
1467 data_blob_free(&server_chal);
1472 lm = data_blob(NULL, 24);
1473 ok = SMBencrypt(pass,
1474 params.password.response.challenge,
1477 data_blob_free(&lm);
1480 nt = data_blob(NULL, 24);
1481 SMBNTencrypt(pass, params.password.response.challenge,
1485 params.password.response.nt_length = nt.length;
1486 params.password.response.nt_data = nt.data;
1487 params.password.response.lm_length = lm.length;
1488 params.password.response.lm_data = lm.data;
1490 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1492 /* Display response */
1494 d_printf("challenge/response password authentication %s\n",
1495 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1497 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1499 "error code was %s (0x%x)\nerror message was: %s\n",
1502 err->display_string);
1504 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1505 wbcFreeMemory(info);
1508 data_blob_free(&nt);
1509 data_blob_free(&lm);
1511 return WBC_ERROR_IS_OK(wbc_status);
1514 /* Authenticate a user with a plaintext password */
1516 static bool wbinfo_pam_logon(char *username)
1518 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1519 struct wbcLogonUserParams params;
1520 struct wbcAuthErrorInfo *error;
1523 TALLOC_CTX *frame = talloc_tos();
1527 ZERO_STRUCT(params);
1529 if ((s = talloc_strdup(frame, username)) == NULL) {
1533 if ((p = strchr(s, '%')) != NULL) {
1536 params.password = talloc_strdup(frame, p);
1538 params.password = wbinfo_prompt_pass(frame, NULL, username);
1540 params.username = s;
1542 flags = WBFLAG_PAM_CACHED_LOGIN;
1544 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1546 (uint8_t *)&flags, sizeof(flags));
1547 if (!WBC_ERROR_IS_OK(wbc_status)) {
1548 d_printf("wbcAddNamedBlob failed: %s\n",
1549 wbcErrorString(wbc_status));
1555 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1557 (uint8_t *)&uid, sizeof(uid));
1558 if (!WBC_ERROR_IS_OK(wbc_status)) {
1559 d_printf("wbcAddNamedBlob failed: %s\n",
1560 wbcErrorString(wbc_status));
1564 wbc_status = wbcLogonUser(¶ms, NULL, &error, NULL);
1566 wbcFreeMemory(params.blobs);
1568 d_printf("plaintext password authentication %s\n",
1569 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1571 if (!WBC_ERROR_IS_OK(wbc_status)) {
1573 "error code was %s (0x%x)\nerror message was: %s\n",
1575 (int)error->nt_status,
1576 error->display_string);
1577 wbcFreeMemory(error);
1583 /* Save creds with winbind */
1585 static bool wbinfo_ccache_save(char *username)
1587 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1590 char *password = NULL;
1592 TALLOC_CTX *frame = talloc_stackframe();
1594 s = talloc_strdup(frame, username);
1603 password = talloc_strdup(frame, p);
1605 password = wbinfo_prompt_pass(frame, NULL, username);
1610 wbc_status = wbcCredentialSave(name, password);
1612 d_printf("saving creds %s\n",
1613 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1617 return WBC_ERROR_IS_OK(wbc_status);
1620 #ifdef WITH_FAKE_KASERVER
1621 /* Authenticate a user with a plaintext password and set a token */
1623 static bool wbinfo_klog(char *username)
1625 struct winbindd_request request;
1626 struct winbindd_response response;
1630 /* Send off request */
1632 ZERO_STRUCT(request);
1633 ZERO_STRUCT(response);
1635 p = strchr(username, '%');
1639 fstrcpy(request.data.auth.user, username);
1640 fstrcpy(request.data.auth.pass, p + 1);
1643 fstrcpy(request.data.auth.user, username);
1644 fstrcpy(request.data.auth.pass, getpass("Password: "));
1647 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1649 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
1652 /* Display response */
1654 d_printf("plaintext password authentication %s\n",
1655 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1657 if (response.data.auth.nt_status)
1659 "error code was %s (0x%x)\nerror message was: %s\n",
1660 response.data.auth.nt_status_string,
1661 response.data.auth.nt_status,
1662 response.data.auth.error_string);
1664 if (result != NSS_STATUS_SUCCESS)
1667 if (response.extra_data.data == NULL) {
1668 d_fprintf(stderr, "Did not get token data\n");
1672 if (!afs_settoken_str((char *)response.extra_data.data)) {
1673 d_fprintf(stderr, "Could not set token\n");
1677 d_printf("Successfully created AFS token\n");
1681 static bool wbinfo_klog(char *username)
1683 d_fprintf(stderr, "No AFS support compiled in.\n");
1688 /* Print domain users */
1690 static bool print_domain_users(const char *domain)
1692 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1694 uint32_t num_users = 0;
1695 const char **users = NULL;
1697 /* Send request to winbind daemon */
1699 /* '.' is the special sign for our own domain */
1700 if (domain && strcmp(domain, ".") == 0) {
1701 domain = get_winbind_domain();
1704 wbc_status = wbcListUsers(domain, &num_users, &users);
1705 if (!WBC_ERROR_IS_OK(wbc_status)) {
1709 for (i=0; i < num_users; i++) {
1710 d_printf("%s\n", users[i]);
1713 wbcFreeMemory(users);
1718 /* Print domain groups */
1720 static bool print_domain_groups(const char *domain)
1722 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1724 uint32_t num_groups = 0;
1725 const char **groups = NULL;
1727 /* Send request to winbind daemon */
1729 /* '.' is the special sign for our own domain */
1730 if (domain && strcmp(domain, ".") == 0) {
1731 domain = get_winbind_domain();
1734 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1735 if (!WBC_ERROR_IS_OK(wbc_status)) {
1736 d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
1737 wbcErrorString(wbc_status));
1741 for (i=0; i < num_groups; i++) {
1742 d_printf("%s\n", groups[i]);
1745 wbcFreeMemory(groups);
1750 /* Set the authorised user for winbindd access in secrets.tdb */
1752 static bool wbinfo_set_auth_user(char *username)
1754 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1755 "See 'net help setauthuser' for details.\n");
1759 static void wbinfo_get_auth_user(void)
1761 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1762 "See 'net help getauthuser' for details.\n");
1765 static bool wbinfo_ping(void)
1769 wbc_status = wbcPing();
1771 /* Display response */
1773 d_printf("Ping to winbindd %s\n",
1774 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1776 return WBC_ERROR_IS_OK(wbc_status);
1779 static bool wbinfo_change_user_password(const char *username)
1782 char *old_password = NULL;
1783 char *new_password = NULL;
1784 TALLOC_CTX *frame = talloc_tos();
1786 old_password = wbinfo_prompt_pass(frame, "old", username);
1787 new_password = wbinfo_prompt_pass(frame, "new", username);
1789 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
1791 /* Display response */
1793 d_printf("Password change for user %s %s\n", username,
1794 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1796 return WBC_ERROR_IS_OK(wbc_status);
1802 OPT_SET_AUTH_USER = 1000,
1815 OPT_LIST_ALL_DOMAINS,
1816 OPT_LIST_OWN_DOMAIN,
1823 OPT_CHANGE_USER_PASSWORD,
1825 OPT_SID_TO_FULLNAME,
1834 int main(int argc, char **argv, char **envp)
1837 TALLOC_CTX *frame = talloc_stackframe();
1839 static char *string_arg;
1840 static char *opt_domain_name;
1843 bool verbose = false;
1844 bool use_ntlmv2 = false;
1845 bool use_lanman = false;
1846 char *logoff_user = getenv("USER");
1847 int logoff_uid = geteuid();
1849 struct poptOption long_options[] = {
1852 /* longName, shortName, argInfo, argPtr, value, descrip,
1855 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1856 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1857 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1858 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1859 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1860 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1861 { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
1862 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
1863 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1864 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1865 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1866 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1867 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1868 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1869 "Get a new UID out of idmap" },
1870 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1871 "Get a new GID out of idmap" },
1872 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1873 { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
1874 { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P',
1875 "Check the NETLOGON connection" },
1876 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1877 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1878 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1879 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Deprecated command, see --online-status" },
1880 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
1881 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1882 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1883 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1884 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1885 { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" },
1886 { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" },
1887 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1888 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1889 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1890 { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" },
1891 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1892 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1893 { "pam-logon", 0, POPT_ARG_STRING, &string_arg, OPT_PAM_LOGON,
1894 "do a pam logon equivalent", "user%password" },
1895 { "logoff", 0, POPT_ARG_NONE, NULL, OPT_LOGOFF,
1896 "log off user", "uid" },
1897 { "logoff-user", 0, POPT_ARG_STRING, &logoff_user,
1898 OPT_LOGOFF_USER, "username to log off" },
1899 { "logoff-uid", 0, POPT_ARG_INT, &logoff_uid,
1900 OPT_LOGOFF_UID, "uid to log off" },
1901 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1902 { "ccache-save", 0, POPT_ARG_STRING, &string_arg,
1903 OPT_CCACHE_SAVE, "Store user and password for ccache "
1904 "operation", "user%password" },
1905 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1906 "Get a DC name for a foreign domain", "domainname" },
1907 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1908 { "dc-info", 0, POPT_ARG_STRING, &string_arg, OPT_DC_INFO,
1909 "Find the currently known DCs", "domainname" },
1910 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1911 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1912 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1913 #ifdef WITH_FAKE_KASERVER
1914 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1917 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1918 /* destroys wbinfo --help output */
1919 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1921 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1922 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1923 { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
1924 { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
1925 { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
1930 /* Samba client initialisation */
1936 pc = poptGetContext("wbinfo", argc, (const char **)argv,
1939 /* Parse command line options */
1942 poptPrintHelp(pc, stderr, 0);
1946 while((opt = poptGetNextOpt(pc)) != -1) {
1947 /* get the generic configuration parameters like --domain */
1961 poptFreeContext(pc);
1963 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1964 POPT_CONTEXT_KEEP_FIRST);
1966 while((opt = poptGetNextOpt(pc)) != -1) {
1969 if (!print_domain_users(opt_domain_name)) {
1971 "Error looking up domain users\n");
1976 if (!print_domain_groups(opt_domain_name)) {
1978 "Error looking up domain groups\n");
1983 if (!wbinfo_lookupsid(string_arg)) {
1985 "Could not lookup sid %s\n",
1990 case OPT_SID_TO_FULLNAME:
1991 if (!wbinfo_lookupsid_fullname(string_arg)) {
1992 d_fprintf(stderr, "Could not lookup sid %s\n",
1998 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
1999 d_fprintf(stderr, "Could not lookup RIDs %s\n",
2005 if (!wbinfo_lookupname(string_arg)) {
2006 d_fprintf(stderr, "Could not lookup name %s\n",
2012 if (!wbinfo_wins_byname(string_arg)) {
2014 "Could not lookup WINS by name %s\n",
2020 if (!wbinfo_wins_byip(string_arg)) {
2022 "Could not lookup WINS by IP %s\n",
2028 if (!wbinfo_uid_to_sid(int_arg)) {
2030 "Could not convert uid %d to sid\n",
2036 if (!wbinfo_gid_to_sid(int_arg)) {
2038 "Could not convert gid %d to sid\n",
2044 if (!wbinfo_sid_to_uid(string_arg)) {
2046 "Could not convert sid %s to uid\n",
2052 if (!wbinfo_sid_to_gid(string_arg)) {
2054 "Could not convert sid %s to gid\n",
2059 case OPT_ALLOCATE_UID:
2060 if (!wbinfo_allocate_uid()) {
2061 d_fprintf(stderr, "Could not allocate a uid\n");
2065 case OPT_ALLOCATE_GID:
2066 if (!wbinfo_allocate_gid()) {
2067 d_fprintf(stderr, "Could not allocate a gid\n");
2072 if (!wbinfo_check_secret(opt_domain_name)) {
2073 d_fprintf(stderr, "Could not check secret\n");
2078 if (!wbinfo_change_secret(opt_domain_name)) {
2079 d_fprintf(stderr, "Could not change secret\n");
2084 if (!wbinfo_ping_dc()) {
2085 d_fprintf(stderr, "Could not ping our DC\n");
2090 if (!wbinfo_list_domains(false, verbose)) {
2092 "Could not list trusted domains\n");
2097 if (!wbinfo_show_sequence(opt_domain_name)) {
2099 "Could not show sequence numbers\n");
2103 case OPT_ONLINESTATUS:
2104 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
2106 "Could not show online-status\n");
2111 if (!wbinfo_domain_info(string_arg)) {
2113 "Could not get domain info\n");
2118 if (!wbinfo_get_userinfo(string_arg)) {
2120 "Could not get info for user %s\n",
2125 case OPT_USER_SIDINFO:
2126 if ( !wbinfo_get_user_sidinfo(string_arg)) {
2128 "Could not get info for user "
2129 "sid %s\n", string_arg);
2134 if ( !wbinfo_get_uidinfo(int_arg)) {
2135 d_fprintf(stderr, "Could not get info for uid "
2140 case OPT_GROUP_INFO:
2141 if ( !wbinfo_get_groupinfo(string_arg)) {
2142 d_fprintf(stderr, "Could not get info for "
2143 "group %s\n", string_arg);
2148 if ( !wbinfo_get_gidinfo(int_arg)) {
2149 d_fprintf(stderr, "Could not get info for gid "
2155 if (!wbinfo_get_usergroups(string_arg)) {
2157 "Could not get groups for user %s\n",
2163 if (!wbinfo_get_usersids(string_arg)) {
2164 d_fprintf(stderr, "Could not get group SIDs "
2165 "for user SID %s\n",
2170 case OPT_USERDOMGROUPS:
2171 if (!wbinfo_get_userdomgroups(string_arg)) {
2172 d_fprintf(stderr, "Could not get user's domain "
2173 "groups for user SID %s\n",
2178 case OPT_SIDALIASES:
2179 if (!wbinfo_get_sidaliases(opt_domain_name,
2181 d_fprintf(stderr, "Could not get sid aliases "
2182 "for user SID %s\n", string_arg);
2187 bool got_error = false;
2189 if (!wbinfo_auth(string_arg)) {
2191 "Could not authenticate user "
2192 "%s with plaintext "
2193 "password\n", string_arg);
2197 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
2200 "Could not authenticate user "
2201 "%s with challenge/response\n",
2211 if (!wbinfo_pam_logon(string_arg)) {
2212 d_fprintf(stderr, "pam_logon failed for %s\n",
2221 wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
2223 d_printf("Logoff %s (%d): %s\n", logoff_user,
2224 logoff_uid, wbcErrorString(wbc_status));
2228 uint32_t flags = WBFLAG_PAM_KRB5 |
2229 WBFLAG_PAM_CACHED_LOGIN |
2230 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
2231 WBFLAG_PAM_INFO3_TEXT |
2232 WBFLAG_PAM_CONTACT_TRUSTDOM;
2234 if (!wbinfo_auth_krb5(string_arg, "FILE",
2237 "Could not authenticate user "
2238 "[%s] with Kerberos "
2239 "(ccache: %s)\n", string_arg,
2246 if (!wbinfo_klog(string_arg)) {
2247 d_fprintf(stderr, "Could not klog user\n");
2252 if (!wbinfo_ping()) {
2253 d_fprintf(stderr, "could not ping winbindd!\n");
2257 case OPT_SET_AUTH_USER:
2258 if (!wbinfo_set_auth_user(string_arg)) {
2262 case OPT_GET_AUTH_USER:
2263 wbinfo_get_auth_user();
2266 case OPT_CCACHE_SAVE:
2267 if (!wbinfo_ccache_save(string_arg)) {
2272 if (!wbinfo_getdcname(string_arg)) {
2276 case OPT_DSGETDCNAME:
2277 if (!wbinfo_dsgetdcname(string_arg, 0)) {
2282 if (!wbinfo_dc_info(string_arg)) {
2286 case OPT_SEPARATOR: {
2287 const char sep = winbind_separator();
2291 d_printf("%c\n", sep);
2294 case OPT_LIST_ALL_DOMAINS:
2295 if (!wbinfo_list_domains(true, verbose)) {
2299 case OPT_LIST_OWN_DOMAIN:
2300 if (!wbinfo_list_own_domain()) {
2304 case OPT_CHANGE_USER_PASSWORD:
2305 if (!wbinfo_change_user_password(string_arg)) {
2307 "Could not change user password "
2308 "for user %s\n", string_arg);
2313 /* generic configuration options */
2314 case OPT_DOMAIN_NAME:
2318 case OPT_LOGOFF_USER:
2319 case OPT_LOGOFF_UID:
2322 d_fprintf(stderr, "Invalid option\n");
2323 poptPrintHelp(pc, stderr, 0);
2335 poptFreeContext(pc);