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 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
143 * Return true if input was valid, false otherwise. */
144 static bool parse_mapping_arg(char *arg, int *id, char **sid)
151 tmp = strtok(arg, ",");
152 *sid = strtok(NULL, ",");
154 if (!tmp || !*tmp || !*sid || !**sid)
157 /* Because atoi() can return 0 on invalid input, which would be a valid
158 * UID/GID we must use strtoul() and do error checking */
159 *id = strtoul(tmp, &endptr, 10);
161 if (endptr[0] != '\0')
167 /* pull pwent info for a given user */
169 static bool wbinfo_get_userinfo(char *user)
171 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
172 struct passwd *pwd = NULL;
174 wbc_status = wbcGetpwnam(user, &pwd);
175 if (!WBC_ERROR_IS_OK(wbc_status)) {
176 d_fprintf(stderr, "failed to call wbcGetpwnam: %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 /* pull pwent info for a given uid */
194 static bool wbinfo_get_uidinfo(int uid)
196 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
197 struct passwd *pwd = NULL;
199 wbc_status = wbcGetpwuid(uid, &pwd);
200 if (!WBC_ERROR_IS_OK(wbc_status)) {
201 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
202 wbcErrorString(wbc_status));
206 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
209 (unsigned int)pwd->pw_uid,
210 (unsigned int)pwd->pw_gid,
218 static bool wbinfo_get_user_sidinfo(const char *sid_str)
220 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
221 struct passwd *pwd = NULL;
222 struct wbcDomainSid sid;
224 wbc_status = wbcStringToSid(sid_str, &sid);
225 wbc_status = wbcGetpwsid(&sid, &pwd);
226 if (!WBC_ERROR_IS_OK(wbc_status)) {
227 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
228 wbcErrorString(wbc_status));
232 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
235 (unsigned int)pwd->pw_uid,
236 (unsigned int)pwd->pw_gid,
245 /* pull grent for a given group */
246 static bool wbinfo_get_groupinfo(const char *group)
248 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
252 wbc_status = wbcGetgrnam(group, &grp);
253 if (!WBC_ERROR_IS_OK(wbc_status)) {
254 d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n",
255 wbcErrorString(wbc_status));
259 d_printf("%s:%s:%u:",
262 (unsigned int)grp->gr_gid);
265 while (*mem != NULL) {
266 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
276 /* pull grent for a given gid */
277 static bool wbinfo_get_gidinfo(int gid)
279 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
283 wbc_status = wbcGetgrgid(gid, &grp);
284 if (!WBC_ERROR_IS_OK(wbc_status)) {
285 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
286 wbcErrorString(wbc_status));
290 d_printf("%s:%s:%u:",
293 (unsigned int)grp->gr_gid);
296 while (*mem != NULL) {
297 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
307 /* List groups a user is a member of */
309 static bool wbinfo_get_usergroups(const char *user)
311 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
314 gid_t *groups = NULL;
318 wbc_status = wbcGetGroups(user, &num_groups, &groups);
319 if (!WBC_ERROR_IS_OK(wbc_status)) {
320 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
321 wbcErrorString(wbc_status));
325 for (i = 0; i < num_groups; i++) {
326 d_printf("%d\n", (int)groups[i]);
329 wbcFreeMemory(groups);
335 /* List group SIDs a user SID is a member of */
336 static bool wbinfo_get_usersids(const char *user_sid_str)
338 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
341 struct wbcDomainSid user_sid, *sids = NULL;
345 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
346 if (!WBC_ERROR_IS_OK(wbc_status)) {
347 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
348 wbcErrorString(wbc_status));
352 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
353 if (!WBC_ERROR_IS_OK(wbc_status)) {
354 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
355 wbcErrorString(wbc_status));
359 for (i = 0; i < num_sids; i++) {
361 wbc_status = wbcSidToString(&sids[i], &str);
362 if (!WBC_ERROR_IS_OK(wbc_status)) {
363 d_fprintf(stderr, "failed to call wbcSidToString: "
364 "%s\n", wbcErrorString(wbc_status));
368 d_printf("%s\n", str);
377 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
379 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
382 struct wbcDomainSid user_sid, *sids = NULL;
386 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
387 if (!WBC_ERROR_IS_OK(wbc_status)) {
388 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
389 wbcErrorString(wbc_status));
393 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
394 if (!WBC_ERROR_IS_OK(wbc_status)) {
395 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
396 wbcErrorString(wbc_status));
400 for (i = 0; i < num_sids; i++) {
402 wbc_status = wbcSidToString(&sids[i], &str);
403 if (!WBC_ERROR_IS_OK(wbc_status)) {
404 d_fprintf(stderr, "failed to call wbcSidToString: "
405 "%s\n", wbcErrorString(wbc_status));
409 d_printf("%s\n", str);
418 static bool wbinfo_get_sidaliases(const char *domain,
419 const char *user_sid_str)
421 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
422 struct wbcDomainInfo *dinfo = NULL;
424 struct wbcDomainSid user_sid;
425 uint32_t *alias_rids = NULL;
426 uint32_t num_alias_rids;
427 char *domain_sid_str = NULL;
430 if ((domain == NULL) || (strequal(domain, ".")) ||
431 (domain[0] == '\0')) {
432 domain = get_winbind_domain();
437 wbc_status = wbcDomainInfo(domain, &dinfo);
438 if (!WBC_ERROR_IS_OK(wbc_status)) {
439 d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain,
440 wbcErrorString(wbc_status));
443 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
444 if (!WBC_ERROR_IS_OK(wbc_status)) {
448 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
449 &alias_rids, &num_alias_rids);
450 if (!WBC_ERROR_IS_OK(wbc_status)) {
454 wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
455 if (!WBC_ERROR_IS_OK(wbc_status)) {
459 for (i = 0; i < num_alias_rids; i++) {
460 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
463 wbcFreeMemory(alias_rids);
466 if (domain_sid_str) {
467 wbcFreeMemory(domain_sid_str);
470 wbcFreeMemory(dinfo);
472 return (WBC_ERR_SUCCESS == wbc_status);
476 /* Convert NetBIOS name to IP */
478 static bool wbinfo_wins_byname(const char *name)
480 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
483 wbc_status = wbcResolveWinsByName(name, &ip);
484 if (!WBC_ERROR_IS_OK(wbc_status)) {
485 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
486 wbcErrorString(wbc_status));
490 /* Display response */
492 d_printf("%s\n", ip);
499 /* Convert IP to NetBIOS name */
501 static bool wbinfo_wins_byip(const char *ip)
503 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
506 wbc_status = wbcResolveWinsByIP(ip, &name);
507 if (!WBC_ERROR_IS_OK(wbc_status)) {
508 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
509 wbcErrorString(wbc_status));
513 /* Display response */
515 d_printf("%s\n", name);
522 /* List all/trusted domains */
524 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
526 struct wbcDomainInfo *domain_list = NULL;
528 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
529 bool print_all = !list_all_domains && verbose;
532 wbc_status = wbcListTrusts(&domain_list, &num_domains);
533 if (!WBC_ERROR_IS_OK(wbc_status)) {
534 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
535 wbcErrorString(wbc_status));
540 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
541 "Domain Name", "DNS Domain", "Trust Type",
542 "Transitive", "In", "Out");
545 for (i=0; i<num_domains; i++) {
547 d_printf("%-16s", domain_list[i].short_name);
549 d_printf("%s", domain_list[i].short_name);
554 d_printf("%-24s", domain_list[i].dns_name);
556 switch(domain_list[i].trust_type) {
557 case WBC_DOMINFO_TRUSTTYPE_NONE:
560 case WBC_DOMINFO_TRUSTTYPE_FOREST:
563 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL:
564 d_printf("External ");
566 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST:
567 d_printf("In-Forest ");
571 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_TRANSITIVE) {
577 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_INCOMING) {
583 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_OUTGOING) {
595 /* List own domain */
597 static bool wbinfo_list_own_domain(void)
599 d_printf("%s\n", get_winbind_domain());
604 /* show sequence numbers */
605 static bool wbinfo_show_sequence(const char *domain)
607 d_printf("This command has been deprecated. Please use the "
608 "--online-status option instead.\n");
612 /* show sequence numbers */
613 static bool wbinfo_show_onlinestatus(const char *domain)
615 struct wbcDomainInfo *domain_list = NULL;
617 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
620 wbc_status = wbcListTrusts(&domain_list, &num_domains);
621 if (!WBC_ERROR_IS_OK(wbc_status)) {
622 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
623 wbcErrorString(wbc_status));
627 for (i=0; i<num_domains; i++) {
631 if (!strequal(domain_list[i].short_name, domain)) {
636 is_offline = (domain_list[i].domain_flags &
637 WBC_DOMINFO_DOMAIN_OFFLINE);
639 d_printf("%s : %s\n",
640 domain_list[i].short_name,
641 is_offline ? "offline" : "online" );
648 /* Show domain info */
650 static bool wbinfo_domain_info(const char *domain)
652 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
653 struct wbcDomainInfo *dinfo = NULL;
654 char *sid_str = NULL;
656 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
657 domain = get_winbind_domain();
662 wbc_status = wbcDomainInfo(domain, &dinfo);
663 if (!WBC_ERROR_IS_OK(wbc_status)) {
664 d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n",
665 wbcErrorString(wbc_status));
669 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
670 if (!WBC_ERROR_IS_OK(wbc_status)) {
671 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
672 wbcErrorString(wbc_status));
673 wbcFreeMemory(dinfo);
677 /* Display response */
679 d_printf("Name : %s\n", dinfo->short_name);
680 d_printf("Alt_Name : %s\n", dinfo->dns_name);
682 d_printf("SID : %s\n", sid_str);
684 d_printf("Active Directory : %s\n",
685 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No");
686 d_printf("Native : %s\n",
687 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ?
690 d_printf("Primary : %s\n",
691 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
694 wbcFreeMemory(sid_str);
695 wbcFreeMemory(dinfo);
700 /* Get a foreign DC's name */
701 static bool wbinfo_getdcname(const char *domain_name)
703 struct winbindd_request request;
704 struct winbindd_response response;
706 ZERO_STRUCT(request);
707 ZERO_STRUCT(response);
709 fstrcpy(request.domain_name, domain_name);
713 if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
714 &response) != NSS_STATUS_SUCCESS) {
715 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
719 /* Display response */
721 d_printf("%s\n", response.data.dc_name);
727 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
729 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
730 struct wbcDomainControllerInfoEx *dc_info;
733 wbc_status = wbcLookupDomainControllerEx(domain_name, NULL, NULL,
734 flags | DS_DIRECTORY_SERVICE_REQUIRED,
736 if (!WBC_ERROR_IS_OK(wbc_status)) {
737 printf("Could not find dc for %s\n", domain_name);
741 wbcGuidToString(dc_info->domain_guid, &str);
743 d_printf("%s\n", dc_info->dc_unc);
744 d_printf("%s\n", dc_info->dc_address);
745 d_printf("%d\n", dc_info->dc_address_type);
746 d_printf("%s\n", str);
747 d_printf("%s\n", dc_info->domain_name);
748 d_printf("%s\n", dc_info->forest_name);
749 d_printf("0x%08x\n", dc_info->dc_flags);
750 d_printf("%s\n", dc_info->dc_site_name);
751 d_printf("%s\n", dc_info->client_site_name);
756 /* Check trust account password */
758 static bool wbinfo_check_secret(const char *domain)
760 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
761 struct wbcAuthErrorInfo *error = NULL;
762 const char *domain_name;
765 domain_name = domain;
767 domain_name = get_winbind_domain();
770 wbc_status = wbcCheckTrustCredentials(domain_name, &error);
772 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
774 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
776 if (wbc_status == WBC_ERR_AUTH_ERROR) {
777 d_fprintf(stderr, "error code was %s (0x%x)\n",
778 error->nt_string, error->nt_status);
779 wbcFreeMemory(error);
781 if (!WBC_ERROR_IS_OK(wbc_status)) {
782 d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: "
783 "%s\n", wbcErrorString(wbc_status));
790 /* Find the currently connected DCs */
792 static bool wbinfo_dc_info(const char *domain_name)
794 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
796 const char **dc_names, **dc_ips;
798 wbc_status = wbcDcInfo(domain_name, &num_dcs,
800 if (!WBC_ERROR_IS_OK(wbc_status)) {
801 printf("Could not find dc info %s\n",
802 domain_name ? domain_name : "our domain");
806 for (i=0; i<num_dcs; i++) {
807 printf("%s (%s)\n", dc_names[i], dc_ips[i]);
809 wbcFreeMemory(dc_names);
810 wbcFreeMemory(dc_ips);
815 /* Change trust account password */
817 static bool wbinfo_change_secret(const char *domain)
819 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
820 struct wbcAuthErrorInfo *error = NULL;
821 const char *domain_name;
824 domain_name = domain;
826 domain_name = get_winbind_domain();
829 wbc_status = wbcChangeTrustCredentials(domain_name, &error);
831 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
833 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
835 if (wbc_status == WBC_ERR_AUTH_ERROR) {
836 d_fprintf(stderr, "error code was %s (0x%x)\n",
837 error->nt_string, error->nt_status);
838 wbcFreeMemory(error);
840 if (!WBC_ERROR_IS_OK(wbc_status)) {
841 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
842 "%s\n", wbcErrorString(wbc_status));
849 /* Check DC connection */
851 static bool wbinfo_ping_dc(void)
853 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
854 struct wbcAuthErrorInfo *error = NULL;
856 wbc_status = wbcPingDc(NULL, &error);
858 d_printf("checking the NETLOGON dc connection %s\n",
859 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
861 if (wbc_status == WBC_ERR_AUTH_ERROR) {
862 d_fprintf(stderr, "error code was %s (0x%x)\n",
863 error->nt_string, error->nt_status);
864 wbcFreeMemory(error);
866 if (!WBC_ERROR_IS_OK(wbc_status)) {
867 d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
868 wbcErrorString(wbc_status));
875 /* Convert uid to sid */
877 static bool wbinfo_uid_to_sid(uid_t uid)
879 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
880 struct wbcDomainSid sid;
881 char *sid_str = NULL;
885 wbc_status = wbcUidToSid(uid, &sid);
886 if (!WBC_ERROR_IS_OK(wbc_status)) {
887 d_fprintf(stderr, "failed to call wbcUidToSid: %s\n",
888 wbcErrorString(wbc_status));
892 wbc_status = wbcSidToString(&sid, &sid_str);
893 if (!WBC_ERROR_IS_OK(wbc_status)) {
894 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
895 wbcErrorString(wbc_status));
899 /* Display response */
901 d_printf("%s\n", sid_str);
903 wbcFreeMemory(sid_str);
908 /* Convert gid to sid */
910 static bool wbinfo_gid_to_sid(gid_t gid)
912 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
913 struct wbcDomainSid sid;
914 char *sid_str = NULL;
918 wbc_status = wbcGidToSid(gid, &sid);
919 if (!WBC_ERROR_IS_OK(wbc_status)) {
920 d_fprintf(stderr, "failed to call wbcGidToSid: %s\n",
921 wbcErrorString(wbc_status));
925 wbc_status = wbcSidToString(&sid, &sid_str);
926 if (!WBC_ERROR_IS_OK(wbc_status)) {
927 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
928 wbcErrorString(wbc_status));
932 /* Display response */
934 d_printf("%s\n", sid_str);
936 wbcFreeMemory(sid_str);
941 /* Convert sid to uid */
943 static bool wbinfo_sid_to_uid(const char *sid_str)
945 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
946 struct wbcDomainSid sid;
951 wbc_status = wbcStringToSid(sid_str, &sid);
952 if (!WBC_ERROR_IS_OK(wbc_status)) {
953 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
954 wbcErrorString(wbc_status));
958 wbc_status = wbcSidToUid(&sid, &uid);
959 if (!WBC_ERROR_IS_OK(wbc_status)) {
960 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
961 wbcErrorString(wbc_status));
965 /* Display response */
967 d_printf("%d\n", (int)uid);
972 static bool wbinfo_sid_to_gid(const char *sid_str)
974 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
975 struct wbcDomainSid sid;
980 wbc_status = wbcStringToSid(sid_str, &sid);
981 if (!WBC_ERROR_IS_OK(wbc_status)) {
982 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
983 wbcErrorString(wbc_status));
987 wbc_status = wbcSidToGid(&sid, &gid);
988 if (!WBC_ERROR_IS_OK(wbc_status)) {
989 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
990 wbcErrorString(wbc_status));
994 /* Display response */
996 d_printf("%d\n", (int)gid);
1001 static bool wbinfo_allocate_uid(void)
1003 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1008 wbc_status = wbcAllocateUid(&uid);
1009 if (!WBC_ERROR_IS_OK(wbc_status)) {
1010 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
1011 wbcErrorString(wbc_status));
1015 /* Display response */
1017 d_printf("New uid: %u\n", (unsigned int)uid);
1022 static bool wbinfo_allocate_gid(void)
1024 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1029 wbc_status = wbcAllocateGid(&gid);
1030 if (!WBC_ERROR_IS_OK(wbc_status)) {
1031 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
1032 wbcErrorString(wbc_status));
1036 /* Display response */
1038 d_printf("New gid: %u\n", (unsigned int)gid);
1043 static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
1045 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1046 struct wbcDomainSid sid;
1050 wbc_status = wbcStringToSid(sid_str, &sid);
1051 if (!WBC_ERROR_IS_OK(wbc_status)) {
1052 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1053 wbcErrorString(wbc_status));
1057 wbc_status = wbcRemoveUidMapping(uid, &sid);
1058 if (!WBC_ERROR_IS_OK(wbc_status)) {
1059 d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
1060 wbcErrorString(wbc_status));
1064 /* Display response */
1066 d_printf("Removed uid %u to sid %s mapping\n",
1067 (unsigned int)uid, sid_str);
1072 static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
1074 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1075 struct wbcDomainSid sid;
1079 wbc_status = wbcStringToSid(sid_str, &sid);
1080 if (!WBC_ERROR_IS_OK(wbc_status)) {
1081 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1082 wbcErrorString(wbc_status));
1086 wbc_status = wbcRemoveGidMapping(gid, &sid);
1087 if (!WBC_ERROR_IS_OK(wbc_status)) {
1088 d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
1089 wbcErrorString(wbc_status));
1093 /* Display response */
1095 d_printf("Removed gid %u to sid %s mapping\n",
1096 (unsigned int)gid, sid_str);
1101 /* Convert sid to string */
1103 static bool wbinfo_lookupsid(const char *sid_str)
1105 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1106 struct wbcDomainSid sid;
1109 enum wbcSidType type;
1111 /* Send off request */
1113 wbc_status = wbcStringToSid(sid_str, &sid);
1114 if (!WBC_ERROR_IS_OK(wbc_status)) {
1115 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1116 wbcErrorString(wbc_status));
1120 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1121 if (!WBC_ERROR_IS_OK(wbc_status)) {
1122 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
1123 wbcErrorString(wbc_status));
1127 /* Display response */
1129 d_printf("%s%c%s %d\n",
1130 domain, winbind_separator(), name, type);
1135 /* Convert sid to fullname */
1137 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1139 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1140 struct wbcDomainSid sid;
1143 enum wbcSidType type;
1145 /* Send off request */
1147 wbc_status = wbcStringToSid(sid_str, &sid);
1148 if (!WBC_ERROR_IS_OK(wbc_status)) {
1149 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1150 wbcErrorString(wbc_status));
1154 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1155 if (!WBC_ERROR_IS_OK(wbc_status)) {
1156 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
1157 wbcErrorString(wbc_status));
1161 /* Display response */
1163 d_printf("%s%c%s %d\n",
1164 domain, winbind_separator(), name, type);
1169 /* Lookup a list of RIDs */
1171 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1173 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1174 struct wbcDomainInfo *dinfo = NULL;
1175 char *domain_name = NULL;
1176 const char **names = NULL;
1177 enum wbcSidType *types = NULL;
1180 uint32_t *rids = NULL;
1183 TALLOC_CTX *mem_ctx = NULL;
1186 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1187 domain = get_winbind_domain();
1192 wbc_status = wbcDomainInfo(domain, &dinfo);
1193 if (!WBC_ERROR_IS_OK(wbc_status)) {
1194 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1195 wbcErrorString(wbc_status));
1199 mem_ctx = talloc_new(NULL);
1200 if (mem_ctx == NULL) {
1201 d_printf("talloc_new failed\n");
1209 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1210 uint32_t rid = strtoul(ridstr, NULL, 10);
1211 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1213 d_printf("talloc_realloc failed\n");
1215 rids[num_rids] = rid;
1220 d_printf("no rids\n");
1224 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
1225 (const char **)&domain_name, &names, &types);
1226 if (!WBC_ERROR_IS_OK(wbc_status)) {
1227 d_printf("winbind_lookup_rids failed: %s\n",
1228 wbcErrorString(wbc_status));
1232 d_printf("Domain: %s\n", domain_name);
1234 for (i=0; i<num_rids; i++) {
1235 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1236 wbcSidTypeString(types[i]));
1242 wbcFreeMemory(dinfo);
1245 wbcFreeMemory(domain_name);
1248 wbcFreeMemory(names);
1251 wbcFreeMemory(types);
1253 TALLOC_FREE(mem_ctx);
1257 /* Convert string to sid */
1259 static bool wbinfo_lookupname(const char *full_name)
1261 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1262 struct wbcDomainSid sid;
1264 enum wbcSidType type;
1265 fstring domain_name;
1266 fstring account_name;
1268 /* Send off request */
1270 parse_wbinfo_domain_user(full_name, domain_name,
1273 wbc_status = wbcLookupName(domain_name, account_name,
1275 if (!WBC_ERROR_IS_OK(wbc_status)) {
1276 d_fprintf(stderr, "failed to call wbcLookupName: %s\n",
1277 wbcErrorString(wbc_status));
1281 wbc_status = wbcSidToString(&sid, &sid_str);
1282 if (!WBC_ERROR_IS_OK(wbc_status)) {
1283 d_fprintf(stderr, "failed to call wbcSidToString: %s\n",
1284 wbcErrorString(wbc_status));
1288 /* Display response */
1290 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
1292 wbcFreeMemory(sid_str);
1297 static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
1299 const char *username)
1302 const char *ret = NULL;
1304 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1309 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1314 prompt = talloc_asprintf_append(prompt, "password: ");
1319 ret = getpass(prompt);
1320 TALLOC_FREE(prompt);
1322 return talloc_strdup(mem_ctx, ret);
1325 /* Authenticate a user with a plaintext password */
1327 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1329 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1332 char *password = NULL;
1334 char *local_cctype = NULL;
1336 struct wbcLogonUserParams params;
1337 struct wbcLogonUserInfo *info;
1338 struct wbcAuthErrorInfo *error;
1339 struct wbcUserPasswordPolicyInfo *policy;
1340 TALLOC_CTX *frame = talloc_tos();
1342 if ((s = talloc_strdup(frame, username)) == NULL) {
1346 if ((p = strchr(s, '%')) != NULL) {
1349 password = talloc_strdup(frame, p);
1351 password = wbinfo_prompt_pass(frame, NULL, username);
1354 local_cctype = talloc_strdup(frame, cctype);
1360 params.username = name;
1361 params.password = password;
1362 params.num_blobs = 0;
1363 params.blobs = NULL;
1365 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1371 if (!WBC_ERROR_IS_OK(wbc_status)) {
1372 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1373 wbcErrorString(wbc_status));
1377 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1383 if (!WBC_ERROR_IS_OK(wbc_status)) {
1384 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1385 wbcErrorString(wbc_status));
1389 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1393 (uint8_t *)local_cctype,
1395 if (!WBC_ERROR_IS_OK(wbc_status)) {
1396 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1397 wbcErrorString(wbc_status));
1401 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1403 d_printf("plaintext kerberos password authentication for [%s] %s "
1404 "(requesting cctype: %s)\n",
1405 username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1410 "error code was %s (0x%x)\nerror message was: %s\n",
1413 error->display_string);
1416 if (WBC_ERROR_IS_OK(wbc_status)) {
1417 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1418 if (info && info->info && info->info->user_flags &
1419 NETLOGON_CACHED_ACCOUNT) {
1420 d_printf("user_flgs: "
1421 "NETLOGON_CACHED_ACCOUNT\n");
1427 for (i=0; i < info->num_blobs; i++) {
1428 if (strequal(info->blobs[i].name,
1430 d_printf("credentials were put "
1433 info->blobs[i].blob.data);
1438 d_printf("no credentials cached\n");
1443 wbcFreeMemory(params.blobs);
1445 return WBC_ERROR_IS_OK(wbc_status);
1448 /* Authenticate a user with a plaintext password */
1450 static bool wbinfo_auth(char *username)
1452 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1455 char *password = NULL;
1457 TALLOC_CTX *frame = talloc_tos();
1459 if ((s = talloc_strdup(frame, username)) == NULL) {
1463 if ((p = strchr(s, '%')) != NULL) {
1466 password = talloc_strdup(frame, p);
1468 password = wbinfo_prompt_pass(frame, NULL, username);
1473 wbc_status = wbcAuthenticateUser(name, password);
1475 d_printf("plaintext password authentication %s\n",
1476 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1479 if (response.data.auth.nt_status)
1481 "error code was %s (0x%x)\nerror message was: %s\n",
1482 response.data.auth.nt_status_string,
1483 response.data.auth.nt_status,
1484 response.data.auth.error_string);
1487 return WBC_ERROR_IS_OK(wbc_status);
1490 /* Authenticate a user with a challenge/response */
1492 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1494 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1495 struct wbcAuthUserParams params;
1496 struct wbcAuthUserInfo *info = NULL;
1497 struct wbcAuthErrorInfo *err = NULL;
1498 DATA_BLOB lm = data_blob_null;
1499 DATA_BLOB nt = data_blob_null;
1501 fstring name_domain;
1504 TALLOC_CTX *frame = talloc_tos();
1506 p = strchr(username, '%');
1510 pass = talloc_strdup(frame, p + 1);
1512 pass = wbinfo_prompt_pass(frame, NULL, username);
1515 parse_wbinfo_domain_user(username, name_domain, name_user);
1517 params.account_name = name_user;
1518 params.domain_name = name_domain;
1519 params.workstation_name = NULL;
1522 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1523 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1525 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1527 generate_random_buffer(params.password.response.challenge, 8);
1530 DATA_BLOB server_chal;
1531 DATA_BLOB names_blob;
1533 server_chal = data_blob(params.password.response.challenge, 8);
1535 /* Pretend this is a login to 'us', for blob purposes */
1536 names_blob = NTLMv2_generate_names_blob(NULL,
1537 get_winbind_netbios_name(),
1538 get_winbind_domain());
1540 if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1543 &lm, &nt, NULL, NULL)) {
1544 data_blob_free(&names_blob);
1545 data_blob_free(&server_chal);
1549 data_blob_free(&names_blob);
1550 data_blob_free(&server_chal);
1555 lm = data_blob(NULL, 24);
1556 ok = SMBencrypt(pass,
1557 params.password.response.challenge,
1560 data_blob_free(&lm);
1563 nt = data_blob(NULL, 24);
1564 SMBNTencrypt(pass, params.password.response.challenge,
1568 params.password.response.nt_length = nt.length;
1569 params.password.response.nt_data = nt.data;
1570 params.password.response.lm_length = lm.length;
1571 params.password.response.lm_data = lm.data;
1573 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1575 /* Display response */
1577 d_printf("challenge/response password authentication %s\n",
1578 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1580 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1582 "error code was %s (0x%x)\nerror message was: %s\n",
1585 err->display_string);
1587 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1588 wbcFreeMemory(info);
1591 data_blob_free(&nt);
1592 data_blob_free(&lm);
1594 return WBC_ERROR_IS_OK(wbc_status);
1597 /* Authenticate a user with a plaintext password */
1599 static bool wbinfo_pam_logon(char *username)
1601 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1602 struct wbcLogonUserParams params;
1603 struct wbcAuthErrorInfo *error;
1606 TALLOC_CTX *frame = talloc_tos();
1610 ZERO_STRUCT(params);
1612 if ((s = talloc_strdup(frame, username)) == NULL) {
1616 if ((p = strchr(s, '%')) != NULL) {
1619 params.password = talloc_strdup(frame, p);
1621 params.password = wbinfo_prompt_pass(frame, NULL, username);
1623 params.username = s;
1625 flags = WBFLAG_PAM_CACHED_LOGIN;
1627 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1629 (uint8_t *)&flags, sizeof(flags));
1630 if (!WBC_ERROR_IS_OK(wbc_status)) {
1631 d_printf("wbcAddNamedBlob failed: %s\n",
1632 wbcErrorString(wbc_status));
1638 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1640 (uint8_t *)&uid, sizeof(uid));
1641 if (!WBC_ERROR_IS_OK(wbc_status)) {
1642 d_printf("wbcAddNamedBlob failed: %s\n",
1643 wbcErrorString(wbc_status));
1647 wbc_status = wbcLogonUser(¶ms, NULL, &error, NULL);
1649 wbcFreeMemory(params.blobs);
1651 d_printf("plaintext password authentication %s\n",
1652 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1654 if (!WBC_ERROR_IS_OK(wbc_status)) {
1656 "error code was %s (0x%x)\nerror message was: %s\n",
1658 (int)error->nt_status,
1659 error->display_string);
1660 wbcFreeMemory(error);
1666 /* Save creds with winbind */
1668 static bool wbinfo_ccache_save(char *username)
1670 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1673 char *password = NULL;
1675 TALLOC_CTX *frame = talloc_stackframe();
1677 s = talloc_strdup(frame, username);
1686 password = talloc_strdup(frame, p);
1688 password = wbinfo_prompt_pass(frame, NULL, username);
1693 wbc_status = wbcCredentialSave(name, password);
1695 d_printf("saving creds %s\n",
1696 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1700 return WBC_ERROR_IS_OK(wbc_status);
1703 #ifdef WITH_FAKE_KASERVER
1704 /* Authenticate a user with a plaintext password and set a token */
1706 static bool wbinfo_klog(char *username)
1708 struct winbindd_request request;
1709 struct winbindd_response response;
1713 /* Send off request */
1715 ZERO_STRUCT(request);
1716 ZERO_STRUCT(response);
1718 p = strchr(username, '%');
1722 fstrcpy(request.data.auth.user, username);
1723 fstrcpy(request.data.auth.pass, p + 1);
1726 fstrcpy(request.data.auth.user, username);
1727 fstrcpy(request.data.auth.pass, getpass("Password: "));
1730 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1732 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
1735 /* Display response */
1737 d_printf("plaintext password authentication %s\n",
1738 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1740 if (response.data.auth.nt_status)
1742 "error code was %s (0x%x)\nerror message was: %s\n",
1743 response.data.auth.nt_status_string,
1744 response.data.auth.nt_status,
1745 response.data.auth.error_string);
1747 if (result != NSS_STATUS_SUCCESS)
1750 if (response.extra_data.data == NULL) {
1751 d_fprintf(stderr, "Did not get token data\n");
1755 if (!afs_settoken_str((char *)response.extra_data.data)) {
1756 d_fprintf(stderr, "Could not set token\n");
1760 d_printf("Successfully created AFS token\n");
1764 static bool wbinfo_klog(char *username)
1766 d_fprintf(stderr, "No AFS support compiled in.\n");
1771 /* Print domain users */
1773 static bool print_domain_users(const char *domain)
1775 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1777 uint32_t num_users = 0;
1778 const char **users = NULL;
1780 /* Send request to winbind daemon */
1782 /* '.' is the special sign for our own domain */
1783 if (domain && strcmp(domain, ".") == 0) {
1784 domain = get_winbind_domain();
1787 wbc_status = wbcListUsers(domain, &num_users, &users);
1788 if (!WBC_ERROR_IS_OK(wbc_status)) {
1792 for (i=0; i < num_users; i++) {
1793 d_printf("%s\n", users[i]);
1796 wbcFreeMemory(users);
1801 /* Print domain groups */
1803 static bool print_domain_groups(const char *domain)
1805 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1807 uint32_t num_groups = 0;
1808 const char **groups = NULL;
1810 /* Send request to winbind daemon */
1812 /* '.' is the special sign for our own domain */
1813 if (domain && strcmp(domain, ".") == 0) {
1814 domain = get_winbind_domain();
1817 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1818 if (!WBC_ERROR_IS_OK(wbc_status)) {
1819 d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
1820 wbcErrorString(wbc_status));
1824 for (i=0; i < num_groups; i++) {
1825 d_printf("%s\n", groups[i]);
1828 wbcFreeMemory(groups);
1833 /* Set the authorised user for winbindd access in secrets.tdb */
1835 static bool wbinfo_set_auth_user(char *username)
1837 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1838 "See 'net help setauthuser' for details.\n");
1842 static void wbinfo_get_auth_user(void)
1844 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1845 "See 'net help getauthuser' for details.\n");
1848 static bool wbinfo_ping(void)
1852 wbc_status = wbcPing();
1854 /* Display response */
1856 d_printf("Ping to winbindd %s\n",
1857 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1859 return WBC_ERROR_IS_OK(wbc_status);
1862 static bool wbinfo_change_user_password(const char *username)
1865 char *old_password = NULL;
1866 char *new_password = NULL;
1867 TALLOC_CTX *frame = talloc_tos();
1869 old_password = wbinfo_prompt_pass(frame, "old", username);
1870 new_password = wbinfo_prompt_pass(frame, "new", username);
1872 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
1874 /* Display response */
1876 d_printf("Password change for user %s %s\n", username,
1877 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1879 return WBC_ERROR_IS_OK(wbc_status);
1885 OPT_SET_AUTH_USER = 1000,
1897 OPT_REMOVE_UID_MAPPING,
1898 OPT_REMOVE_GID_MAPPING,
1900 OPT_LIST_ALL_DOMAINS,
1901 OPT_LIST_OWN_DOMAIN,
1908 OPT_CHANGE_USER_PASSWORD,
1910 OPT_SID_TO_FULLNAME,
1919 int main(int argc, char **argv, char **envp)
1922 TALLOC_CTX *frame = talloc_stackframe();
1924 static char *string_arg;
1925 char *string_subarg = NULL;
1926 static char *opt_domain_name;
1928 int int_subarg = -1;
1930 bool verbose = false;
1931 bool use_ntlmv2 = false;
1932 bool use_lanman = false;
1933 char *logoff_user = getenv("USER");
1934 int logoff_uid = geteuid();
1936 struct poptOption long_options[] = {
1939 /* longName, shortName, argInfo, argPtr, value, descrip,
1942 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1943 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1944 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1945 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1946 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1947 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1948 { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
1949 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
1950 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1951 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1952 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1953 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1954 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1955 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1956 "Get a new UID out of idmap" },
1957 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1958 "Get a new GID out of idmap" },
1959 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
1960 { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
1961 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1962 { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
1963 { "ping-dc", 'P', POPT_ARG_NONE, 0, 'P',
1964 "Check the NETLOGON connection" },
1965 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1966 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1967 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1968 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Deprecated command, see --online-status" },
1969 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
1970 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1971 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1972 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1973 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1974 { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" },
1975 { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" },
1976 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1977 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1978 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1979 { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" },
1980 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1981 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1982 { "pam-logon", 0, POPT_ARG_STRING, &string_arg, OPT_PAM_LOGON,
1983 "do a pam logon equivalent", "user%password" },
1984 { "logoff", 0, POPT_ARG_NONE, NULL, OPT_LOGOFF,
1985 "log off user", "uid" },
1986 { "logoff-user", 0, POPT_ARG_STRING, &logoff_user,
1987 OPT_LOGOFF_USER, "username to log off" },
1988 { "logoff-uid", 0, POPT_ARG_INT, &logoff_uid,
1989 OPT_LOGOFF_UID, "uid to log off" },
1990 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1991 { "ccache-save", 0, POPT_ARG_STRING, &string_arg,
1992 OPT_CCACHE_SAVE, "Store user and password for ccache "
1993 "operation", "user%password" },
1994 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1995 "Get a DC name for a foreign domain", "domainname" },
1996 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1997 { "dc-info", 0, POPT_ARG_STRING, &string_arg, OPT_DC_INFO,
1998 "Find the currently known DCs", "domainname" },
1999 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
2000 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
2001 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
2002 #ifdef WITH_FAKE_KASERVER
2003 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
2006 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
2007 /* destroys wbinfo --help output */
2008 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
2010 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
2011 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
2012 { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
2013 { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
2014 { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
2019 /* Samba client initialisation */
2025 pc = poptGetContext("wbinfo", argc, (const char **)argv,
2028 /* Parse command line options */
2031 poptPrintHelp(pc, stderr, 0);
2035 while((opt = poptGetNextOpt(pc)) != -1) {
2036 /* get the generic configuration parameters like --domain */
2050 poptFreeContext(pc);
2052 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
2053 POPT_CONTEXT_KEEP_FIRST);
2055 while((opt = poptGetNextOpt(pc)) != -1) {
2058 if (!print_domain_users(opt_domain_name)) {
2060 "Error looking up domain users\n");
2065 if (!print_domain_groups(opt_domain_name)) {
2067 "Error looking up domain groups\n");
2072 if (!wbinfo_lookupsid(string_arg)) {
2074 "Could not lookup sid %s\n",
2079 case OPT_SID_TO_FULLNAME:
2080 if (!wbinfo_lookupsid_fullname(string_arg)) {
2081 d_fprintf(stderr, "Could not lookup sid %s\n",
2087 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
2088 d_fprintf(stderr, "Could not lookup RIDs %s\n",
2094 if (!wbinfo_lookupname(string_arg)) {
2095 d_fprintf(stderr, "Could not lookup name %s\n",
2101 if (!wbinfo_wins_byname(string_arg)) {
2103 "Could not lookup WINS by name %s\n",
2109 if (!wbinfo_wins_byip(string_arg)) {
2111 "Could not lookup WINS by IP %s\n",
2117 if (!wbinfo_uid_to_sid(int_arg)) {
2119 "Could not convert uid %d to sid\n",
2125 if (!wbinfo_gid_to_sid(int_arg)) {
2127 "Could not convert gid %d to sid\n",
2133 if (!wbinfo_sid_to_uid(string_arg)) {
2135 "Could not convert sid %s to uid\n",
2141 if (!wbinfo_sid_to_gid(string_arg)) {
2143 "Could not convert sid %s to gid\n",
2148 case OPT_ALLOCATE_UID:
2149 if (!wbinfo_allocate_uid()) {
2150 d_fprintf(stderr, "Could not allocate a uid\n");
2154 case OPT_ALLOCATE_GID:
2155 if (!wbinfo_allocate_gid()) {
2156 d_fprintf(stderr, "Could not allocate a gid\n");
2160 case OPT_REMOVE_UID_MAPPING:
2161 if (!parse_mapping_arg(string_arg, &int_subarg,
2163 !wbinfo_remove_uid_mapping(int_subarg,
2166 d_fprintf(stderr, "Could not remove uid to sid "
2171 case OPT_REMOVE_GID_MAPPING:
2172 if (!parse_mapping_arg(string_arg, &int_subarg,
2174 !wbinfo_remove_gid_mapping(int_subarg,
2177 d_fprintf(stderr, "Could not remove gid to sid "
2183 if (!wbinfo_check_secret(opt_domain_name)) {
2184 d_fprintf(stderr, "Could not check secret\n");
2189 if (!wbinfo_change_secret(opt_domain_name)) {
2190 d_fprintf(stderr, "Could not change secret\n");
2195 if (!wbinfo_ping_dc()) {
2196 d_fprintf(stderr, "Could not ping our DC\n");
2201 if (!wbinfo_list_domains(false, verbose)) {
2203 "Could not list trusted domains\n");
2208 if (!wbinfo_show_sequence(opt_domain_name)) {
2210 "Could not show sequence numbers\n");
2214 case OPT_ONLINESTATUS:
2215 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
2217 "Could not show online-status\n");
2222 if (!wbinfo_domain_info(string_arg)) {
2224 "Could not get domain info\n");
2229 if (!wbinfo_get_userinfo(string_arg)) {
2231 "Could not get info for user %s\n",
2236 case OPT_USER_SIDINFO:
2237 if ( !wbinfo_get_user_sidinfo(string_arg)) {
2239 "Could not get info for user "
2240 "sid %s\n", string_arg);
2245 if ( !wbinfo_get_uidinfo(int_arg)) {
2246 d_fprintf(stderr, "Could not get info for uid "
2251 case OPT_GROUP_INFO:
2252 if ( !wbinfo_get_groupinfo(string_arg)) {
2253 d_fprintf(stderr, "Could not get info for "
2254 "group %s\n", string_arg);
2259 if ( !wbinfo_get_gidinfo(int_arg)) {
2260 d_fprintf(stderr, "Could not get info for gid "
2266 if (!wbinfo_get_usergroups(string_arg)) {
2268 "Could not get groups for user %s\n",
2274 if (!wbinfo_get_usersids(string_arg)) {
2275 d_fprintf(stderr, "Could not get group SIDs "
2276 "for user SID %s\n",
2281 case OPT_USERDOMGROUPS:
2282 if (!wbinfo_get_userdomgroups(string_arg)) {
2283 d_fprintf(stderr, "Could not get user's domain "
2284 "groups for user SID %s\n",
2289 case OPT_SIDALIASES:
2290 if (!wbinfo_get_sidaliases(opt_domain_name,
2292 d_fprintf(stderr, "Could not get sid aliases "
2293 "for user SID %s\n", string_arg);
2298 bool got_error = false;
2300 if (!wbinfo_auth(string_arg)) {
2302 "Could not authenticate user "
2303 "%s with plaintext "
2304 "password\n", string_arg);
2308 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
2311 "Could not authenticate user "
2312 "%s with challenge/response\n",
2322 if (!wbinfo_pam_logon(string_arg)) {
2323 d_fprintf(stderr, "pam_logon failed for %s\n",
2332 wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
2334 d_printf("Logoff %s (%d): %s\n", logoff_user,
2335 logoff_uid, wbcErrorString(wbc_status));
2339 uint32_t flags = WBFLAG_PAM_KRB5 |
2340 WBFLAG_PAM_CACHED_LOGIN |
2341 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
2342 WBFLAG_PAM_INFO3_TEXT |
2343 WBFLAG_PAM_CONTACT_TRUSTDOM;
2345 if (!wbinfo_auth_krb5(string_arg, "FILE",
2348 "Could not authenticate user "
2349 "[%s] with Kerberos "
2350 "(ccache: %s)\n", string_arg,
2357 if (!wbinfo_klog(string_arg)) {
2358 d_fprintf(stderr, "Could not klog user\n");
2363 if (!wbinfo_ping()) {
2364 d_fprintf(stderr, "could not ping winbindd!\n");
2368 case OPT_SET_AUTH_USER:
2369 if (!wbinfo_set_auth_user(string_arg)) {
2373 case OPT_GET_AUTH_USER:
2374 wbinfo_get_auth_user();
2377 case OPT_CCACHE_SAVE:
2378 if (!wbinfo_ccache_save(string_arg)) {
2383 if (!wbinfo_getdcname(string_arg)) {
2387 case OPT_DSGETDCNAME:
2388 if (!wbinfo_dsgetdcname(string_arg, 0)) {
2393 if (!wbinfo_dc_info(string_arg)) {
2397 case OPT_SEPARATOR: {
2398 const char sep = winbind_separator();
2402 d_printf("%c\n", sep);
2405 case OPT_LIST_ALL_DOMAINS:
2406 if (!wbinfo_list_domains(true, verbose)) {
2410 case OPT_LIST_OWN_DOMAIN:
2411 if (!wbinfo_list_own_domain()) {
2415 case OPT_CHANGE_USER_PASSWORD:
2416 if (!wbinfo_change_user_password(string_arg)) {
2418 "Could not change user password "
2419 "for user %s\n", string_arg);
2424 /* generic configuration options */
2425 case OPT_DOMAIN_NAME:
2429 case OPT_LOGOFF_USER:
2430 case OPT_LOGOFF_UID:
2433 d_fprintf(stderr, "Invalid option\n");
2434 poptPrintHelp(pc, stderr, 0);
2446 poptFreeContext(pc);