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 "winbind_client.h"
26 #include "libwbclient/wbclient.h"
27 #include "../libcli/auth/libcli_auth.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "lib/afs/afs_settoken.h"
30 #include "lib/util/smb_strtox.h"
31 #include "lib/util/string_wrappers.h"
35 #define DBGC_CLASS DBGC_WINBIND
38 static struct wbcInterfaceDetails *init_interface_details(void)
40 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
41 static struct wbcInterfaceDetails *details;
47 wbc_status = wbcInterfaceDetails(&details);
48 if (!WBC_ERROR_IS_OK(wbc_status)) {
49 d_fprintf(stderr, "could not obtain winbind interface "
50 "details: %s\n", wbcErrorString(wbc_status));
56 static char winbind_separator(void)
58 struct wbcInterfaceDetails *details;
65 details = init_interface_details();
68 d_fprintf(stderr, "could not obtain winbind separator!\n");
72 sep = details->winbind_separator;
76 d_fprintf(stderr, "winbind separator was NULL!\n");
83 static const char *get_winbind_domain(void)
85 static struct wbcInterfaceDetails *details;
87 details = init_interface_details();
90 d_fprintf(stderr, "could not obtain winbind domain name!\n");
94 return details->netbios_domain;
97 static const char *get_winbind_netbios_name(void)
99 static struct wbcInterfaceDetails *details;
101 details = init_interface_details();
104 d_fprintf(stderr, "could not obtain winbind netbios name!\n");
108 return details->netbios_name;
111 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
112 form DOMAIN/user into a domain and a user */
114 static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
118 char *p = strchr(domuser,winbind_separator());
121 /* Maybe it was a UPN? */
122 p = strchr(domuser, '@');
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;
141 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
142 * Return true if input was valid, false otherwise. */
143 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 = smb_strtoul(tmp, NULL, 10, &error, SMB_STR_FULL_STR_CONV);
166 /* pull pwent info for a given user */
168 static bool wbinfo_get_userinfo(char *user)
170 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
171 struct passwd *pwd = NULL;
173 wbc_status = wbcGetpwnam(user, &pwd);
174 if (!WBC_ERROR_IS_OK(wbc_status)) {
175 d_fprintf(stderr, "failed to call wbcGetpwnam: %s\n",
176 wbcErrorString(wbc_status));
180 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
183 (unsigned int)pwd->pw_uid,
184 (unsigned int)pwd->pw_gid,
194 /* pull pwent info for a given uid */
195 static bool wbinfo_get_uidinfo(int uid)
197 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
198 struct passwd *pwd = NULL;
200 wbc_status = wbcGetpwuid(uid, &pwd);
201 if (!WBC_ERROR_IS_OK(wbc_status)) {
202 d_fprintf(stderr, "failed to call wbcGetpwuid: %s\n",
203 wbcErrorString(wbc_status));
207 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
210 (unsigned int)pwd->pw_uid,
211 (unsigned int)pwd->pw_gid,
221 static bool wbinfo_get_user_sidinfo(const char *sid_str)
223 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
224 struct passwd *pwd = NULL;
225 struct wbcDomainSid sid;
227 wbc_status = wbcStringToSid(sid_str, &sid);
228 wbc_status = wbcGetpwsid(&sid, &pwd);
229 if (!WBC_ERROR_IS_OK(wbc_status)) {
230 d_fprintf(stderr, "failed to call wbcGetpwsid: %s\n",
231 wbcErrorString(wbc_status));
235 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
238 (unsigned int)pwd->pw_uid,
239 (unsigned int)pwd->pw_gid,
250 /* pull grent for a given group */
251 static bool wbinfo_get_groupinfo(const char *group)
253 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
257 wbc_status = wbcGetgrnam(group, &grp);
258 if (!WBC_ERROR_IS_OK(wbc_status)) {
259 d_fprintf(stderr, "failed to call wbcGetgrnam: %s\n",
260 wbcErrorString(wbc_status));
264 d_printf("%s:%s:%u:",
267 (unsigned int)grp->gr_gid);
270 while (*mem != NULL) {
271 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
281 /* pull grent for a given gid */
282 static bool wbinfo_get_gidinfo(int gid)
284 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
288 wbc_status = wbcGetgrgid(gid, &grp);
289 if (!WBC_ERROR_IS_OK(wbc_status)) {
290 d_fprintf(stderr, "failed to call wbcGetgrgid: %s\n",
291 wbcErrorString(wbc_status));
295 d_printf("%s:%s:%u:",
298 (unsigned int)grp->gr_gid);
301 while (*mem != NULL) {
302 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
312 /* List groups a user is a member of */
314 static bool wbinfo_get_usergroups(const char *user)
316 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
319 gid_t *groups = NULL;
323 wbc_status = wbcGetGroups(user, &num_groups, &groups);
324 if (!WBC_ERROR_IS_OK(wbc_status)) {
325 d_fprintf(stderr, "failed to call wbcGetGroups: %s\n",
326 wbcErrorString(wbc_status));
330 for (i = 0; i < num_groups; i++) {
331 d_printf("%d\n", (int)groups[i]);
334 wbcFreeMemory(groups);
340 /* List group SIDs a user SID is a member of */
341 static bool wbinfo_get_usersids(const char *user_sid_str)
343 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
346 struct wbcDomainSid user_sid, *sids = NULL;
350 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
351 if (!WBC_ERROR_IS_OK(wbc_status)) {
352 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
353 wbcErrorString(wbc_status));
357 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
358 if (!WBC_ERROR_IS_OK(wbc_status)) {
359 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
360 wbcErrorString(wbc_status));
364 for (i = 0; i < num_sids; i++) {
365 char str[WBC_SID_STRING_BUFLEN];
366 wbcSidToStringBuf(&sids[i], str, sizeof(str));
367 d_printf("%s\n", str);
375 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
377 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
380 struct wbcDomainSid user_sid, *sids = NULL;
384 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
385 if (!WBC_ERROR_IS_OK(wbc_status)) {
386 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
387 wbcErrorString(wbc_status));
391 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
392 if (!WBC_ERROR_IS_OK(wbc_status)) {
393 d_fprintf(stderr, "failed to call wbcLookupUserSids: %s\n",
394 wbcErrorString(wbc_status));
398 for (i = 0; i < num_sids; i++) {
399 char str[WBC_SID_STRING_BUFLEN];
400 wbcSidToStringBuf(&sids[i], str, sizeof(str));
401 d_printf("%s\n", str);
409 static bool wbinfo_get_sidaliases(const char *domain,
410 const char *user_sid_str)
412 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
413 struct wbcDomainInfo *dinfo = NULL;
415 struct wbcDomainSid user_sid;
416 uint32_t *alias_rids = NULL;
417 uint32_t num_alias_rids;
418 char domain_sid_str[WBC_SID_STRING_BUFLEN];
421 if ((domain == NULL) || (strequal(domain, ".")) ||
422 (domain[0] == '\0')) {
423 domain = get_winbind_domain();
428 wbc_status = wbcDomainInfo(domain, &dinfo);
429 if (!WBC_ERROR_IS_OK(wbc_status)) {
430 d_fprintf(stderr, "wbcDomainInfo(%s) failed: %s\n", domain,
431 wbcErrorString(wbc_status));
434 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
435 if (!WBC_ERROR_IS_OK(wbc_status)) {
439 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
440 &alias_rids, &num_alias_rids);
441 if (!WBC_ERROR_IS_OK(wbc_status)) {
445 wbcSidToStringBuf(&dinfo->sid, domain_sid_str, sizeof(domain_sid_str));
447 for (i = 0; i < num_alias_rids; i++) {
448 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
451 wbcFreeMemory(alias_rids);
454 wbcFreeMemory(dinfo);
455 return (WBC_ERR_SUCCESS == wbc_status);
459 /* Convert NetBIOS name to IP */
461 static bool wbinfo_wins_byname(const char *name)
463 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
466 wbc_status = wbcResolveWinsByName(name, &ip);
467 if (!WBC_ERROR_IS_OK(wbc_status)) {
468 d_fprintf(stderr, "failed to call wbcResolveWinsByName: %s\n",
469 wbcErrorString(wbc_status));
473 /* Display response */
475 d_printf("%s\n", ip);
482 /* Convert IP to NetBIOS name */
484 static bool wbinfo_wins_byip(const char *ip)
486 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
489 wbc_status = wbcResolveWinsByIP(ip, &name);
490 if (!WBC_ERROR_IS_OK(wbc_status)) {
491 d_fprintf(stderr, "failed to call wbcResolveWinsByIP: %s\n",
492 wbcErrorString(wbc_status));
496 /* Display response */
498 d_printf("%s\n", name);
505 /* List all/trusted domains */
507 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
509 struct wbcDomainInfo *domain_list = NULL;
511 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
512 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;
621 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
624 wbc_status = wbcListTrusts(&domain_list, &num_domains);
625 if (!WBC_ERROR_IS_OK(wbc_status)) {
626 d_fprintf(stderr, "failed to call wbcListTrusts: %s\n",
627 wbcErrorString(wbc_status));
631 for (i=0; i<num_domains; i++) {
635 if (!strequal(domain_list[i].short_name, domain)) {
640 is_offline = (domain_list[i].domain_flags &
641 WBC_DOMINFO_DOMAIN_OFFLINE);
643 d_printf("%s : %s\n",
644 domain_list[i].short_name,
645 is_offline ? "no active connection" : "active connection" );
648 wbcFreeMemory(domain_list);
654 /* Show domain info */
656 static bool wbinfo_domain_info(const char *domain)
658 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
659 struct wbcDomainInfo *dinfo = NULL;
660 char sid_str[WBC_SID_STRING_BUFLEN];
662 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
663 domain = get_winbind_domain();
668 wbc_status = wbcDomainInfo(domain, &dinfo);
669 if (!WBC_ERROR_IS_OK(wbc_status)) {
670 d_fprintf(stderr, "failed to call wbcDomainInfo: %s\n",
671 wbcErrorString(wbc_status));
675 wbcSidToStringBuf(&dinfo->sid, sid_str, sizeof(sid_str));
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(dinfo);
699 /* Get a foreign DC's name */
700 static bool wbinfo_getdcname(const char *domain_name)
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 if (winbindd_request_response(NULL, WINBINDD_GETDCNAME, &request,
713 &response) != NSS_STATUS_SUCCESS) {
714 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
718 /* Display response */
720 d_printf("%s\n", response.data.dc_name);
726 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
728 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
729 struct wbcDomainControllerInfoEx *dc_info;
732 wbc_status = wbcLookupDomainControllerEx(domain_name, NULL, NULL,
733 flags | DS_DIRECTORY_SERVICE_REQUIRED,
735 if (!WBC_ERROR_IS_OK(wbc_status)) {
736 printf("Could not find dc for %s\n", domain_name);
740 wbcGuidToString(dc_info->domain_guid, &str);
742 d_printf("%s\n", dc_info->dc_unc);
743 d_printf("%s\n", dc_info->dc_address);
744 d_printf("%d\n", dc_info->dc_address_type);
745 d_printf("%s\n", str);
746 d_printf("%s\n", dc_info->domain_name);
747 d_printf("%s\n", dc_info->forest_name);
748 d_printf("0x%08x\n", dc_info->dc_flags);
749 d_printf("%s\n", dc_info->dc_site_name);
750 d_printf("%s\n", dc_info->client_site_name);
753 wbcFreeMemory(dc_info);
758 /* Check trust account password */
760 static bool wbinfo_check_secret(const char *domain)
762 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
763 struct wbcAuthErrorInfo *error = NULL;
764 const char *domain_name;
767 domain_name = domain;
769 domain_name = get_winbind_domain();
772 wbc_status = wbcCheckTrustCredentials(domain_name, &error);
774 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
776 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
778 if (wbc_status == WBC_ERR_AUTH_ERROR) {
779 d_fprintf(stderr, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
780 domain_name, error->nt_string, error->nt_status);
781 wbcFreeMemory(error);
783 if (!WBC_ERROR_IS_OK(wbc_status)) {
784 d_fprintf(stderr, "failed to call wbcCheckTrustCredentials: "
785 "%s\n", wbcErrorString(wbc_status));
792 /* Find the currently connected DCs */
794 static bool wbinfo_dc_info(const char *domain_name)
796 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
798 const char **dc_names, **dc_ips;
800 wbc_status = wbcDcInfo(domain_name, &num_dcs,
802 if (!WBC_ERROR_IS_OK(wbc_status)) {
803 printf("Could not find dc info %s\n",
804 domain_name ? domain_name : "our domain");
808 for (i=0; i<num_dcs; i++) {
809 printf("%s (%s)\n", dc_names[i], dc_ips[i]);
811 wbcFreeMemory(dc_names);
812 wbcFreeMemory(dc_ips);
817 /* Change trust account password */
819 static bool wbinfo_change_secret(const char *domain)
821 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
822 struct wbcAuthErrorInfo *error = NULL;
823 const char *domain_name;
826 domain_name = domain;
828 domain_name = get_winbind_domain();
831 wbc_status = wbcChangeTrustCredentials(domain_name, &error);
833 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
835 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
837 if (wbc_status == WBC_ERR_AUTH_ERROR) {
838 d_fprintf(stderr, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
839 domain_name, error->nt_string, error->nt_status);
840 wbcFreeMemory(error);
842 if (!WBC_ERROR_IS_OK(wbc_status)) {
843 d_fprintf(stderr, "failed to call wbcChangeTrustCredentials: "
844 "%s\n", wbcErrorString(wbc_status));
851 /* Check DC connection */
853 static bool wbinfo_ping_dc(const char *domain)
855 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
856 struct wbcAuthErrorInfo *error = NULL;
859 const char *domain_name;
862 domain_name = domain;
864 domain_name = get_winbind_domain();
867 wbc_status = wbcPingDc2(domain_name, &error, &dcname);
869 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
870 domain_name ? domain_name : "",
871 dcname ? dcname : "",
872 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
874 wbcFreeMemory(dcname);
875 if (wbc_status == WBC_ERR_AUTH_ERROR) {
876 d_fprintf(stderr, "wbcPingDc2(%s): error code was %s (0x%x)\n",
877 domain_name, error->nt_string, error->nt_status);
878 wbcFreeMemory(error);
881 if (!WBC_ERROR_IS_OK(wbc_status)) {
882 d_fprintf(stderr, "failed to call wbcPingDc: %s\n",
883 wbcErrorString(wbc_status));
890 /* Convert uid to sid */
892 static bool wbinfo_uid_to_sid(uid_t uid)
894 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
895 struct wbcDomainSid sid;
896 char sid_str[WBC_SID_STRING_BUFLEN];
900 wbc_status = wbcUidToSid(uid, &sid);
901 if (!WBC_ERROR_IS_OK(wbc_status)) {
902 d_fprintf(stderr, "failed to call wbcUidToSid: %s\n",
903 wbcErrorString(wbc_status));
907 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
909 /* Display response */
911 d_printf("%s\n", sid_str);
916 /* Convert gid to sid */
918 static bool wbinfo_gid_to_sid(gid_t gid)
920 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
921 struct wbcDomainSid sid;
922 char sid_str[WBC_SID_STRING_BUFLEN];
926 wbc_status = wbcGidToSid(gid, &sid);
927 if (!WBC_ERROR_IS_OK(wbc_status)) {
928 d_fprintf(stderr, "failed to call wbcGidToSid: %s\n",
929 wbcErrorString(wbc_status));
933 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
935 /* Display response */
937 d_printf("%s\n", sid_str);
942 /* Convert sid to uid */
944 static bool wbinfo_sid_to_uid(const char *sid_str)
946 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
947 struct wbcDomainSid sid;
952 wbc_status = wbcStringToSid(sid_str, &sid);
953 if (!WBC_ERROR_IS_OK(wbc_status)) {
954 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
955 wbcErrorString(wbc_status));
959 wbc_status = wbcSidToUid(&sid, &uid);
960 if (!WBC_ERROR_IS_OK(wbc_status)) {
961 d_fprintf(stderr, "failed to call wbcSidToUid: %s\n",
962 wbcErrorString(wbc_status));
966 /* Display response */
968 d_printf("%d\n", (int)uid);
973 static bool wbinfo_sid_to_gid(const char *sid_str)
975 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
976 struct wbcDomainSid sid;
981 wbc_status = wbcStringToSid(sid_str, &sid);
982 if (!WBC_ERROR_IS_OK(wbc_status)) {
983 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
984 wbcErrorString(wbc_status));
988 wbc_status = wbcSidToGid(&sid, &gid);
989 if (!WBC_ERROR_IS_OK(wbc_status)) {
990 d_fprintf(stderr, "failed to call wbcSidToGid: %s\n",
991 wbcErrorString(wbc_status));
995 /* Display response */
997 d_printf("%d\n", (int)gid);
1002 static bool wbinfo_sids_to_unix_ids(const char *arg)
1004 char sidstr[WBC_SID_STRING_BUFLEN];
1005 struct wbcDomainSid *sids;
1006 struct wbcUnixId *unix_ids;
1016 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1017 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1020 d_fprintf(stderr, "talloc failed\n");
1023 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
1024 if (!WBC_ERROR_IS_OK(wbc_status)) {
1025 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
1026 sidstr, wbcErrorString(wbc_status));
1033 unix_ids = talloc_array(talloc_tos(), struct wbcUnixId, num_sids);
1034 if (unix_ids == NULL) {
1039 wbc_status = wbcSidsToUnixIds(sids, num_sids, unix_ids);
1040 if (!WBC_ERROR_IS_OK(wbc_status)) {
1041 d_fprintf(stderr, "wbcSidsToUnixIds failed: %s\n",
1042 wbcErrorString(wbc_status));
1047 for (i=0; i<num_sids; i++) {
1049 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
1051 switch(unix_ids[i].type) {
1052 case WBC_ID_TYPE_UID:
1053 d_printf("%s -> uid %d\n", sidstr, unix_ids[i].id.uid);
1055 case WBC_ID_TYPE_GID:
1056 d_printf("%s -> gid %d\n", sidstr, unix_ids[i].id.gid);
1058 case WBC_ID_TYPE_BOTH:
1059 d_printf("%s -> uid/gid %d\n", sidstr, unix_ids[i].id.uid);
1062 d_printf("%s -> unmapped\n", sidstr);
1068 TALLOC_FREE(unix_ids);
1073 static bool wbinfo_xids_to_sids(const char *arg)
1076 struct wbcUnixId *xids = NULL;
1077 struct wbcDomainSid *sids;
1085 while (next_token(&p, idstr, LIST_SEP, sizeof(idstr))) {
1086 xids = talloc_realloc(talloc_tos(), xids, struct wbcUnixId,
1089 d_fprintf(stderr, "talloc failed\n");
1095 xids[num_xids] = (struct wbcUnixId) {
1096 .type = WBC_ID_TYPE_UID,
1097 .id.uid = atoi(&idstr[1])
1101 xids[num_xids] = (struct wbcUnixId) {
1102 .type = WBC_ID_TYPE_GID,
1103 .id.gid = atoi(&idstr[1])
1107 d_fprintf(stderr, "%s is an invalid id\n", idstr);
1114 sids = talloc_array(talloc_tos(), struct wbcDomainSid, num_xids);
1116 d_fprintf(stderr, "talloc failed\n");
1121 wbc_status = wbcUnixIdsToSids(xids, num_xids, sids);
1122 if (!WBC_ERROR_IS_OK(wbc_status)) {
1123 d_fprintf(stderr, "wbcUnixIdsToSids failed: %s\n",
1124 wbcErrorString(wbc_status));
1130 for (i=0; i<num_xids; i++) {
1131 char str[WBC_SID_STRING_BUFLEN];
1132 struct wbcDomainSid null_sid = { 0 };
1134 if (memcmp(&null_sid, &sids[i], sizeof(struct wbcDomainSid)) == 0) {
1135 d_printf("NOT MAPPED\n");
1138 wbcSidToStringBuf(&sids[i], str, sizeof(str));
1139 d_printf("%s\n", str);
1145 static bool wbinfo_allocate_uid(void)
1147 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1152 wbc_status = wbcAllocateUid(&uid);
1153 if (!WBC_ERROR_IS_OK(wbc_status)) {
1154 d_fprintf(stderr, "failed to call wbcAllocateUid: %s\n",
1155 wbcErrorString(wbc_status));
1159 /* Display response */
1161 d_printf("New uid: %u\n", (unsigned int)uid);
1166 static bool wbinfo_allocate_gid(void)
1168 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1173 wbc_status = wbcAllocateGid(&gid);
1174 if (!WBC_ERROR_IS_OK(wbc_status)) {
1175 d_fprintf(stderr, "failed to call wbcAllocateGid: %s\n",
1176 wbcErrorString(wbc_status));
1180 /* Display response */
1182 d_printf("New gid: %u\n", (unsigned int)gid);
1187 static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str)
1189 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1190 struct wbcDomainSid sid;
1194 wbc_status = wbcStringToSid(sid_str, &sid);
1195 if (!WBC_ERROR_IS_OK(wbc_status)) {
1196 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1197 wbcErrorString(wbc_status));
1201 wbc_status = wbcSetUidMapping(uid, &sid);
1202 if (!WBC_ERROR_IS_OK(wbc_status)) {
1203 d_fprintf(stderr, "failed to call wbcSetUidMapping: %s\n",
1204 wbcErrorString(wbc_status));
1208 /* Display response */
1210 d_printf("uid %u now mapped to sid %s\n",
1211 (unsigned int)uid, sid_str);
1216 static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str)
1218 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1219 struct wbcDomainSid sid;
1223 wbc_status = wbcStringToSid(sid_str, &sid);
1224 if (!WBC_ERROR_IS_OK(wbc_status)) {
1225 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1226 wbcErrorString(wbc_status));
1230 wbc_status = wbcSetGidMapping(gid, &sid);
1231 if (!WBC_ERROR_IS_OK(wbc_status)) {
1232 d_fprintf(stderr, "failed to call wbcSetGidMapping: %s\n",
1233 wbcErrorString(wbc_status));
1237 /* Display response */
1239 d_printf("gid %u now mapped to sid %s\n",
1240 (unsigned int)gid, sid_str);
1245 static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
1247 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1248 struct wbcDomainSid sid;
1252 wbc_status = wbcStringToSid(sid_str, &sid);
1253 if (!WBC_ERROR_IS_OK(wbc_status)) {
1254 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1255 wbcErrorString(wbc_status));
1259 wbc_status = wbcRemoveUidMapping(uid, &sid);
1260 if (!WBC_ERROR_IS_OK(wbc_status)) {
1261 d_fprintf(stderr, "failed to call wbcRemoveUidMapping: %s\n",
1262 wbcErrorString(wbc_status));
1266 /* Display response */
1268 d_printf("Removed uid %u to sid %s mapping\n",
1269 (unsigned int)uid, sid_str);
1274 static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
1276 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1277 struct wbcDomainSid sid;
1281 wbc_status = wbcStringToSid(sid_str, &sid);
1282 if (!WBC_ERROR_IS_OK(wbc_status)) {
1283 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1284 wbcErrorString(wbc_status));
1288 wbc_status = wbcRemoveGidMapping(gid, &sid);
1289 if (!WBC_ERROR_IS_OK(wbc_status)) {
1290 d_fprintf(stderr, "failed to call wbcRemoveGidMapping: %s\n",
1291 wbcErrorString(wbc_status));
1295 /* Display response */
1297 d_printf("Removed gid %u to sid %s mapping\n",
1298 (unsigned int)gid, sid_str);
1303 /* Convert sid to string */
1305 static bool wbinfo_lookupsid(const char *sid_str)
1307 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1308 struct wbcDomainSid sid;
1311 enum wbcSidType type;
1313 /* Send off request */
1315 wbc_status = wbcStringToSid(sid_str, &sid);
1316 if (!WBC_ERROR_IS_OK(wbc_status)) {
1317 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1318 wbcErrorString(wbc_status));
1322 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1323 if (!WBC_ERROR_IS_OK(wbc_status)) {
1324 d_fprintf(stderr, "failed to call wbcLookupSid: %s\n",
1325 wbcErrorString(wbc_status));
1329 /* Display response */
1331 if (type == WBC_SID_NAME_DOMAIN) {
1332 d_printf("%s %d\n", domain, type);
1334 d_printf("%s%c%s %d\n",
1335 domain, winbind_separator(), name, type);
1338 wbcFreeMemory(domain);
1339 wbcFreeMemory(name);
1344 /* Convert sid to fullname */
1346 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1348 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1349 struct wbcDomainSid sid;
1352 enum wbcSidType type;
1354 /* Send off request */
1356 wbc_status = wbcStringToSid(sid_str, &sid);
1357 if (!WBC_ERROR_IS_OK(wbc_status)) {
1358 d_fprintf(stderr, "failed to call wbcStringToSid: %s\n",
1359 wbcErrorString(wbc_status));
1363 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1364 if (!WBC_ERROR_IS_OK(wbc_status)) {
1365 d_fprintf(stderr, "failed to call wbcGetDisplayName: %s\n",
1366 wbcErrorString(wbc_status));
1370 /* Display response */
1372 d_printf("%s%c%s %d\n",
1373 domain, winbind_separator(), name, type);
1375 wbcFreeMemory(domain);
1376 wbcFreeMemory(name);
1381 /* Lookup a list of RIDs */
1383 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1385 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1386 struct wbcDomainInfo *dinfo = NULL;
1387 char *domain_name = NULL;
1388 const char **names = NULL;
1389 enum wbcSidType *types = NULL;
1392 uint32_t *rids = NULL;
1395 TALLOC_CTX *mem_ctx = NULL;
1398 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1399 domain = get_winbind_domain();
1404 wbc_status = wbcDomainInfo(domain, &dinfo);
1405 if (!WBC_ERROR_IS_OK(wbc_status)) {
1406 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1407 wbcErrorString(wbc_status));
1411 mem_ctx = talloc_new(NULL);
1412 if (mem_ctx == NULL) {
1413 d_printf("talloc_new failed\n");
1421 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1425 rid = smb_strtoul(ridstr, NULL, 10, &error, SMB_STR_STANDARD);
1427 d_printf("failed to convert rid\n");
1430 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1432 d_printf("talloc_realloc failed\n");
1434 rids[num_rids] = rid;
1439 d_printf("no rids\n");
1443 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
1444 &p, &names, &types);
1445 if (!WBC_ERROR_IS_OK(wbc_status)) {
1446 d_printf("winbind_lookup_rids failed: %s\n",
1447 wbcErrorString(wbc_status));
1451 domain_name = discard_const_p(char, p);
1452 d_printf("Domain: %s\n", domain_name);
1454 for (i=0; i<num_rids; i++) {
1455 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1456 wbcSidTypeString(types[i]));
1461 wbcFreeMemory(dinfo);
1462 wbcFreeMemory(domain_name);
1463 wbcFreeMemory(names);
1464 wbcFreeMemory(types);
1465 TALLOC_FREE(mem_ctx);
1469 static bool wbinfo_lookup_sids(const char *arg)
1471 char sidstr[WBC_SID_STRING_BUFLEN];
1472 struct wbcDomainSid *sids;
1473 struct wbcDomainInfo *domains;
1474 struct wbcTranslatedName *names;
1485 while (next_token(&p, sidstr, LIST_SEP, sizeof(sidstr))) {
1486 sids = talloc_realloc(talloc_tos(), sids, struct wbcDomainSid,
1489 d_fprintf(stderr, "talloc failed\n");
1492 wbc_status = wbcStringToSid(sidstr, &sids[num_sids]);
1493 if (!WBC_ERROR_IS_OK(wbc_status)) {
1494 d_fprintf(stderr, "wbcSidToString(%s) failed: %s\n",
1495 sidstr, wbcErrorString(wbc_status));
1502 wbc_status = wbcLookupSids(sids, num_sids, &domains, &num_domains,
1504 if (!WBC_ERROR_IS_OK(wbc_status)) {
1505 d_fprintf(stderr, "wbcLookupSids failed: %s\n",
1506 wbcErrorString(wbc_status));
1511 for (i=0; i<num_sids; i++) {
1512 const char *domain = NULL;
1514 wbcSidToStringBuf(&sids[i], sidstr, sizeof(sidstr));
1516 if (names[i].domain_index >= num_domains) {
1518 } else if (names[i].domain_index < 0) {
1521 domain = domains[names[i].domain_index].short_name;
1524 if (names[i].type == WBC_SID_NAME_DOMAIN) {
1525 d_printf("%s -> %s %d\n", sidstr,
1529 d_printf("%s -> %s%c%s %d\n", sidstr,
1531 winbind_separator(),
1532 names[i].name, names[i].type);
1535 wbcFreeMemory(names);
1536 wbcFreeMemory(domains);
1540 /* Convert string to sid */
1542 static bool wbinfo_lookupname(const char *full_name)
1544 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1545 struct wbcDomainSid sid;
1546 char sid_str[WBC_SID_STRING_BUFLEN];
1547 enum wbcSidType type;
1548 fstring domain_name;
1549 fstring account_name;
1551 /* Send off request */
1553 parse_wbinfo_domain_user(full_name, domain_name,
1556 wbc_status = wbcLookupName(domain_name, account_name,
1558 if (!WBC_ERROR_IS_OK(wbc_status)) {
1559 d_fprintf(stderr, "failed to call wbcLookupName: %s\n",
1560 wbcErrorString(wbc_status));
1564 wbcSidToStringBuf(&sid, sid_str, sizeof(sid_str));
1566 /* Display response */
1568 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
1573 static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
1575 const char *username)
1578 char buf[1024] = {0};
1581 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1586 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1591 prompt = talloc_asprintf_append(prompt, "password: ");
1596 rc = samba_getpass(prompt, buf, sizeof(buf), false, false);
1597 TALLOC_FREE(prompt);
1602 return talloc_strdup(mem_ctx, buf);
1605 /* Authenticate a user with a plaintext password */
1607 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1609 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1612 char *password = NULL;
1614 char *local_cctype = NULL;
1616 struct wbcLogonUserParams params;
1617 struct wbcLogonUserInfo *info;
1618 struct wbcAuthErrorInfo *error;
1619 struct wbcUserPasswordPolicyInfo *policy;
1620 TALLOC_CTX *frame = talloc_tos();
1622 if ((s = talloc_strdup(frame, username)) == NULL) {
1626 if ((p = strchr(s, '%')) != NULL) {
1629 password = talloc_strdup(frame, p);
1631 password = wbinfo_prompt_pass(frame, NULL, username);
1634 local_cctype = talloc_strdup(frame, cctype);
1640 params.username = name;
1641 params.password = password;
1642 params.num_blobs = 0;
1643 params.blobs = NULL;
1645 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1651 if (!WBC_ERROR_IS_OK(wbc_status)) {
1652 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1653 wbcErrorString(wbc_status));
1657 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1663 if (!WBC_ERROR_IS_OK(wbc_status)) {
1664 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1665 wbcErrorString(wbc_status));
1669 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1673 (uint8_t *)local_cctype,
1675 if (!WBC_ERROR_IS_OK(wbc_status)) {
1676 d_fprintf(stderr, "failed to call wbcAddNamedBlob: %s\n",
1677 wbcErrorString(wbc_status));
1681 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1683 d_printf("plaintext kerberos password authentication for [%s] %s "
1684 "(requesting cctype: %s)\n",
1685 name, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1690 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1691 "error message was: %s\n",
1692 params.username, error->nt_string,
1694 error->display_string);
1697 if (WBC_ERROR_IS_OK(wbc_status)) {
1698 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1699 if (info && info->info && info->info->user_flags &
1700 NETLOGON_CACHED_ACCOUNT) {
1701 d_printf("user_flgs: "
1702 "NETLOGON_CACHED_ACCOUNT\n");
1708 for (i=0; i < info->num_blobs; i++) {
1709 if (strequal(info->blobs[i].name,
1711 d_printf("credentials were put "
1714 info->blobs[i].blob.data);
1719 d_printf("no credentials cached\n");
1724 wbcFreeMemory(params.blobs);
1726 return WBC_ERROR_IS_OK(wbc_status);
1729 /* Authenticate a user with a plaintext password */
1731 static bool wbinfo_auth(char *username)
1733 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1736 char *password = NULL;
1738 TALLOC_CTX *frame = talloc_tos();
1740 if ((s = talloc_strdup(frame, username)) == NULL) {
1744 if ((p = strchr(s, '%')) != NULL) {
1747 password = talloc_strdup(frame, p);
1749 password = wbinfo_prompt_pass(frame, NULL, username);
1754 wbc_status = wbcAuthenticateUser(name, password);
1756 d_printf("plaintext password authentication %s\n",
1757 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1760 if (response.data.auth.nt_status)
1762 "error code was %s (0x%x)\nerror message was: %s\n",
1763 response.data.auth.nt_status_string,
1764 response.data.auth.nt_status,
1765 response.data.auth.error_string);
1768 return WBC_ERROR_IS_OK(wbc_status);
1771 /* Authenticate a user with a challenge/response */
1773 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1775 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1776 struct wbcAuthUserParams params;
1777 struct wbcAuthUserInfo *info = NULL;
1778 struct wbcAuthErrorInfo *err = NULL;
1779 DATA_BLOB lm = data_blob_null;
1780 DATA_BLOB nt = data_blob_null;
1782 fstring name_domain;
1785 TALLOC_CTX *frame = talloc_tos();
1787 p = strchr(username, '%');
1791 pass = talloc_strdup(frame, p + 1);
1793 pass = wbinfo_prompt_pass(frame, NULL, username);
1796 parse_wbinfo_domain_user(username, name_domain, name_user);
1798 params.account_name = name_user;
1799 params.domain_name = name_domain;
1800 params.workstation_name = NULL;
1803 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1804 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1806 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1808 generate_random_buffer(params.password.response.challenge, 8);
1811 DATA_BLOB server_chal;
1812 DATA_BLOB names_blob;
1813 const char *netbios_name = NULL;
1814 const char *domain = NULL;
1816 netbios_name = get_winbind_netbios_name(),
1817 domain = get_winbind_domain();
1818 if (domain == NULL) {
1819 d_fprintf(stderr, "Failed to get domain from winbindd\n");
1823 server_chal = data_blob(params.password.response.challenge, 8);
1825 /* Pretend this is a login to 'us', for blob purposes */
1826 names_blob = NTLMv2_generate_names_blob(NULL,
1831 !SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1834 &lm, &nt, NULL, NULL)) {
1835 data_blob_free(&names_blob);
1836 data_blob_free(&server_chal);
1840 data_blob_free(&names_blob);
1841 data_blob_free(&server_chal);
1846 lm = data_blob(NULL, 24);
1847 ok = SMBencrypt(pass,
1848 params.password.response.challenge,
1851 data_blob_free(&lm);
1854 nt = data_blob(NULL, 24);
1855 SMBNTencrypt(pass, params.password.response.challenge,
1859 params.password.response.nt_length = nt.length;
1860 params.password.response.nt_data = nt.data;
1861 params.password.response.lm_length = lm.length;
1862 params.password.response.lm_data = lm.data;
1864 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1866 /* Display response */
1868 d_printf("challenge/response password authentication %s\n",
1869 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1871 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1873 "wbcAuthenticateUserEx(%s%c%s): error code was "
1874 "%s (0x%x, authoritative=%"PRIu8")\n"
1875 "error message was: %s\n",
1877 winbind_separator(),
1882 err->display_string);
1884 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1885 wbcFreeMemory(info);
1888 data_blob_free(&nt);
1889 data_blob_free(&lm);
1891 return WBC_ERROR_IS_OK(wbc_status);
1894 /* Authenticate a user with a plaintext password */
1896 static bool wbinfo_pam_logon(char *username, bool verbose)
1898 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1899 struct wbcLogonUserParams params;
1900 struct wbcLogonUserInfo *info = NULL;
1901 struct wbcAuthErrorInfo *error = NULL;
1904 TALLOC_CTX *frame = talloc_tos();
1908 ZERO_STRUCT(params);
1910 if ((s = talloc_strdup(frame, username)) == NULL) {
1914 if ((p = strchr(s, '%')) != NULL) {
1917 params.password = talloc_strdup(frame, p);
1919 params.password = wbinfo_prompt_pass(frame, NULL, username);
1921 params.username = s;
1923 flags = WBFLAG_PAM_CACHED_LOGIN;
1925 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1927 (uint8_t *)&flags, sizeof(flags));
1928 if (!WBC_ERROR_IS_OK(wbc_status)) {
1929 d_printf("wbcAddNamedBlob failed: %s\n",
1930 wbcErrorString(wbc_status));
1936 wbc_status = wbcAddNamedBlob(¶ms.num_blobs, ¶ms.blobs,
1938 (uint8_t *)&uid, sizeof(uid));
1939 if (!WBC_ERROR_IS_OK(wbc_status)) {
1940 d_printf("wbcAddNamedBlob failed: %s\n",
1941 wbcErrorString(wbc_status));
1945 wbc_status = wbcLogonUser(¶ms, &info, &error, NULL);
1947 if (verbose && (info != NULL)) {
1948 struct wbcAuthUserInfo *i = info->info;
1951 if (i->account_name != NULL) {
1952 d_printf("account_name: %s\n", i->account_name);
1954 if (i->user_principal != NULL) {
1955 d_printf("user_principal: %s\n", i->user_principal);
1957 if (i->full_name != NULL) {
1958 d_printf("full_name: %s\n", i->full_name);
1960 if (i->domain_name != NULL) {
1961 d_printf("domain_name: %s\n", i->domain_name);
1963 if (i->dns_domain_name != NULL) {
1964 d_printf("dns_domain_name: %s\n", i->dns_domain_name);
1966 if (i->logon_server != NULL) {
1967 d_printf("logon_server: %s\n", i->logon_server);
1969 if (i->logon_script != NULL) {
1970 d_printf("logon_script: %s\n", i->logon_script);
1972 if (i->profile_path != NULL) {
1973 d_printf("profile_path: %s\n", i->profile_path);
1975 if (i->home_directory != NULL) {
1976 d_printf("home_directory: %s\n", i->home_directory);
1978 if (i->home_drive != NULL) {
1979 d_printf("home_drive: %s\n", i->home_drive);
1984 for (j=0; j<i->num_sids; j++) {
1985 char buf[WBC_SID_STRING_BUFLEN];
1986 wbcSidToStringBuf(&i->sids[j].sid, buf, sizeof(buf));
1987 d_printf(" %s", buf);
1991 wbcFreeMemory(info);
1995 wbcFreeMemory(params.blobs);
1997 d_printf("plaintext password authentication %s\n",
1998 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2000 if (!WBC_ERROR_IS_OK(wbc_status) && (error != NULL)) {
2002 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2003 "error message was: %s\n",
2006 (int)error->nt_status,
2007 error->display_string);
2008 wbcFreeMemory(error);
2010 return WBC_ERROR_IS_OK(wbc_status);
2013 /* Save creds with winbind */
2015 static bool wbinfo_ccache_save(char *username)
2017 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2020 char *password = NULL;
2022 TALLOC_CTX *frame = talloc_stackframe();
2024 s = talloc_strdup(frame, username);
2033 password = talloc_strdup(frame, p);
2035 password = wbinfo_prompt_pass(frame, NULL, username);
2040 wbc_status = wbcCredentialSave(name, password);
2042 d_printf("saving creds %s\n",
2043 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2047 return WBC_ERROR_IS_OK(wbc_status);
2050 #ifdef WITH_FAKE_KASERVER
2051 /* Authenticate a user with a plaintext password and set a token */
2053 static bool wbinfo_klog(char *username)
2055 struct winbindd_request request;
2056 struct winbindd_response response;
2060 /* Send off request */
2062 ZERO_STRUCT(request);
2063 ZERO_STRUCT(response);
2065 p = strchr(username, '%');
2069 fstrcpy(request.data.auth.user, username);
2070 fstrcpy(request.data.auth.pass, p + 1);
2073 fstrcpy(request.data.auth.user, username);
2074 (void) samba_getpass("Password: ",
2075 request.data.auth.pass,
2076 sizeof(request.data.auth.pass),
2080 request.flags |= WBFLAG_PAM_AFS_TOKEN;
2082 result = winbindd_request_response(NULL, WINBINDD_PAM_AUTH, &request,
2085 /* Display response */
2087 d_printf("plaintext password authentication %s\n",
2088 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
2090 if (response.data.auth.nt_status)
2092 "error code was %s (0x%x)\nerror message was: %s\n",
2093 response.data.auth.nt_status_string,
2094 response.data.auth.nt_status,
2095 response.data.auth.error_string);
2097 if (result != NSS_STATUS_SUCCESS)
2100 if (response.extra_data.data == NULL) {
2101 d_fprintf(stderr, "Did not get token data\n");
2105 if (!afs_settoken_str((char *)response.extra_data.data)) {
2106 d_fprintf(stderr, "Could not set token\n");
2110 d_printf("Successfully created AFS token\n");
2114 static bool wbinfo_klog(char *username)
2116 d_fprintf(stderr, "No AFS support compiled in.\n");
2121 /* Print domain users */
2123 static bool print_domain_users(const char *domain)
2125 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2127 uint32_t num_users = 0;
2128 const char **users = NULL;
2130 /* Send request to winbind daemon */
2132 if (domain == NULL) {
2133 domain = get_winbind_domain();
2135 /* '.' is the special sign for our own domain */
2136 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
2137 domain = get_winbind_domain();
2138 /* '*' is the special sign for all domains */
2139 } else if (strcmp(domain, "*") == 0) {
2144 wbc_status = wbcListUsers(domain, &num_users, &users);
2145 if (!WBC_ERROR_IS_OK(wbc_status)) {
2149 for (i=0; i < num_users; i++) {
2150 d_printf("%s\n", users[i]);
2153 wbcFreeMemory(users);
2158 /* Print domain groups */
2160 static bool print_domain_groups(const char *domain)
2162 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
2164 uint32_t num_groups = 0;
2165 const char **groups = NULL;
2167 /* Send request to winbind daemon */
2169 if (domain == NULL) {
2170 domain = get_winbind_domain();
2172 /* '.' is the special sign for our own domain */
2173 if ((domain[0] == '\0') || strcmp(domain, ".") == 0) {
2174 domain = get_winbind_domain();
2175 /* '*' is the special sign for all domains */
2176 } else if (strcmp(domain, "*") == 0) {
2181 wbc_status = wbcListGroups(domain, &num_groups, &groups);
2182 if (!WBC_ERROR_IS_OK(wbc_status)) {
2183 d_fprintf(stderr, "failed to call wbcListGroups: %s\n",
2184 wbcErrorString(wbc_status));
2188 for (i=0; i < num_groups; i++) {
2189 d_printf("%s\n", groups[i]);
2192 wbcFreeMemory(groups);
2197 /* Set the authorised user for winbindd access in secrets.tdb */
2199 static bool wbinfo_set_auth_user(char *username)
2201 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
2202 "See 'net help setauthuser' for details.\n");
2206 static void wbinfo_get_auth_user(void)
2208 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
2209 "See 'net help getauthuser' for details.\n");
2212 static bool wbinfo_ping(void)
2216 wbc_status = wbcPing();
2218 /* Display response */
2220 d_printf("Ping to winbindd %s\n",
2221 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2223 return WBC_ERROR_IS_OK(wbc_status);
2226 static bool wbinfo_change_user_password(const char *username)
2229 char *old_password = NULL;
2230 char *new_password = NULL;
2231 TALLOC_CTX *frame = talloc_tos();
2233 old_password = wbinfo_prompt_pass(frame, "old", username);
2234 new_password = wbinfo_prompt_pass(frame, "new", username);
2236 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
2238 /* Display response */
2240 d_printf("Password change for user %s %s\n", username,
2241 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
2243 return WBC_ERROR_IS_OK(wbc_status);
2249 OPT_SET_AUTH_USER = 1000,
2262 OPT_SET_UID_MAPPING,
2263 OPT_SET_GID_MAPPING,
2264 OPT_REMOVE_UID_MAPPING,
2265 OPT_REMOVE_GID_MAPPING,
2269 OPT_LIST_ALL_DOMAINS,
2270 OPT_LIST_OWN_DOMAIN,
2277 OPT_CHANGE_USER_PASSWORD,
2279 OPT_SID_TO_FULLNAME,
2290 int main(int argc, const char **argv, char **envp)
2293 TALLOC_CTX *frame = talloc_stackframe();
2295 static char *string_arg;
2296 char *string_subarg = NULL;
2297 static char *opt_domain_name;
2299 int int_subarg = -1;
2301 bool verbose = false;
2302 bool use_ntlmv2 = true;
2303 bool use_lanman = false;
2304 char *logoff_user = getenv("USER");
2305 int logoff_uid = geteuid();
2306 const char *opt_krb5ccname = "FILE";
2308 struct poptOption long_options[] = {
2311 /* longName, shortName, argInfo, argPtr, value, descrip,
2315 .longName = "domain-users",
2317 .argInfo = POPT_ARG_NONE,
2319 .descrip = "Lists all domain users",
2320 .argDescrip = "domain"
2323 .longName = "domain-groups",
2325 .argInfo = POPT_ARG_NONE,
2327 .descrip = "Lists all domain groups",
2328 .argDescrip = "domain"
2331 .longName = "WINS-by-name",
2333 .argInfo = POPT_ARG_STRING,
2336 .descrip = "Converts NetBIOS name to IP",
2337 .argDescrip = "NETBIOS-NAME"
2340 .longName = "WINS-by-ip",
2342 .argInfo = POPT_ARG_STRING,
2345 .descrip = "Converts IP address to NetBIOS name",
2349 .longName = "name-to-sid",
2351 .argInfo = POPT_ARG_STRING,
2354 .descrip = "Converts name to sid",
2355 .argDescrip = "NAME"
2358 .longName = "sid-to-name",
2360 .argInfo = POPT_ARG_STRING,
2363 .descrip = "Converts sid to name",
2367 .longName = "sid-to-fullname",
2368 .argInfo = POPT_ARG_STRING,
2370 .val = OPT_SID_TO_FULLNAME,
2371 .descrip = "Converts sid to fullname",
2375 .longName = "lookup-rids",
2377 .argInfo = POPT_ARG_STRING,
2380 .descrip = "Converts RIDs to names",
2381 .argDescrip = "RIDs"
2384 .longName = "lookup-sids",
2385 .argInfo = POPT_ARG_STRING,
2387 .val = OPT_LOOKUP_SIDS,
2388 .descrip = "Converts SIDs to types and names",
2389 .argDescrip = "Sid-List"
2392 .longName = "uid-to-sid",
2394 .argInfo = POPT_ARG_INT,
2397 .descrip = "Converts uid to sid",
2401 .longName = "gid-to-sid",
2403 .argInfo = POPT_ARG_INT,
2406 .descrip = "Converts gid to sid",
2410 .longName = "sid-to-uid",
2412 .argInfo = POPT_ARG_STRING,
2415 .descrip = "Converts sid to uid",
2419 .longName = "sid-to-gid",
2421 .argInfo = POPT_ARG_STRING,
2424 .descrip = "Converts sid to gid",
2428 .longName = "allocate-uid",
2429 .argInfo = POPT_ARG_NONE,
2430 .val = OPT_ALLOCATE_UID,
2431 .descrip = "Get a new UID out of idmap"
2434 .longName = "allocate-gid",
2435 .argInfo = POPT_ARG_NONE,
2436 .val = OPT_ALLOCATE_GID,
2437 .descrip = "Get a new GID out of idmap"
2440 .longName = "set-uid-mapping",
2441 .argInfo = POPT_ARG_STRING,
2443 .val = OPT_SET_UID_MAPPING,
2444 .descrip = "Create or modify uid to sid mapping in "
2446 .argDescrip = "UID,SID"
2449 .longName = "set-gid-mapping",
2450 .argInfo = POPT_ARG_STRING,
2452 .val = OPT_SET_GID_MAPPING,
2453 .descrip = "Create or modify gid to sid mapping in "
2455 .argDescrip = "GID,SID"
2458 .longName = "remove-uid-mapping",
2459 .argInfo = POPT_ARG_STRING,
2461 .val = OPT_REMOVE_UID_MAPPING,
2462 .descrip = "Remove uid to sid mapping in idmap",
2463 .argDescrip = "UID,SID"
2466 .longName = "remove-gid-mapping",
2467 .argInfo = POPT_ARG_STRING,
2469 .val = OPT_REMOVE_GID_MAPPING,
2470 .descrip = "Remove gid to sid mapping in idmap",
2471 .argDescrip = "GID,SID",
2474 .longName = "sids-to-unix-ids",
2475 .argInfo = POPT_ARG_STRING,
2477 .val = OPT_SIDS_TO_XIDS,
2478 .descrip = "Translate SIDs to Unix IDs",
2479 .argDescrip = "Sid-List",
2482 .longName = "unix-ids-to-sids",
2483 .argInfo = POPT_ARG_STRING,
2485 .val = OPT_XIDS_TO_SIDS,
2486 .descrip = "Translate Unix IDs to SIDs",
2487 .argDescrip = "ID-List (u<num> g<num>)",
2490 .longName = "check-secret",
2492 .argInfo = POPT_ARG_NONE,
2494 .descrip = "Check shared secret",
2497 .longName = "change-secret",
2499 .argInfo = POPT_ARG_NONE,
2501 .descrip = "Change shared secret",
2504 .longName = "ping-dc",
2506 .argInfo = POPT_ARG_NONE,
2508 .descrip = "Check the NETLOGON connection",
2511 .longName = "trusted-domains",
2513 .argInfo = POPT_ARG_NONE,
2515 .descrip = "List trusted domains",
2518 .longName = "all-domains",
2519 .argInfo = POPT_ARG_NONE,
2520 .val = OPT_LIST_ALL_DOMAINS,
2521 .descrip = "List all domains (trusted and own "
2525 .longName = "own-domain",
2526 .argInfo = POPT_ARG_NONE,
2527 .val = OPT_LIST_OWN_DOMAIN,
2528 .descrip = "List own domain",
2531 .longName = "sequence",
2532 .argInfo = POPT_ARG_NONE,
2533 .val = OPT_SEQUENCE,
2534 .descrip = "Deprecated command, see --online-status",
2537 .longName = "online-status",
2538 .argInfo = POPT_ARG_NONE,
2539 .val = OPT_ONLINESTATUS,
2540 .descrip = "Show whether domains maintain an active "
2544 .longName = "domain-info",
2546 .argInfo = POPT_ARG_STRING,
2549 .descrip = "Show most of the info we have about the "
2553 .longName = "user-info",
2555 .argInfo = POPT_ARG_STRING,
2558 .descrip = "Get user info",
2559 .argDescrip = "USER",
2562 .longName = "uid-info",
2563 .argInfo = POPT_ARG_INT,
2565 .val = OPT_UID_INFO,
2566 .descrip = "Get user info from uid",
2567 .argDescrip = "UID",
2570 .longName = "group-info",
2571 .argInfo = POPT_ARG_STRING,
2573 .val = OPT_GROUP_INFO,
2574 .descrip = "Get group info",
2575 .argDescrip = "GROUP",
2578 .longName = "user-sidinfo",
2579 .argInfo = POPT_ARG_STRING,
2581 .val = OPT_USER_SIDINFO,
2582 .descrip = "Get user info from sid",
2583 .argDescrip = "SID",
2586 .longName = "gid-info",
2587 .argInfo = POPT_ARG_INT,
2589 .val = OPT_GID_INFO,
2590 .descrip = "Get group info from gid",
2591 .argDescrip = "GID",
2594 .longName = "user-groups",
2596 .argInfo = POPT_ARG_STRING,
2599 .descrip = "Get user groups",
2600 .argDescrip = "USER",
2603 .longName = "user-domgroups",
2604 .argInfo = POPT_ARG_STRING,
2606 .val = OPT_USERDOMGROUPS,
2607 .descrip = "Get user domain groups",
2608 .argDescrip = "SID",
2611 .longName = "sid-aliases",
2612 .argInfo = POPT_ARG_STRING,
2614 .val = OPT_SIDALIASES,
2615 .descrip = "Get sid aliases",
2616 .argDescrip = "SID",
2619 .longName = "user-sids",
2620 .argInfo = POPT_ARG_STRING,
2622 .val = OPT_USERSIDS,
2623 .descrip = "Get user group sids for user SID",
2624 .argDescrip = "SID",
2627 .longName = "authenticate",
2629 .argInfo = POPT_ARG_STRING,
2632 .descrip = "authenticate user",
2633 .argDescrip = "user%password",
2636 .longName = "pam-logon",
2637 .argInfo = POPT_ARG_STRING,
2639 .val = OPT_PAM_LOGON,
2640 .descrip = "do a pam logon equivalent",
2641 .argDescrip = "user%password",
2644 .longName = "logoff",
2645 .argInfo = POPT_ARG_NONE,
2647 .descrip = "log off user",
2648 .argDescrip = "uid",
2651 .longName = "logoff-user",
2652 .argInfo = POPT_ARG_STRING,
2653 .arg = &logoff_user,
2654 .val = OPT_LOGOFF_USER,
2655 .descrip = "username to log off"
2658 .longName = "logoff-uid",
2659 .argInfo = POPT_ARG_INT,
2661 .val = OPT_LOGOFF_UID,
2662 .descrip = "uid to log off",
2665 .longName = "set-auth-user",
2666 .argInfo = POPT_ARG_STRING,
2668 .val = OPT_SET_AUTH_USER,
2669 .descrip = "Store user and password used by "
2670 "winbindd (root only)",
2671 .argDescrip = "user%password",
2674 .longName = "ccache-save",
2676 .argInfo = POPT_ARG_STRING,
2678 .val = OPT_CCACHE_SAVE,
2679 .descrip = "Store user and password for ccache "
2681 .argDescrip = "user%password",
2684 .longName = "getdcname",
2685 .argInfo = POPT_ARG_STRING,
2687 .val = OPT_GETDCNAME,
2688 .descrip = "Get a DC name for a foreign domain",
2689 .argDescrip = "domainname",
2692 .longName = "dsgetdcname",
2693 .argInfo = POPT_ARG_STRING,
2695 .val = OPT_DSGETDCNAME,
2696 .descrip = "Find a DC for a domain",
2697 .argDescrip = "domainname",
2700 .longName = "dc-info",
2701 .argInfo = POPT_ARG_STRING,
2704 .descrip = "Find the currently known DCs",
2705 .argDescrip = "domainname",
2708 .longName = "get-auth-user",
2709 .argInfo = POPT_ARG_NONE,
2710 .val = OPT_GET_AUTH_USER,
2711 .descrip = "Retrieve user and password used by "
2712 "winbindd (root only)",
2717 .argInfo = POPT_ARG_NONE,
2720 .descrip = "Ping winbindd to see if it is alive",
2723 .longName = "domain",
2725 .argInfo = POPT_ARG_STRING,
2726 .arg = &opt_domain_name,
2727 .val = OPT_DOMAIN_NAME,
2728 .descrip = "Define to the domain to restrict "
2730 .argDescrip = "domain",
2732 #ifdef WITH_FAKE_KASERVER
2736 .argInfo = POPT_ARG_STRING,
2739 .descrip = "set an AFS token from winbind",
2740 .argDescrip = "user%password",
2745 .longName = "krb5auth",
2747 .argInfo = POPT_ARG_STRING,
2750 .descrip = "authenticate user using Kerberos",
2751 .argDescrip = "user%password",
2753 /* destroys wbinfo --help output */
2754 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2757 .longName = "krb5ccname",
2758 .argInfo = POPT_ARG_STRING,
2759 .arg = &opt_krb5ccname,
2760 .val = OPT_KRB5CCNAME,
2761 .descrip = "authenticate user using Kerberos and "
2762 "specific credential cache type",
2763 .argDescrip = "krb5ccname",
2767 .longName = "separator",
2768 .argInfo = POPT_ARG_NONE,
2769 .val = OPT_SEPARATOR,
2770 .descrip = "Get the active winbind separator",
2773 .longName = "verbose",
2774 .argInfo = POPT_ARG_NONE,
2776 .descrip = "Print additional information per command",
2779 .longName = "change-user-password",
2780 .argInfo = POPT_ARG_STRING,
2782 .val = OPT_CHANGE_USER_PASSWORD,
2783 .descrip = "Change the password for a user",
2786 .longName = "ntlmv1",
2787 .argInfo = POPT_ARG_NONE,
2789 .descrip = "Use NTLMv1 cryptography for user authentication",
2792 .longName = "ntlmv2",
2793 .argInfo = POPT_ARG_NONE,
2795 .descrip = "Use NTLMv2 cryptography for user authentication",
2798 .longName = "lanman",
2799 .argInfo = POPT_ARG_NONE,
2801 .descrip = "Use lanman cryptography for user authentication",
2807 /* Samba client initialisation */
2813 pc = poptGetContext("wbinfo", argc, argv,
2816 /* Parse command line options */
2819 poptPrintHelp(pc, stderr, 0);
2823 while((opt = poptGetNextOpt(pc)) != -1) {
2824 /* get the generic configuration parameters like --domain */
2838 poptFreeContext(pc);
2840 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
2841 POPT_CONTEXT_KEEP_FIRST);
2843 while((opt = poptGetNextOpt(pc)) != -1) {
2846 if (!print_domain_users(opt_domain_name)) {
2848 "Error looking up domain users\n");
2853 if (!print_domain_groups(opt_domain_name)) {
2855 "Error looking up domain groups\n");
2860 if (!wbinfo_lookupsid(string_arg)) {
2862 "Could not lookup sid %s\n",
2867 case OPT_SID_TO_FULLNAME:
2868 if (!wbinfo_lookupsid_fullname(string_arg)) {
2869 d_fprintf(stderr, "Could not lookup sid %s\n",
2875 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
2876 d_fprintf(stderr, "Could not lookup RIDs %s\n",
2881 case OPT_LOOKUP_SIDS:
2882 if (!wbinfo_lookup_sids(string_arg)) {
2883 d_fprintf(stderr, "Could not lookup SIDs %s\n",
2889 if (!wbinfo_lookupname(string_arg)) {
2890 d_fprintf(stderr, "Could not lookup name %s\n",
2896 if (!wbinfo_wins_byname(string_arg)) {
2898 "Could not lookup WINS by name %s\n",
2904 if (!wbinfo_wins_byip(string_arg)) {
2906 "Could not lookup WINS by IP %s\n",
2912 if (!wbinfo_uid_to_sid(int_arg)) {
2914 "Could not convert uid %d to sid\n",
2920 if (!wbinfo_gid_to_sid(int_arg)) {
2922 "Could not convert gid %d to sid\n",
2928 if (!wbinfo_sid_to_uid(string_arg)) {
2930 "Could not convert sid %s to uid\n",
2936 if (!wbinfo_sid_to_gid(string_arg)) {
2938 "Could not convert sid %s to gid\n",
2943 case OPT_ALLOCATE_UID:
2944 if (!wbinfo_allocate_uid()) {
2945 d_fprintf(stderr, "Could not allocate a uid\n");
2949 case OPT_ALLOCATE_GID:
2950 if (!wbinfo_allocate_gid()) {
2951 d_fprintf(stderr, "Could not allocate a gid\n");
2955 case OPT_SET_UID_MAPPING:
2956 if (!parse_mapping_arg(string_arg, &int_subarg,
2958 !wbinfo_set_uid_mapping(int_subarg, string_subarg))
2960 d_fprintf(stderr, "Could not create or modify "
2961 "uid to sid mapping\n");
2965 case OPT_SET_GID_MAPPING:
2966 if (!parse_mapping_arg(string_arg, &int_subarg,
2968 !wbinfo_set_gid_mapping(int_subarg, string_subarg))
2970 d_fprintf(stderr, "Could not create or modify "
2971 "gid to sid mapping\n");
2975 case OPT_REMOVE_UID_MAPPING:
2976 if (!parse_mapping_arg(string_arg, &int_subarg,
2978 !wbinfo_remove_uid_mapping(int_subarg,
2981 d_fprintf(stderr, "Could not remove uid to sid "
2986 case OPT_REMOVE_GID_MAPPING:
2987 if (!parse_mapping_arg(string_arg, &int_subarg,
2989 !wbinfo_remove_gid_mapping(int_subarg,
2992 d_fprintf(stderr, "Could not remove gid to sid "
2997 case OPT_SIDS_TO_XIDS:
2998 if (!wbinfo_sids_to_unix_ids(string_arg)) {
2999 d_fprintf(stderr, "wbinfo_sids_to_unix_ids "
3004 case OPT_XIDS_TO_SIDS:
3005 if (!wbinfo_xids_to_sids(string_arg)) {
3006 d_fprintf(stderr, "wbinfo_xids_to_sids "
3012 if (!wbinfo_check_secret(opt_domain_name)) {
3013 d_fprintf(stderr, "Could not check secret\n");
3018 if (!wbinfo_change_secret(opt_domain_name)) {
3019 d_fprintf(stderr, "Could not change secret\n");
3024 if (!wbinfo_ping_dc(opt_domain_name)) {
3029 if (!wbinfo_list_domains(false, verbose)) {
3031 "Could not list trusted domains\n");
3036 if (!wbinfo_show_sequence(opt_domain_name)) {
3038 "Could not show sequence numbers\n");
3042 case OPT_ONLINESTATUS:
3043 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
3045 "Could not show online-status\n");
3050 if (!wbinfo_domain_info(string_arg)) {
3052 "Could not get domain info\n");
3057 if (!wbinfo_get_userinfo(string_arg)) {
3059 "Could not get info for user %s\n",
3064 case OPT_USER_SIDINFO:
3065 if ( !wbinfo_get_user_sidinfo(string_arg)) {
3067 "Could not get info for user "
3068 "sid %s\n", string_arg);
3073 if ( !wbinfo_get_uidinfo(int_arg)) {
3074 d_fprintf(stderr, "Could not get info for uid "
3079 case OPT_GROUP_INFO:
3080 if ( !wbinfo_get_groupinfo(string_arg)) {
3081 d_fprintf(stderr, "Could not get info for "
3082 "group %s\n", string_arg);
3087 if ( !wbinfo_get_gidinfo(int_arg)) {
3088 d_fprintf(stderr, "Could not get info for gid "
3094 if (!wbinfo_get_usergroups(string_arg)) {
3096 "Could not get groups for user %s\n",
3102 if (!wbinfo_get_usersids(string_arg)) {
3103 d_fprintf(stderr, "Could not get group SIDs "
3104 "for user SID %s\n",
3109 case OPT_USERDOMGROUPS:
3110 if (!wbinfo_get_userdomgroups(string_arg)) {
3111 d_fprintf(stderr, "Could not get user's domain "
3112 "groups for user SID %s\n",
3117 case OPT_SIDALIASES:
3118 if (!wbinfo_get_sidaliases(opt_domain_name,
3120 d_fprintf(stderr, "Could not get sid aliases "
3121 "for user SID %s\n", string_arg);
3126 bool got_error = false;
3128 if (!wbinfo_auth(string_arg)) {
3130 "Could not authenticate user "
3131 "%s with plaintext "
3132 "password\n", string_arg);
3136 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
3139 "Could not authenticate user "
3140 "%s with challenge/response\n",
3150 if (!wbinfo_pam_logon(string_arg, verbose)) {
3151 d_fprintf(stderr, "pam_logon failed for %s\n",
3160 wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
3162 d_printf("Logoff %s (%d): %s\n", logoff_user,
3163 logoff_uid, wbcErrorString(wbc_status));
3167 uint32_t flags = WBFLAG_PAM_KRB5 |
3168 WBFLAG_PAM_CACHED_LOGIN |
3169 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
3170 WBFLAG_PAM_INFO3_TEXT |
3171 WBFLAG_PAM_CONTACT_TRUSTDOM;
3173 if (!wbinfo_auth_krb5(string_arg, opt_krb5ccname,
3176 "Could not authenticate user "
3177 "[%s] with Kerberos "
3178 "(ccache: %s)\n", string_arg,
3185 if (!wbinfo_klog(string_arg)) {
3186 d_fprintf(stderr, "Could not klog user\n");
3191 if (!wbinfo_ping()) {
3192 d_fprintf(stderr, "could not ping winbindd!\n");
3196 case OPT_SET_AUTH_USER:
3197 if (!wbinfo_set_auth_user(string_arg)) {
3201 case OPT_GET_AUTH_USER:
3202 wbinfo_get_auth_user();
3205 case OPT_CCACHE_SAVE:
3206 if (!wbinfo_ccache_save(string_arg)) {
3211 if (!wbinfo_getdcname(string_arg)) {
3215 case OPT_DSGETDCNAME:
3216 if (!wbinfo_dsgetdcname(string_arg, 0)) {
3221 if (!wbinfo_dc_info(string_arg)) {
3225 case OPT_SEPARATOR: {
3226 const char sep = winbind_separator();
3230 d_printf("%c\n", sep);
3233 case OPT_LIST_ALL_DOMAINS:
3234 if (!wbinfo_list_domains(true, verbose)) {
3238 case OPT_LIST_OWN_DOMAIN:
3239 if (!wbinfo_list_own_domain()) {
3243 case OPT_CHANGE_USER_PASSWORD:
3244 if (!wbinfo_change_user_password(string_arg)) {
3246 "Could not change user password "
3247 "for user %s\n", string_arg);
3252 /* generic configuration options */
3253 case OPT_DOMAIN_NAME:
3258 case OPT_LOGOFF_USER:
3259 case OPT_LOGOFF_UID:
3260 case OPT_KRB5CCNAME:
3263 d_fprintf(stderr, "Invalid option\n");
3264 poptPrintHelp(pc, stderr, 0);
3276 poptFreeContext(pc);