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 "libwbclient/wbclient.h"
26 #include "winbind_struct_protocol.h"
27 #include "libwbclient/wbclient_internal.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #include "lib/cmdline/cmdline.h"
30 #include "lib/afs/afs_settoken.h"
31 #include "lib/util/smb_strtox.h"
32 #include "lib/util/string_wrappers.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 p = strchr(domuser, '@');
126 fstrcpy(user, domuser);
130 fstrcpy(user, domuser);
131 fstrcpy(domain, get_winbind_domain());
136 fstrcpy(domain, domuser);
137 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)
152 tmp = strtok(arg, ",");
153 *sid = strtok(NULL, ",");
155 if (!tmp || !*tmp || !*sid || !**sid)
158 /* Because atoi() can return 0 on invalid input, which would be a valid
159 * UID/GID we must use strtoul() and do error checking */
160 *id = smb_strtoul(tmp, NULL, 10, &error, SMB_STR_FULL_STR_CONV);
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,
195 /* pull pwent info for a given uid */
196 static bool wbinfo_get_uidinfo(int uid)
198 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
199 struct passwd *pwd = NULL;
201 wbc_status = wbcGetpwuid(uid, &pwd);
202 if (!WBC_ERROR_IS_OK(wbc_status)) {
203 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
204 wbcErrorString(wbc_status));
208 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
211 (unsigned int)pwd->pw_uid,
212 (unsigned int)pwd->pw_gid,
222 static bool wbinfo_get_user_sidinfo(const char *sid_str)
224 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
225 struct passwd *pwd = NULL;
226 struct wbcDomainSid sid;
228 wbc_status = wbcStringToSid(sid_str, &sid);
229 wbc_status = wbcGetpwsid(&sid, &pwd);
230 if (!WBC_ERROR_IS_OK(wbc_status)) {
231 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
232 wbcErrorString(wbc_status));
236 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
239 (unsigned int)pwd->pw_uid,
240 (unsigned int)pwd->pw_gid,
251 /* pull grent for a given group */
252 static bool wbinfo_get_groupinfo(const char *group)
254 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
258 wbc_status = wbcGetgrnam(group, &grp);
259 if (!WBC_ERROR_IS_OK(wbc_status)) {
260 d_fprintf(stderr, "failed to call wbcGetgrnam: %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 /* pull grent for a given gid */
283 static bool wbinfo_get_gidinfo(int gid)
285 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
289 wbc_status = wbcGetgrgid(gid, &grp);
290 if (!WBC_ERROR_IS_OK(wbc_status)) {
291 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
292 wbcErrorString(wbc_status));
296 d_printf("%s:%s:%u:",
299 (unsigned int)grp->gr_gid);
302 while (*mem != NULL) {
303 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
313 /* List groups a user is a member of */
315 static bool wbinfo_get_usergroups(const char *user)
317 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
320 gid_t *groups = NULL;
324 wbc_status = wbcGetGroups(user, &num_groups, &groups);
325 if (!WBC_ERROR_IS_OK(wbc_status)) {
326 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
327 wbcErrorString(wbc_status));
331 for (i = 0; i < num_groups; i++) {
332 d_printf("%d\n", (int)groups[i]);
335 wbcFreeMemory(groups);
341 /* List group SIDs a user SID is a member of */
342 static bool wbinfo_get_usersids(const char *user_sid_str)
344 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
347 struct wbcDomainSid user_sid, *sids = NULL;
351 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
352 if (!WBC_ERROR_IS_OK(wbc_status)) {
353 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
354 wbcErrorString(wbc_status));
358 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
359 if (!WBC_ERROR_IS_OK(wbc_status)) {
360 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
361 wbcErrorString(wbc_status));
365 for (i = 0; i < num_sids; i++) {
366 char str[WBC_SID_STRING_BUFLEN];
367 wbcSidToStringBuf(&sids[i], str, sizeof(str));
368 d_printf("%s\n", str);
376 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
378 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
381 struct wbcDomainSid user_sid, *sids = NULL;
385 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
386 if (!WBC_ERROR_IS_OK(wbc_status)) {
387 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
388 wbcErrorString(wbc_status));
392 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
393 if (!WBC_ERROR_IS_OK(wbc_status)) {
394 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
395 wbcErrorString(wbc_status));
399 for (i = 0; i < num_sids; i++) {
400 char str[WBC_SID_STRING_BUFLEN];
401 wbcSidToStringBuf(&sids[i], str, sizeof(str));
402 d_printf("%s\n", str);
410 static bool wbinfo_get_sidaliases(const char *domain,
411 const char *user_sid_str)
413 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
414 struct wbcDomainInfo *dinfo = NULL;
416 struct wbcDomainSid user_sid;
417 uint32_t *alias_rids = NULL;
418 uint32_t num_alias_rids;
419 char domain_sid_str[WBC_SID_STRING_BUFLEN];
422 if ((domain == NULL) || (strequal(domain, ".")) ||
423 (domain[0] == '\0')) {
424 domain = get_winbind_domain();
429 wbc_status = wbcDomainInfo(domain, &dinfo);
430 if (!WBC_ERROR_IS_OK(wbc_status)) {
431 d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain,
432 wbcErrorString(wbc_status));
435 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
436 if (!WBC_ERROR_IS_OK(wbc_status)) {
440 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
441 &alias_rids, &num_alias_rids);
442 if (!WBC_ERROR_IS_OK(wbc_status)) {
446 wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str));
448 for (i = 0; i < num_alias_rids; i++) {
449 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
452 wbcFreeMemory(alias_rids);
455 wbcFreeMemory(dinfo);
456 return (WBC_ERR_SUCCESS == wbc_status);
460 /* Convert NetBIOS name to IP */
462 static bool wbinfo_wins_byname(const char *name)
464 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
467 wbc_status = wbcResolveWinsByName(name, &ip);
468 if (!WBC_ERROR_IS_OK(wbc_status)) {
469 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
470 wbcErrorString(wbc_status));
474 /* Display response */
476 d_printf("%s\n", ip);
483 /* Convert IP to NetBIOS name */
485 static bool wbinfo_wins_byip(const char *ip)
487 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
490 wbc_status = wbcResolveWinsByIP(ip, &name);
491 if (!WBC_ERROR_IS_OK(wbc_status)) {
492 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
493 wbcErrorString(wbc_status));
497 /* Display response */
499 d_printf("%s\n", name);
506 /* List all/trusted domains */
508 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
510 struct wbcDomainInfo *domain_list = NULL;
511 size_t i, num_domains;
512 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
513 bool print_all = !list_all_domains && verbose;
515 wbc_status = wbcListTrusts(&domain_list, &num_domains);
516 if (!WBC_ERROR_IS_OK(wbc_status)) {
517 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
518 wbcErrorString(wbc_status));
523 d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
524 "Domain Name", "DNS Domain", "Trust Type",
525 "Transitive", "In", "Out");
528 for (i=0; i<num_domains; i++) {
530 d_printf("%-16s", domain_list[i].short_name);
532 d_printf("%s", domain_list[i].short_name);
537 d_printf("%-65s", domain_list[i].dns_name);
539 switch(domain_list[i].trust_type) {
540 case WBC_DOMINFO_TRUSTTYPE_NONE:
541 if (domain_list[i].trust_routing != NULL) {
542 d_printf("%s\n", domain_list[i].trust_routing);
547 case WBC_DOMINFO_TRUSTTYPE_LOCAL:
550 case WBC_DOMINFO_TRUSTTYPE_RWDC:
553 case WBC_DOMINFO_TRUSTTYPE_RODC:
556 case WBC_DOMINFO_TRUSTTYPE_PDC:
559 case WBC_DOMINFO_TRUSTTYPE_WKSTA:
560 d_printf("Workstation ");
562 case WBC_DOMINFO_TRUSTTYPE_FOREST:
565 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL:
566 d_printf("External ");
568 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST:
569 d_printf("In-Forest ");
573 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_TRANSITIVE) {
579 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_INCOMING) {
585 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_OUTGOING) {
594 wbcFreeMemory(domain_list);
599 /* List own domain */
601 static bool wbinfo_list_own_domain(void)
603 d_printf("%s\n", get_winbind_domain());
608 /* show sequence numbers */
609 static bool wbinfo_show_sequence(const char *domain)
611 d_printf("This command has been deprecated. Please use the "
612 "--online-status option instead.\n");
616 /* show sequence numbers */
617 static bool wbinfo_show_onlinestatus(const char *domain)
619 struct wbcDomainInfo *domain_list = NULL;
620 size_t i, num_domains;
621 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
623 wbc_status = wbcListTrusts(&domain_list, &num_domains);
624 if (!WBC_ERROR_IS_OK(wbc_status)) {
625 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
626 wbcErrorString(wbc_status));
630 for (i=0; i<num_domains; i++) {
634 if (!strequal(domain_list[i].short_name, domain)) {
639 is_offline = (domain_list[i].domain_flags &
640 WBC_DOMINFO_DOMAIN_OFFLINE);
642 d_printf("%s : %s\n",
643 domain_list[i].short_name,
644 is_offline ? "no active connection" : "active connection" );
647 wbcFreeMemory(domain_list);
653 /* Show domain info */
655 static bool wbinfo_domain_info(const char *domain)
657 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
658 struct wbcDomainInfo *dinfo = NULL;
659 char sid_str[WBC_SID_STRING_BUFLEN];
661 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
662 domain = get_winbind_domain();
667 wbc_status = wbcDomainInfo(domain, &dinfo);
668 if (!WBC_ERROR_IS_OK(wbc_status)) {
669 d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n",
670 wbcErrorString(wbc_status));
674 wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str));
676 /* Display response */
678 d_printf("Name : %s\n", dinfo->short_name);
679 d_printf("Alt_Name : %s\n", dinfo->dns_name);
681 d_printf("SID : %s\n", sid_str);
683 d_printf("Active Directory : %s\n",
684 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No");
685 d_printf("Native : %s\n",
686 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ?
689 d_printf("Primary : %s\n",
690 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
693 wbcFreeMemory(dinfo);
698 /* Get a foreign DC's name */
699 static bool wbinfo_getdcname(const char *domain_name)
701 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
702 struct winbindd_request request;
703 struct winbindd_response response;
705 ZERO_STRUCT(request);
706 ZERO_STRUCT(response);
708 fstrcpy(request.domain_name, domain_name);
712 wbc_status = wbcRequestResponse(NULL, WINBINDD_GETDCNAME,
713 &request, &response);
714 if (!WBC_ERROR_IS_OK(wbc_status)) {
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);
754 wbcFreeMemory(dc_info);
759 /* Check trust account password */
761 static bool wbinfo_check_secret(const char *domain)
763 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
764 struct wbcAuthErrorInfo *error = NULL;
765 const char *domain_name;
768 domain_name = domain;
770 domain_name = get_winbind_domain();
773 wbc_status = wbcCheckTrustCredentials(domain_name, &error);
775 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
777 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
779 if (wbc_status == WBC_ERR_AUTH_ERROR) {
780 d_fprintf(stderr, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
781 domain_name, error->nt_string, error->nt_status);
782 wbcFreeMemory(error);
784 if (!WBC_ERROR_IS_OK(wbc_status)) {
785 d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: "
786 "%s\n", wbcErrorString(wbc_status));
793 /* Find the currently connected DCs */
795 static bool wbinfo_dc_info(const char *domain_name)
797 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
799 const char **dc_names, **dc_ips;
801 wbc_status = wbcDcInfo(domain_name, &num_dcs,
803 if (!WBC_ERROR_IS_OK(wbc_status)) {
804 printf("Could not find dc info %s\n",
805 domain_name ? domain_name : "our domain");
809 for (i=0; i<num_dcs; i++) {
810 printf("%s (%s)\n", dc_names[i], dc_ips[i]);
812 wbcFreeMemory(dc_names);
813 wbcFreeMemory(dc_ips);
818 /* Change trust account password */
820 static bool wbinfo_change_secret(const char *domain)
822 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
823 struct wbcAuthErrorInfo *error = NULL;
824 const char *domain_name;
827 domain_name = domain;
829 domain_name = get_winbind_domain();
832 wbc_status = wbcChangeTrustCredentials(domain_name, &error);
834 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
836 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
838 if (wbc_status == WBC_ERR_AUTH_ERROR) {
839 d_fprintf(stderr, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
840 domain_name, error->nt_string, error->nt_status);
841 wbcFreeMemory(error);
843 if (!WBC_ERROR_IS_OK(wbc_status)) {
844 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
845 "%s\n", wbcErrorString(wbc_status));
852 /* Change trust account password chose Domain Controller */
854 static bool wbinfo_change_secret_at(const char *domain,
855 const char *domain_controller)
857 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
858 struct wbcAuthErrorInfo *error = NULL;
859 const char *domain_name;
862 domain_name = domain;
864 domain_name = get_winbind_domain();
867 wbc_status = wbcChangeTrustCredentialsAt(
868 domain_name, domain_controller, &error);
870 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
872 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
874 if (wbc_status == WBC_ERR_AUTH_ERROR) {
875 d_fprintf(stderr, "wbcChangeTrustCredentials(%s): "
876 "error code was %s (0x%x)\n",
877 domain_name, error->nt_string, error->nt_status);
878 wbcFreeMemory(error);
880 if (!WBC_ERROR_IS_OK(wbc_status)) {
881 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
882 "%s\n", wbcErrorString(wbc_status));
889 /* Check DC connection */
891 static bool wbinfo_ping_dc(const char *domain)
893 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
894 struct wbcAuthErrorInfo *error = NULL;
897 const char *domain_name;
900 domain_name = domain;
902 domain_name = get_winbind_domain();
905 wbc_status = wbcPingDc2(domain_name, &error, &dcname);
907 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
908 domain_name ? domain_name : "",
909 dcname ? dcname : "",
910 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
912 wbcFreeMemory(dcname);
913 if (wbc_status == WBC_ERR_AUTH_ERROR) {
914 d_fprintf(stderr, "wbcPingDc2(%s): error code was %s (0x%x)\n",
915 domain_name, error->nt_string, error->nt_status);
916 wbcFreeMemory(error);
919 if (!WBC_ERROR_IS_OK(wbc_status)) {
920 d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
921 wbcErrorString(wbc_status));
928 /* Convert uid to sid */
930 static bool wbinfo_uid_to_sid(uid_t uid)
932 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
933 struct wbcDomainSid sid;
934 char sid_str[WBC_SID_STRING_BUFLEN];
938 wbc_status = wbcUidToSid(uid, &sid);
939 if (!WBC_ERROR_IS_OK(wbc_status)) {
940 d_fprintf(stderr, "failed to call wbcUidToSid: %s\n",
941 wbcErrorString(wbc_status));
945 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
947 /* Display response */
949 d_printf("%s\n", sid_str);
954 /* Convert gid to sid */
956 static bool wbinfo_gid_to_sid(gid_t gid)
958 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
959 struct wbcDomainSid sid;
960 char sid_str[WBC_SID_STRING_BUFLEN];
964 wbc_status = wbcGidToSid(gid, &sid);
965 if (!WBC_ERROR_IS_OK(wbc_status)) {
966 d_fprintf(stderr, "failed to call wbcGidToSid: %s\n",
967 wbcErrorString(wbc_status));
971 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
973 /* Display response */
975 d_printf("%s\n", sid_str);
980 /* Convert sid to uid */
982 static bool wbinfo_sid_to_uid(const char *sid_str)
984 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
985 struct wbcDomainSid sid;
990 wbc_status = wbcStringToSid(sid_str, &sid);
991 if (!WBC_ERROR_IS_OK(wbc_status)) {
992 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
993 wbcErrorString(wbc_status));
997 wbc_status = wbcSidToUid(&sid, &uid);
998 if (!WBC_ERROR_IS_OK(wbc_status)) {
999 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
1000 wbcErrorString(wbc_status));
1004 /* Display response */
1006 d_printf("%d\n", (int)uid);
1011 static bool wbinfo_sid_to_gid(const char *sid_str)
1013 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1014 struct wbcDomainSid sid;
1019 wbc_status = wbcStringToSid(sid_str, &sid);
1020 if (!WBC_ERROR_IS_OK(wbc_status)) {
1021 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1022 wbcErrorString(wbc_status));
1026 wbc_status = wbcSidToGid(&sid, &gid);
1027 if (!WBC_ERROR_IS_OK(wbc_status)) {
1028 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
1029 wbcErrorString(wbc_status));
1033 /* Display response */
1035 d_printf("%d\n", (int)gid);
1040 static bool wbinfo_sids_to_unix_ids(const char *arg)
1042 char sidstr[WBC_SID_STRING_BUFLEN];
1043 struct wbcDomainSid *sids;
1044 struct wbcUnixId *unix_ids;
1054 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1055 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1058 d_fprintf(stderr, "talloc failed\n");
1061 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
1062 if (!WBC_ERROR_IS_OK(wbc_status)) {
1063 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
1064 sidstr, wbcErrorString(wbc_status));
1071 unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids);
1072 if (unix_ids == NULL) {
1077 wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids);
1078 if (!WBC_ERROR_IS_OK(wbc_status)) {
1079 d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n",
1080 wbcErrorString(wbc_status));
1085 for (i=0; i<num_sids; i++) {
1087 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
1089 switch(unix_ids[i].type) {
1090 case WBC_ID_TYPE_UID:
1091 d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid);
1093 case WBC_ID_TYPE_GID:
1094 d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
1096 case WBC_ID_TYPE_BOTH:
1097 d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid);
1100 d_printf("%s -> unmapped\n", sidstr);
1106 TALLOC_FREE(unix_ids);
1111 static bool wbinfo_xids_to_sids(const char *arg)
1114 struct wbcUnixId *xids = NULL;
1115 struct wbcDomainSid *sids;
1123 while (next_token(&p, idstr, LIST_SEP, sizeof(idstr))) {
1124 xids = talloc_realloc(talloc_tos(), xids, struct wbcUnixId,
1127 d_fprintf(stderr, "talloc failed\n");
1133 xids[num_xids] = (struct wbcUnixId) {
1134 .type = WBC_ID_TYPE_UID,
1135 .id.uid = atoi(&idstr[1])
1139 xids[num_xids] = (struct wbcUnixId) {
1140 .type = WBC_ID_TYPE_GID,
1141 .id.gid = atoi(&idstr[1])
1145 d_fprintf(stderr, "%s is an invalid id\n", idstr);
1152 sids = talloc_array(talloc_tos(), struct wbcDomainSid, num_xids);
1154 d_fprintf(stderr, "talloc failed\n");
1159 wbc_status = wbcUnixIdsToSids(xids, num_xids, sids);
1160 if (!WBC_ERROR_IS_OK(wbc_status)) {
1161 d_fprintf(stderr, "wbcUnixIdsToSids failed: %s\n",
1162 wbcErrorString(wbc_status));
1168 for (i=0; i<num_xids; i++) {
1169 char str[WBC_SID_STRING_BUFLEN];
1170 struct wbcDomainSid null_sid = { 0 };
1172 if (memcmp(&null_sid, &sids[i], sizeof(struct wbcDomainSid)) == 0) {
1173 d_printf("NOT MAPPED\n");
1176 wbcSidToStringBuf(&sids[i], str, sizeof(str));
1177 d_printf("%s\n", str);
1183 static bool wbinfo_allocate_uid(void)
1185 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1190 wbc_status = wbcAllocateUid(&uid);
1191 if (!WBC_ERROR_IS_OK(wbc_status)) {
1192 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
1193 wbcErrorString(wbc_status));
1197 /* Display response */
1199 d_printf("New uid: %u\n", (unsigned int)uid);
1204 static bool wbinfo_allocate_gid(void)
1206 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1211 wbc_status = wbcAllocateGid(&gid);
1212 if (!WBC_ERROR_IS_OK(wbc_status)) {
1213 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
1214 wbcErrorString(wbc_status));
1218 /* Display response */
1220 d_printf("New gid: %u\n", (unsigned int)gid);
1225 static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str)
1227 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1228 struct wbcDomainSid sid;
1232 wbc_status = wbcStringToSid(sid_str, &sid);
1233 if (!WBC_ERROR_IS_OK(wbc_status)) {
1234 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1235 wbcErrorString(wbc_status));
1239 wbc_status = wbcSetUidMapping(uid, &sid);
1240 if (!WBC_ERROR_IS_OK(wbc_status)) {
1241 d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n",
1242 wbcErrorString(wbc_status));
1246 /* Display response */
1248 d_printf("uid %u now mapped to sid %s\n",
1249 (unsigned int)uid, sid_str);
1254 static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str)
1256 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1257 struct wbcDomainSid sid;
1261 wbc_status = wbcStringToSid(sid_str, &sid);
1262 if (!WBC_ERROR_IS_OK(wbc_status)) {
1263 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1264 wbcErrorString(wbc_status));
1268 wbc_status = wbcSetGidMapping(gid, &sid);
1269 if (!WBC_ERROR_IS_OK(wbc_status)) {
1270 d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n",
1271 wbcErrorString(wbc_status));
1275 /* Display response */
1277 d_printf("gid %u now mapped to sid %s\n",
1278 (unsigned int)gid, sid_str);
1283 static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
1285 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1286 struct wbcDomainSid sid;
1290 wbc_status = wbcStringToSid(sid_str, &sid);
1291 if (!WBC_ERROR_IS_OK(wbc_status)) {
1292 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1293 wbcErrorString(wbc_status));
1297 wbc_status = wbcRemoveUidMapping(uid, &sid);
1298 if (!WBC_ERROR_IS_OK(wbc_status)) {
1299 d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
1300 wbcErrorString(wbc_status));
1304 /* Display response */
1306 d_printf("Removed uid %u to sid %s mapping\n",
1307 (unsigned int)uid, sid_str);
1312 static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
1314 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1315 struct wbcDomainSid sid;
1319 wbc_status = wbcStringToSid(sid_str, &sid);
1320 if (!WBC_ERROR_IS_OK(wbc_status)) {
1321 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1322 wbcErrorString(wbc_status));
1326 wbc_status = wbcRemoveGidMapping(gid, &sid);
1327 if (!WBC_ERROR_IS_OK(wbc_status)) {
1328 d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
1329 wbcErrorString(wbc_status));
1333 /* Display response */
1335 d_printf("Removed gid %u to sid %s mapping\n",
1336 (unsigned int)gid, sid_str);
1341 /* Convert sid to string */
1343 static bool wbinfo_lookupsid(const char *sid_str)
1345 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1346 struct wbcDomainSid sid;
1349 enum wbcSidType type;
1351 /* Send off request */
1353 wbc_status = wbcStringToSid(sid_str, &sid);
1354 if (!WBC_ERROR_IS_OK(wbc_status)) {
1355 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1356 wbcErrorString(wbc_status));
1360 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1361 if (!WBC_ERROR_IS_OK(wbc_status)) {
1362 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
1363 wbcErrorString(wbc_status));
1367 /* Display response */
1369 if (type == WBC_SID_NAME_DOMAIN) {
1370 d_printf("%s %d\n", domain, type);
1372 d_printf("%s%c%s %d\n",
1373 domain, winbind_separator(), name, type);
1376 wbcFreeMemory(domain);
1377 wbcFreeMemory(name);
1382 /* Convert sid to fullname */
1384 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1386 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1387 struct wbcDomainSid sid;
1390 enum wbcSidType type;
1392 /* Send off request */
1394 wbc_status = wbcStringToSid(sid_str, &sid);
1395 if (!WBC_ERROR_IS_OK(wbc_status)) {
1396 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1397 wbcErrorString(wbc_status));
1401 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1402 if (!WBC_ERROR_IS_OK(wbc_status)) {
1403 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
1404 wbcErrorString(wbc_status));
1408 /* Display response */
1410 d_printf("%s%c%s %d\n",
1411 domain, winbind_separator(), name, type);
1413 wbcFreeMemory(domain);
1414 wbcFreeMemory(name);
1419 /* Lookup a list of RIDs */
1421 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1423 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1424 struct wbcDomainSid dsid;
1425 char *domain_name = NULL;
1426 const char **names = NULL;
1427 enum wbcSidType *types = NULL;
1429 uint32_t *rids = NULL;
1432 TALLOC_CTX *mem_ctx = NULL;
1435 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1436 domain = get_winbind_domain();
1439 wbc_status = wbcStringToSid(domain, &dsid);
1440 if (!WBC_ERROR_IS_OK(wbc_status)) {
1441 struct wbcDomainInfo *dinfo = NULL;
1443 wbc_status = wbcDomainInfo(domain, &dinfo);
1444 if (!WBC_ERROR_IS_OK(wbc_status)) {
1445 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1446 wbcErrorString(wbc_status));
1451 wbcFreeMemory(dinfo);
1454 mem_ctx = talloc_new(NULL);
1455 if (mem_ctx == NULL) {
1456 d_printf("talloc_new failed\n");
1464 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1468 rid = smb_strtoul(ridstr, NULL, 10, &error, SMB_STR_STANDARD);
1470 d_printf("failed to convert rid\n");
1473 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1475 d_printf("talloc_realloc failed\n");
1477 rids[num_rids] = rid;
1482 d_printf("no rids\n");
1486 wbc_status = wbcLookupRids(
1487 &dsid, num_rids, rids, &p, &names, &types);
1488 if (!WBC_ERROR_IS_OK(wbc_status)) {
1489 d_printf("winbind_lookup_rids failed: %s\n",
1490 wbcErrorString(wbc_status));
1494 domain_name = discard_const_p(char, p);
1495 d_printf("Domain: %s\n", domain_name);
1497 for (i=0; i<num_rids; i++) {
1498 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1499 wbcSidTypeString(types[i]));
1504 wbcFreeMemory(domain_name);
1505 wbcFreeMemory(names);
1506 wbcFreeMemory(types);
1507 TALLOC_FREE(mem_ctx);
1511 static bool wbinfo_lookup_sids(const char *arg)
1513 char sidstr[WBC_SID_STRING_BUFLEN];
1514 struct wbcDomainSid *sids;
1515 struct wbcDomainInfo *domains;
1516 struct wbcTranslatedName *names;
1527 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1528 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1531 d_fprintf(stderr, "talloc failed\n");
1534 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
1535 if (!WBC_ERROR_IS_OK(wbc_status)) {
1536 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
1537 sidstr, wbcErrorString(wbc_status));
1544 wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains,
1546 if (!WBC_ERROR_IS_OK(wbc_status)) {
1547 d_fprintf(stderr, "wbcLookupSids failed: %s\n",
1548 wbcErrorString(wbc_status));
1553 for (i=0; i<num_sids; i++) {
1554 const char *domain = NULL;
1556 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
1558 if (names[i].domain_index >= num_domains) {
1560 } else if (names[i].domain_index < 0) {
1563 domain = domains[names[i].domain_index].short_name;
1566 if (names[i].type == WBC_SID_NAME_DOMAIN) {
1567 d_printf("%s -> %s %d\n", sidstr,
1571 d_printf("%s -> %s%c%s %d\n", sidstr,
1573 winbind_separator(),
1574 names[i].name, names[i].type);
1577 wbcFreeMemory(names);
1578 wbcFreeMemory(domains);
1582 /* Convert string to sid */
1584 static bool wbinfo_lookupname(const char *full_name)
1586 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1587 struct wbcDomainSid sid;
1588 char sid_str[WBC_SID_STRING_BUFLEN];
1589 enum wbcSidType type;
1590 fstring domain_name;
1591 fstring account_name;
1593 /* Send off request */
1595 parse_wbinfo_domain_user(full_name, domain_name,
1598 wbc_status = wbcLookupName(domain_name, account_name,
1600 if (!WBC_ERROR_IS_OK(wbc_status)) {
1601 d_fprintf(stderr, "failed to call wbcLookupName: %s\n",
1602 wbcErrorString(wbc_status));
1606 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
1608 /* Display response */
1610 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
1615 static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
1617 const char *username)
1620 char buf[1024] = {0};
1623 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1628 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1633 prompt = talloc_asprintf_append(prompt, "password: ");
1638 rc = samba_getpass(prompt, buf, sizeof(buf), false, false);
1639 TALLOC_FREE(prompt);
1644 return talloc_strdup(mem_ctx, buf);
1647 /* Authenticate a user with a plaintext password */
1649 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1651 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1654 char *password = NULL;
1656 char *local_cctype = NULL;
1658 struct wbcLogonUserParams params;
1659 struct wbcLogonUserInfo *info;
1660 struct wbcAuthErrorInfo *error;
1661 struct wbcUserPasswordPolicyInfo *policy;
1662 TALLOC_CTX *frame = talloc_tos();
1664 if ((s = talloc_strdup(frame, username)) == NULL) {
1668 if ((p = strchr(s, '%')) != NULL) {
1671 password = talloc_strdup(frame, p);
1673 password = wbinfo_prompt_pass(frame, NULL, username);
1676 local_cctype = talloc_strdup(frame, cctype);
1682 params.username = name;
1683 params.password = password;
1684 params.num_blobs = 0;
1685 params.blobs = NULL;
1687 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1693 if (!WBC_ERROR_IS_OK(wbc_status)) {
1694 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1695 wbcErrorString(wbc_status));
1699 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1705 if (!WBC_ERROR_IS_OK(wbc_status)) {
1706 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1707 wbcErrorString(wbc_status));
1711 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1715 (uint8_t *)local_cctype,
1717 if (!WBC_ERROR_IS_OK(wbc_status)) {
1718 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1719 wbcErrorString(wbc_status));
1723 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1725 d_printf("plaintext kerberos password authentication for [%s] %s "
1726 "(requesting cctype: %s)\n",
1727 name, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1732 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1733 "error message was: %s\n",
1734 params.username, error->nt_string,
1736 error->display_string);
1739 if (WBC_ERROR_IS_OK(wbc_status)) {
1740 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1741 if (info && info->info && info->info->user_flags &
1742 NETLOGON_CACHED_ACCOUNT) {
1743 d_printf("user_flgs: "
1744 "NETLOGON_CACHED_ACCOUNT\n");
1750 for (i=0; i < info->num_blobs; i++) {
1751 if (strequal(info->blobs[i].name,
1753 d_printf("credentials were put "
1756 info->blobs[i].blob.data);
1761 d_printf("no credentials cached\n");
1766 wbcFreeMemory(params.blobs);
1768 return WBC_ERROR_IS_OK(wbc_status);
1771 /* Authenticate a user with a plaintext password */
1773 static bool wbinfo_auth(char *username)
1775 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1778 char *password = NULL;
1780 TALLOC_CTX *frame = talloc_tos();
1782 if ((s = talloc_strdup(frame, username)) == NULL) {
1786 if ((p = strchr(s, '%')) != NULL) {
1789 password = talloc_strdup(frame, p);
1791 password = wbinfo_prompt_pass(frame, NULL, username);
1796 wbc_status = wbcAuthenticateUser(name, password);
1798 d_printf("plaintext password authentication %s\n",
1799 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1802 if (response.data.auth.nt_status)
1804 "error code was %s (0x%x)\nerror message was: %s\n",
1805 response.data.auth.nt_status_string,
1806 response.data.auth.nt_status,
1807 response.data.auth.error_string);
1810 return WBC_ERROR_IS_OK(wbc_status);
1813 /* Authenticate a user with a challenge/response */
1815 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1817 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1818 struct wbcAuthUserParams params;
1819 struct wbcAuthUserInfo *info = NULL;
1820 struct wbcAuthErrorInfo *err = NULL;
1821 DATA_BLOB lm = data_blob_null;
1822 DATA_BLOB nt = data_blob_null;
1824 fstring name_domain;
1827 TALLOC_CTX *frame = talloc_tos();
1829 p = strchr(username, '%');
1833 pass = talloc_strdup(frame, p + 1);
1835 pass = wbinfo_prompt_pass(frame, NULL, username);
1838 parse_wbinfo_domain_user(username, name_domain, name_user);
1840 params.account_name = name_user;
1841 params.domain_name = name_domain;
1842 params.workstation_name = NULL;
1845 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1846 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1848 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1850 generate_random_buffer(params.password.response.challenge, 8);
1853 DATA_BLOB server_chal;
1854 DATA_BLOB names_blob;
1855 const char *netbios_name = NULL;
1856 const char *domain = NULL;
1858 netbios_name = get_winbind_netbios_name(),
1859 domain = get_winbind_domain();
1860 if (domain == NULL) {
1861 d_fprintf(stderr, "Failed to get domain from winbindd\n");
1865 server_chal = data_blob(params.password.response.challenge, 8);
1867 /* Pretend this is a login to 'us', for blob purposes */
1868 names_blob = NTLMv2_generate_names_blob(NULL,
1873 !SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1876 &lm, &nt, NULL, NULL)) {
1877 data_blob_free(&names_blob);
1878 data_blob_free(&server_chal);
1882 data_blob_free(&names_blob);
1883 data_blob_free(&server_chal);
1888 lm = data_blob(NULL, 24);
1889 ok = SMBencrypt(pass,
1890 params.password.response.challenge,
1893 data_blob_free(&lm);
1896 nt = data_blob(NULL, 24);
1897 SMBNTencrypt(pass, params.password.response.challenge,
1901 params.password.response.nt_length = nt.length;
1902 params.password.response.nt_data = nt.data;
1903 params.password.response.lm_length = lm.length;
1904 params.password.response.lm_data = lm.data;
1906 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1908 /* Display response */
1910 d_printf("challenge/response password authentication %s\n",
1911 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1913 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1915 "wbcAuthenticateUserEx(%s%c%s): error code was "
1916 "%s (0x%x, authoritative=%"PRIu8")\n"
1917 "error message was: %s\n",
1919 winbind_separator(),
1924 err->display_string);
1926 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1927 wbcFreeMemory(info);
1930 data_blob_free(&nt);
1931 data_blob_free(&lm);
1933 return WBC_ERROR_IS_OK(wbc_status);
1936 /* Authenticate a user with a plaintext password */
1938 static bool wbinfo_pam_logon(char *username, bool verbose)
1940 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1941 struct wbcLogonUserParams params;
1942 struct wbcLogonUserInfo *info = NULL;
1943 struct wbcAuthErrorInfo *error = NULL;
1946 TALLOC_CTX *frame = talloc_tos();
1950 ZERO_STRUCT(params);
1952 if ((s = talloc_strdup(frame, username)) == NULL) {
1956 if ((p = strchr(s, '%')) != NULL) {
1959 params.password = talloc_strdup(frame, p);
1961 params.password = wbinfo_prompt_pass(frame, NULL, username);
1963 params.username = s;
1965 flags = WBFLAG_PAM_CACHED_LOGIN;
1967 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1969 (uint8_t *)&flags, sizeof(flags));
1970 if (!WBC_ERROR_IS_OK(wbc_status)) {
1971 d_printf("wbcAddNamedBlob failed: %s\n",
1972 wbcErrorString(wbc_status));
1978 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1980 (uint8_t *)&uid, sizeof(uid));
1981 if (!WBC_ERROR_IS_OK(wbc_status)) {
1982 d_printf("wbcAddNamedBlob failed: %s\n",
1983 wbcErrorString(wbc_status));
1987 wbc_status = wbcLogonUser(¶ms, &info, &error, NULL);
1989 if (verbose && (info != NULL)) {
1990 struct wbcAuthUserInfo *i = info->info;
1993 if (i->account_name != NULL) {
1994 d_printf("account_name: %s\n", i->account_name);
1996 if (i->user_principal != NULL) {
1997 d_printf("user_principal: %s\n", i->user_principal);
1999 if (i->full_name != NULL) {
2000 d_printf("full_name: %s\n", i->full_name);
2002 if (i->domain_name != NULL) {
2003 d_printf("domain_name: %s\n", i->domain_name);
2005 if (i->dns_domain_name != NULL) {
2006 d_printf("dns_domain_name: %s\n", i->dns_domain_name);
2008 if (i->logon_server != NULL) {
2009 d_printf("logon_server: %s\n", i->logon_server);
2011 if (i->logon_script != NULL) {
2012 d_printf("logon_script: %s\n", i->logon_script);
2014 if (i->profile_path != NULL) {
2015 d_printf("profile_path: %s\n", i->profile_path);
2017 if (i->home_directory != NULL) {
2018 d_printf("home_directory: %s\n", i->home_directory);
2020 if (i->home_drive != NULL) {
2021 d_printf("home_drive: %s\n", i->home_drive);
2026 for (j=0; j<i->num_sids; j++) {
2027 char buf[WBC_SID_STRING_BUFLEN];
2028 wbcSidToStringBuf(&i->sids[j].sid, buf, sizeof(buf));
2029 d_printf(" %s", buf);
2033 wbcFreeMemory(info);
2037 wbcFreeMemory(params.blobs);
2039 d_printf("plaintext password authentication %s\n",
2040 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2042 if (!WBC_ERROR_IS_OK(wbc_status) && (error != NULL)) {
2044 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2045 "error message was: %s\n",
2048 (int)error->nt_status,
2049 error->display_string);
2050 wbcFreeMemory(error);
2052 return WBC_ERROR_IS_OK(wbc_status);
2055 /* Save creds with winbind */
2057 static bool wbinfo_ccache_save(char *username)
2059 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2062 char *password = NULL;
2064 TALLOC_CTX *frame = talloc_stackframe();
2066 s = talloc_strdup(frame, username);
2075 password = talloc_strdup(frame, p);
2077 password = wbinfo_prompt_pass(frame, NULL, username);
2082 wbc_status = wbcCredentialSave(name, password);
2084 d_printf("saving creds %s\n",
2085 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2089 return WBC_ERROR_IS_OK(wbc_status);
2092 #ifdef WITH_FAKE_KASERVER
2093 /* Authenticate a user with a plaintext password and set a token */
2095 static bool wbinfo_klog(char *username)
2097 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2098 struct winbindd_request request;
2099 struct winbindd_response response;
2102 /* Send off request */
2104 ZERO_STRUCT(request);
2105 ZERO_STRUCT(response);
2107 p = strchr(username, '%');
2111 fstrcpy(request.data.auth.user, username);
2112 fstrcpy(request.data.auth.pass, p + 1);
2115 fstrcpy(request.data.auth.user, username);
2116 (void) samba_getpass("Password: ",
2117 request.data.auth.pass,
2118 sizeof(request.data.auth.pass),
2122 request.flags |= WBFLAG_PAM_AFS_TOKEN;
2124 wbc_status = wbcRequestResponse(NULL, WINBINDD_PAM_AUTH,
2125 &request, &response);
2127 /* Display response */
2129 d_printf("plaintext password authentication %s\n",
2130 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2132 if (response.data.auth.nt_status)
2134 "error code was %s (0x%x)\nerror message was: %s\n",
2135 response.data.auth.nt_status_string,
2136 response.data.auth.nt_status,
2137 response.data.auth.error_string);
2139 if (!WBC_ERROR_IS_OK(wbc_status))
2142 if (response.extra_data.data == NULL) {
2143 d_fprintf(stderr, "Did not get token data\n");
2147 if (!afs_settoken_str((char *)response.extra_data.data)) {
2148 winbindd_free_response(&response);
2149 d_fprintf(stderr, "Could not set token\n");
2153 winbindd_free_response(&response);
2154 d_printf("Successfully created AFS token\n");
2158 static bool wbinfo_klog(char *username)
2160 d_fprintf(stderr, "No AFS support compiled in.\n");
2165 /* Print domain users */
2167 static bool print_domain_users(const char *domain)
2169 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2171 uint32_t num_users = 0;
2172 const char **users = NULL;
2174 /* Send request to winbind daemon */
2176 if (domain == NULL) {
2177 domain = get_winbind_domain();
2179 /* '.' is the special sign for our own domain */
2180 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
2181 domain = get_winbind_domain();
2182 /* '*' is the special sign for all domains */
2183 } else if (strcmp(domain, "*") == 0) {
2188 wbc_status = wbcListUsers(domain, &num_users, &users);
2189 if (!WBC_ERROR_IS_OK(wbc_status)) {
2193 for (i=0; i < num_users; i++) {
2194 d_printf("%s\n", users[i]);
2197 wbcFreeMemory(users);
2202 /* Print domain groups */
2204 static bool print_domain_groups(const char *domain)
2206 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2208 uint32_t num_groups = 0;
2209 const char **groups = NULL;
2211 /* Send request to winbind daemon */
2213 if (domain == NULL) {
2214 domain = get_winbind_domain();
2216 /* '.' is the special sign for our own domain */
2217 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
2218 domain = get_winbind_domain();
2219 /* '*' is the special sign for all domains */
2220 } else if (strcmp(domain, "*") == 0) {
2225 wbc_status = wbcListGroups(domain, &num_groups, &groups);
2226 if (!WBC_ERROR_IS_OK(wbc_status)) {
2227 d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
2228 wbcErrorString(wbc_status));
2232 for (i=0; i < num_groups; i++) {
2233 d_printf("%s\n", groups[i]);
2236 wbcFreeMemory(groups);
2241 /* Set the authorised user for winbindd access in secrets.tdb */
2243 static bool wbinfo_set_auth_user(char *username)
2245 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
2246 "See 'net help setauthuser' for details.\n");
2250 static void wbinfo_get_auth_user(void)
2252 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
2253 "See 'net help getauthuser' for details.\n");
2256 static bool wbinfo_ping(void)
2260 wbc_status = wbcPing();
2262 /* Display response */
2264 d_printf("Ping to winbindd %s\n",
2265 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2267 return WBC_ERROR_IS_OK(wbc_status);
2270 static bool wbinfo_change_user_password(const char *username)
2273 char *old_password = NULL;
2274 char *new_password = NULL;
2275 TALLOC_CTX *frame = talloc_tos();
2277 old_password = wbinfo_prompt_pass(frame, "old", username);
2278 new_password = wbinfo_prompt_pass(frame, "new", username);
2280 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
2282 /* Display response */
2284 d_printf("Password change for user %s %s\n", username,
2285 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2287 return WBC_ERROR_IS_OK(wbc_status);
2293 OPT_SET_AUTH_USER = 1000,
2306 OPT_SET_UID_MAPPING,
2307 OPT_SET_GID_MAPPING,
2308 OPT_REMOVE_UID_MAPPING,
2309 OPT_REMOVE_GID_MAPPING,
2313 OPT_LIST_ALL_DOMAINS,
2314 OPT_LIST_OWN_DOMAIN,
2321 OPT_CHANGE_USER_PASSWORD,
2323 OPT_SID_TO_FULLNAME,
2332 OPT_CHANGE_SECRET_AT
2335 int main(int argc, const char **argv, char **envp)
2338 TALLOC_CTX *frame = talloc_stackframe();
2340 static char *string_arg;
2341 char *string_subarg = NULL;
2342 static char *opt_domain_name;
2344 int int_subarg = -1;
2346 bool verbose = false;
2347 bool use_ntlmv2 = true;
2348 bool use_lanman = false;
2349 char *logoff_user = getenv("USER");
2350 int logoff_uid = geteuid();
2351 const char *opt_krb5ccname = "FILE";
2353 struct poptOption long_options[] = {
2356 /* longName, shortName, argInfo, argPtr, value, descrip,
2360 .longName = "domain-users",
2362 .argInfo = POPT_ARG_NONE,
2364 .descrip = "Lists all domain users",
2365 .argDescrip = "domain"
2368 .longName = "domain-groups",
2370 .argInfo = POPT_ARG_NONE,
2372 .descrip = "Lists all domain groups",
2373 .argDescrip = "domain"
2376 .longName = "WINS-by-name",
2378 .argInfo = POPT_ARG_STRING,
2381 .descrip = "Converts NetBIOS name to IP",
2382 .argDescrip = "NETBIOS-NAME"
2385 .longName = "WINS-by-ip",
2387 .argInfo = POPT_ARG_STRING,
2390 .descrip = "Converts IP address to NetBIOS name",
2394 .longName = "name-to-sid",
2396 .argInfo = POPT_ARG_STRING,
2399 .descrip = "Converts name to sid",
2400 .argDescrip = "NAME"
2403 .longName = "sid-to-name",
2405 .argInfo = POPT_ARG_STRING,
2408 .descrip = "Converts sid to name",
2412 .longName = "sid-to-fullname",
2413 .argInfo = POPT_ARG_STRING,
2415 .val = OPT_SID_TO_FULLNAME,
2416 .descrip = "Converts sid to fullname",
2420 .longName = "lookup-rids",
2422 .argInfo = POPT_ARG_STRING,
2425 .descrip = "Converts RIDs to names",
2426 .argDescrip = "RIDs"
2429 .longName = "lookup-sids",
2430 .argInfo = POPT_ARG_STRING,
2432 .val = OPT_LOOKUP_SIDS,
2433 .descrip = "Converts SIDs to types and names",
2434 .argDescrip = "Sid-List"
2437 .longName = "uid-to-sid",
2439 .argInfo = POPT_ARG_INT,
2442 .descrip = "Converts uid to sid",
2446 .longName = "gid-to-sid",
2448 .argInfo = POPT_ARG_INT,
2451 .descrip = "Converts gid to sid",
2455 .longName = "sid-to-uid",
2457 .argInfo = POPT_ARG_STRING,
2460 .descrip = "Converts sid to uid",
2464 .longName = "sid-to-gid",
2466 .argInfo = POPT_ARG_STRING,
2469 .descrip = "Converts sid to gid",
2473 .longName = "allocate-uid",
2474 .argInfo = POPT_ARG_NONE,
2475 .val = OPT_ALLOCATE_UID,
2476 .descrip = "Get a new UID out of idmap"
2479 .longName = "allocate-gid",
2480 .argInfo = POPT_ARG_NONE,
2481 .val = OPT_ALLOCATE_GID,
2482 .descrip = "Get a new GID out of idmap"
2485 .longName = "set-uid-mapping",
2486 .argInfo = POPT_ARG_STRING,
2488 .val = OPT_SET_UID_MAPPING,
2489 .descrip = "Create or modify uid to sid mapping in "
2491 .argDescrip = "UID,SID"
2494 .longName = "set-gid-mapping",
2495 .argInfo = POPT_ARG_STRING,
2497 .val = OPT_SET_GID_MAPPING,
2498 .descrip = "Create or modify gid to sid mapping in "
2500 .argDescrip = "GID,SID"
2503 .longName = "remove-uid-mapping",
2504 .argInfo = POPT_ARG_STRING,
2506 .val = OPT_REMOVE_UID_MAPPING,
2507 .descrip = "Remove uid to sid mapping in idmap",
2508 .argDescrip = "UID,SID"
2511 .longName = "remove-gid-mapping",
2512 .argInfo = POPT_ARG_STRING,
2514 .val = OPT_REMOVE_GID_MAPPING,
2515 .descrip = "Remove gid to sid mapping in idmap",
2516 .argDescrip = "GID,SID",
2519 .longName = "sids-to-unix-ids",
2520 .argInfo = POPT_ARG_STRING,
2522 .val = OPT_SIDS_TO_XIDS,
2523 .descrip = "Translate SIDs to Unix IDs",
2524 .argDescrip = "Sid-List",
2527 .longName = "unix-ids-to-sids",
2528 .argInfo = POPT_ARG_STRING,
2530 .val = OPT_XIDS_TO_SIDS,
2531 .descrip = "Translate Unix IDs to SIDs",
2532 .argDescrip = "ID-List (u<num> g<num>)",
2535 .longName = "check-secret",
2537 .argInfo = POPT_ARG_NONE,
2539 .descrip = "Check shared secret",
2542 .longName = "change-secret",
2544 .argInfo = POPT_ARG_NONE,
2546 .descrip = "Change shared secret",
2549 .longName = "change-secret-at",
2551 .argInfo = POPT_ARG_STRING,
2553 .val = OPT_CHANGE_SECRET_AT,
2554 .descrip = "Change shared secret at Domain Controller" },
2556 .longName = "ping-dc",
2558 .argInfo = POPT_ARG_NONE,
2560 .descrip = "Check the NETLOGON connection",
2563 .longName = "trusted-domains",
2565 .argInfo = POPT_ARG_NONE,
2567 .descrip = "List trusted domains",
2570 .longName = "all-domains",
2571 .argInfo = POPT_ARG_NONE,
2572 .val = OPT_LIST_ALL_DOMAINS,
2573 .descrip = "List all domains (trusted and own "
2577 .longName = "own-domain",
2578 .argInfo = POPT_ARG_NONE,
2579 .val = OPT_LIST_OWN_DOMAIN,
2580 .descrip = "List own domain",
2583 .longName = "sequence",
2584 .argInfo = POPT_ARG_NONE,
2585 .val = OPT_SEQUENCE,
2586 .descrip = "Deprecated command, see --online-status",
2589 .longName = "online-status",
2590 .argInfo = POPT_ARG_NONE,
2591 .val = OPT_ONLINESTATUS,
2592 .descrip = "Show whether domains maintain an active "
2596 .longName = "domain-info",
2598 .argInfo = POPT_ARG_STRING,
2601 .descrip = "Show most of the info we have about the "
2605 .longName = "user-info",
2607 .argInfo = POPT_ARG_STRING,
2610 .descrip = "Get user info",
2611 .argDescrip = "USER",
2614 .longName = "uid-info",
2615 .argInfo = POPT_ARG_INT,
2617 .val = OPT_UID_INFO,
2618 .descrip = "Get user info from uid",
2619 .argDescrip = "UID",
2622 .longName = "group-info",
2623 .argInfo = POPT_ARG_STRING,
2625 .val = OPT_GROUP_INFO,
2626 .descrip = "Get group info",
2627 .argDescrip = "GROUP",
2630 .longName = "user-sidinfo",
2631 .argInfo = POPT_ARG_STRING,
2633 .val = OPT_USER_SIDINFO,
2634 .descrip = "Get user info from sid",
2635 .argDescrip = "SID",
2638 .longName = "gid-info",
2639 .argInfo = POPT_ARG_INT,
2641 .val = OPT_GID_INFO,
2642 .descrip = "Get group info from gid",
2643 .argDescrip = "GID",
2646 .longName = "user-groups",
2648 .argInfo = POPT_ARG_STRING,
2651 .descrip = "Get user groups",
2652 .argDescrip = "USER",
2655 .longName = "user-domgroups",
2656 .argInfo = POPT_ARG_STRING,
2658 .val = OPT_USERDOMGROUPS,
2659 .descrip = "Get user domain groups",
2660 .argDescrip = "SID",
2663 .longName = "sid-aliases",
2664 .argInfo = POPT_ARG_STRING,
2666 .val = OPT_SIDALIASES,
2667 .descrip = "Get sid aliases",
2668 .argDescrip = "SID",
2671 .longName = "user-sids",
2672 .argInfo = POPT_ARG_STRING,
2674 .val = OPT_USERSIDS,
2675 .descrip = "Get user group sids for user SID",
2676 .argDescrip = "SID",
2679 .longName = "authenticate",
2681 .argInfo = POPT_ARG_STRING,
2684 .descrip = "authenticate user",
2685 .argDescrip = "user%password",
2688 .longName = "pam-logon",
2689 .argInfo = POPT_ARG_STRING,
2691 .val = OPT_PAM_LOGON,
2692 .descrip = "do a pam logon equivalent",
2693 .argDescrip = "user%password",
2696 .longName = "logoff",
2697 .argInfo = POPT_ARG_NONE,
2699 .descrip = "log off user",
2700 .argDescrip = "uid",
2703 .longName = "logoff-user",
2704 .argInfo = POPT_ARG_STRING,
2705 .arg = &logoff_user,
2706 .val = OPT_LOGOFF_USER,
2707 .descrip = "username to log off"
2710 .longName = "logoff-uid",
2711 .argInfo = POPT_ARG_INT,
2713 .val = OPT_LOGOFF_UID,
2714 .descrip = "uid to log off",
2717 .longName = "set-auth-user",
2718 .argInfo = POPT_ARG_STRING,
2720 .val = OPT_SET_AUTH_USER,
2721 .descrip = "Store user and password used by "
2722 "winbindd (root only)",
2723 .argDescrip = "user%password",
2726 .longName = "ccache-save",
2728 .argInfo = POPT_ARG_STRING,
2730 .val = OPT_CCACHE_SAVE,
2731 .descrip = "Store user and password for ccache "
2733 .argDescrip = "user%password",
2736 .longName = "getdcname",
2737 .argInfo = POPT_ARG_STRING,
2739 .val = OPT_GETDCNAME,
2740 .descrip = "Get a DC name for a foreign domain",
2741 .argDescrip = "domainname",
2744 .longName = "dsgetdcname",
2745 .argInfo = POPT_ARG_STRING,
2747 .val = OPT_DSGETDCNAME,
2748 .descrip = "Find a DC for a domain",
2749 .argDescrip = "domainname",
2752 .longName = "dc-info",
2753 .argInfo = POPT_ARG_STRING,
2756 .descrip = "Find the currently known DCs",
2757 .argDescrip = "domainname",
2760 .longName = "get-auth-user",
2761 .argInfo = POPT_ARG_NONE,
2762 .val = OPT_GET_AUTH_USER,
2763 .descrip = "Retrieve user and password used by "
2764 "winbindd (root only)",
2769 .argInfo = POPT_ARG_NONE,
2772 .descrip = "Ping winbindd to see if it is alive",
2775 .longName = "domain",
2777 .argInfo = POPT_ARG_STRING,
2778 .arg = &opt_domain_name,
2779 .val = OPT_DOMAIN_NAME,
2780 .descrip = "Define to the domain to restrict "
2782 .argDescrip = "domain",
2784 #ifdef WITH_FAKE_KASERVER
2788 .argInfo = POPT_ARG_STRING,
2791 .descrip = "set an AFS token from winbind",
2792 .argDescrip = "user%password",
2797 .longName = "krb5auth",
2799 .argInfo = POPT_ARG_STRING,
2802 .descrip = "authenticate user using Kerberos",
2803 .argDescrip = "user%password",
2805 /* destroys wbinfo --help output */
2806 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2809 .longName = "krb5ccname",
2810 .argInfo = POPT_ARG_STRING,
2811 .arg = &opt_krb5ccname,
2812 .val = OPT_KRB5CCNAME,
2813 .descrip = "authenticate user using Kerberos and "
2814 "specific credential cache type",
2815 .argDescrip = "krb5ccname",
2819 .longName = "separator",
2820 .argInfo = POPT_ARG_NONE,
2821 .val = OPT_SEPARATOR,
2822 .descrip = "Get the active winbind separator",
2825 .longName = "verbose",
2826 .argInfo = POPT_ARG_NONE,
2828 .descrip = "Print additional information per command",
2831 .longName = "change-user-password",
2832 .argInfo = POPT_ARG_STRING,
2834 .val = OPT_CHANGE_USER_PASSWORD,
2835 .descrip = "Change the password for a user",
2838 .longName = "ntlmv1",
2839 .argInfo = POPT_ARG_NONE,
2841 .descrip = "Use NTLMv1 cryptography for user authentication",
2844 .longName = "ntlmv2",
2845 .argInfo = POPT_ARG_NONE,
2847 .descrip = "Use NTLMv2 cryptography for user authentication",
2850 .longName = "lanman",
2851 .argInfo = POPT_ARG_NONE,
2853 .descrip = "Use lanman cryptography for user authentication",
2859 /* Samba client initialisation */
2865 pc = samba_popt_get_context(getprogname(),
2871 DBG_ERR("Failed to setup popt context!\n");
2875 /* Parse command line options */
2878 poptPrintHelp(pc, stderr, 0);
2882 while((opt = poptGetNextOpt(pc)) != -1) {
2883 /* get the generic configuration parameters like --domain */
2897 poptFreeContext(pc);
2899 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
2900 POPT_CONTEXT_KEEP_FIRST);
2902 while((opt = poptGetNextOpt(pc)) != -1) {
2905 if (!print_domain_users(opt_domain_name)) {
2907 "Error looking up domain users\n");
2912 if (!print_domain_groups(opt_domain_name)) {
2914 "Error looking up domain groups\n");
2919 if (!wbinfo_lookupsid(string_arg)) {
2921 "Could not lookup sid %s\n",
2926 case OPT_SID_TO_FULLNAME:
2927 if (!wbinfo_lookupsid_fullname(string_arg)) {
2928 d_fprintf(stderr, "Could not lookup sid %s\n",
2934 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
2935 d_fprintf(stderr, "Could not lookup RIDs %s\n",
2940 case OPT_LOOKUP_SIDS:
2941 if (!wbinfo_lookup_sids(string_arg)) {
2942 d_fprintf(stderr, "Could not lookup SIDs %s\n",
2948 if (!wbinfo_lookupname(string_arg)) {
2949 d_fprintf(stderr, "Could not lookup name %s\n",
2955 if (!wbinfo_wins_byname(string_arg)) {
2957 "Could not lookup WINS by name %s\n",
2963 if (!wbinfo_wins_byip(string_arg)) {
2965 "Could not lookup WINS by IP %s\n",
2971 if (!wbinfo_uid_to_sid(int_arg)) {
2973 "Could not convert uid %d to sid\n",
2979 if (!wbinfo_gid_to_sid(int_arg)) {
2981 "Could not convert gid %d to sid\n",
2987 if (!wbinfo_sid_to_uid(string_arg)) {
2989 "Could not convert sid %s to uid\n",
2995 if (!wbinfo_sid_to_gid(string_arg)) {
2997 "Could not convert sid %s to gid\n",
3002 case OPT_ALLOCATE_UID:
3003 if (!wbinfo_allocate_uid()) {
3004 d_fprintf(stderr, "Could not allocate a uid\n");
3008 case OPT_ALLOCATE_GID:
3009 if (!wbinfo_allocate_gid()) {
3010 d_fprintf(stderr, "Could not allocate a gid\n");
3014 case OPT_SET_UID_MAPPING:
3015 if (!parse_mapping_arg(string_arg, &int_subarg,
3017 !wbinfo_set_uid_mapping(int_subarg, string_subarg))
3019 d_fprintf(stderr, "Could not create or modify "
3020 "uid to sid mapping\n");
3024 case OPT_SET_GID_MAPPING:
3025 if (!parse_mapping_arg(string_arg, &int_subarg,
3027 !wbinfo_set_gid_mapping(int_subarg, string_subarg))
3029 d_fprintf(stderr, "Could not create or modify "
3030 "gid to sid mapping\n");
3034 case OPT_REMOVE_UID_MAPPING:
3035 if (!parse_mapping_arg(string_arg, &int_subarg,
3037 !wbinfo_remove_uid_mapping(int_subarg,
3040 d_fprintf(stderr, "Could not remove uid to sid "
3045 case OPT_REMOVE_GID_MAPPING:
3046 if (!parse_mapping_arg(string_arg, &int_subarg,
3048 !wbinfo_remove_gid_mapping(int_subarg,
3051 d_fprintf(stderr, "Could not remove gid to sid "
3056 case OPT_SIDS_TO_XIDS:
3057 if (!wbinfo_sids_to_unix_ids(string_arg)) {
3058 d_fprintf(stderr, "wbinfo_sids_to_unix_ids "
3063 case OPT_XIDS_TO_SIDS:
3064 if (!wbinfo_xids_to_sids(string_arg)) {
3065 d_fprintf(stderr, "wbinfo_xids_to_sids "
3071 if (!wbinfo_check_secret(opt_domain_name)) {
3072 d_fprintf(stderr, "Could not check secret\n");
3077 if (!wbinfo_change_secret(opt_domain_name)) {
3078 d_fprintf(stderr, "Could not change secret\n");
3082 case OPT_CHANGE_SECRET_AT:
3083 if (!wbinfo_change_secret_at(opt_domain_name, string_arg)) {
3084 d_fprintf(stderr, "Could not change secret\n");
3089 if (!wbinfo_ping_dc(opt_domain_name)) {
3094 if (!wbinfo_list_domains(false, verbose)) {
3096 "Could not list trusted domains\n");
3101 if (!wbinfo_show_sequence(opt_domain_name)) {
3103 "Could not show sequence numbers\n");
3107 case OPT_ONLINESTATUS:
3108 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
3110 "Could not show online-status\n");
3115 if (!wbinfo_domain_info(string_arg)) {
3117 "Could not get domain info\n");
3122 if (!wbinfo_get_userinfo(string_arg)) {
3124 "Could not get info for user %s\n",
3129 case OPT_USER_SIDINFO:
3130 if ( !wbinfo_get_user_sidinfo(string_arg)) {
3132 "Could not get info for user "
3133 "sid %s\n", string_arg);
3138 if ( !wbinfo_get_uidinfo(int_arg)) {
3139 d_fprintf(stderr, "Could not get info for uid "
3144 case OPT_GROUP_INFO:
3145 if ( !wbinfo_get_groupinfo(string_arg)) {
3146 d_fprintf(stderr, "Could not get info for "
3147 "group %s\n", string_arg);
3152 if ( !wbinfo_get_gidinfo(int_arg)) {
3153 d_fprintf(stderr, "Could not get info for gid "
3159 if (!wbinfo_get_usergroups(string_arg)) {
3161 "Could not get groups for user %s\n",
3167 if (!wbinfo_get_usersids(string_arg)) {
3168 d_fprintf(stderr, "Could not get group SIDs "
3169 "for user SID %s\n",
3174 case OPT_USERDOMGROUPS:
3175 if (!wbinfo_get_userdomgroups(string_arg)) {
3176 d_fprintf(stderr, "Could not get user's domain "
3177 "groups for user SID %s\n",
3182 case OPT_SIDALIASES:
3183 if (!wbinfo_get_sidaliases(opt_domain_name,
3185 d_fprintf(stderr, "Could not get sid aliases "
3186 "for user SID %s\n", string_arg);
3191 bool got_error = false;
3193 if (!wbinfo_auth(string_arg)) {
3195 "Could not authenticate user "
3196 "%s with plaintext "
3197 "password\n", string_arg);
3201 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
3204 "Could not authenticate user "
3205 "%s with challenge/response\n",
3215 if (!wbinfo_pam_logon(string_arg, verbose)) {
3216 d_fprintf(stderr, "pam_logon failed for %s\n",
3225 wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
3227 d_printf("Logoff %s (%d): %s\n", logoff_user,
3228 logoff_uid, wbcErrorString(wbc_status));
3232 uint32_t flags = WBFLAG_PAM_KRB5 |
3233 WBFLAG_PAM_CACHED_LOGIN |
3234 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
3235 WBFLAG_PAM_INFO3_TEXT |
3236 WBFLAG_PAM_CONTACT_TRUSTDOM;
3238 if (!wbinfo_auth_krb5(string_arg, opt_krb5ccname,
3241 "Could not authenticate user "
3242 "[%s] with Kerberos "
3243 "(ccache: %s)\n", string_arg,
3250 if (!wbinfo_klog(string_arg)) {
3251 d_fprintf(stderr, "Could not klog user\n");
3256 if (!wbinfo_ping()) {
3257 d_fprintf(stderr, "could not ping winbindd!\n");
3261 case OPT_SET_AUTH_USER:
3262 if (!wbinfo_set_auth_user(string_arg)) {
3266 case OPT_GET_AUTH_USER:
3267 wbinfo_get_auth_user();
3270 case OPT_CCACHE_SAVE:
3271 if (!wbinfo_ccache_save(string_arg)) {
3276 if (!wbinfo_getdcname(string_arg)) {
3280 case OPT_DSGETDCNAME:
3281 if (!wbinfo_dsgetdcname(string_arg, 0)) {
3286 if (!wbinfo_dc_info(string_arg)) {
3290 case OPT_SEPARATOR: {
3291 const char sep = winbind_separator();
3295 d_printf("%c\n", sep);
3298 case OPT_LIST_ALL_DOMAINS:
3299 if (!wbinfo_list_domains(true, verbose)) {
3303 case OPT_LIST_OWN_DOMAIN:
3304 if (!wbinfo_list_own_domain()) {
3308 case OPT_CHANGE_USER_PASSWORD:
3309 if (!wbinfo_change_user_password(string_arg)) {
3311 "Could not change user password "
3312 "for user %s\n", string_arg);
3317 /* generic configuration options */
3318 case OPT_DOMAIN_NAME:
3323 case OPT_LOGOFF_USER:
3324 case OPT_LOGOFF_UID:
3325 case OPT_KRB5CCNAME:
3328 d_fprintf(stderr, "Invalid option\n");
3329 poptPrintHelp(pc, stderr, 0);
3341 poptFreeContext(pc);