2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "winbind_client.h"
25 #include "libwbclient/wbclient.h"
26 #include "../libcli/auth/libcli_auth.h"
29 #define DBGC_CLASS DBGC_WINBIND
31 static struct wbcInterfaceDetails *init_interface_details(void)
33 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
34 static struct wbcInterfaceDetails *details;
40 wbc_status = wbcInterfaceDetails(&details);
41 if (!WBC_ERROR_IS_OK(wbc_status)) {
42 d_fprintf(stderr, "could not obtain winbind interface "
49 static char winbind_separator(void)
51 struct wbcInterfaceDetails *details;
58 details = init_interface_details();
61 d_fprintf(stderr, "could not obtain winbind separator!\n");
65 sep = details->winbind_separator;
69 d_fprintf(stderr, "winbind separator was NULL!\n");
76 static const char *get_winbind_domain(void)
78 static struct wbcInterfaceDetails *details;
80 details = init_interface_details();
83 d_fprintf(stderr, "could not obtain winbind domain name!\n");
87 return details->netbios_domain;
90 static const char *get_winbind_netbios_name(void)
92 static struct wbcInterfaceDetails *details;
94 details = init_interface_details();
97 d_fprintf(stderr, "could not obtain winbind netbios name!\n");
101 return details->netbios_name;
104 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
105 form DOMAIN/user into a domain and a user */
107 static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
111 char *p = strchr(domuser,winbind_separator());
114 /* Maybe it was a UPN? */
115 if ((p = strchr(domuser, '@')) != NULL) {
117 fstrcpy(user, domuser);
121 fstrcpy(user, domuser);
122 fstrcpy(domain, get_winbind_domain());
127 fstrcpy(domain, domuser);
128 domain[PTR_DIFF(p, domuser)] = 0;
134 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
135 * Return true if input was valid, false otherwise. */
136 static bool parse_mapping_arg(char *arg, int *id, char **sid)
143 tmp = strtok(arg, ",");
144 *sid = strtok(NULL, ",");
146 if (!tmp || !*tmp || !*sid || !**sid)
149 /* Because atoi() can return 0 on invalid input, which would be a valid
150 * UID/GID we must use strtoul() and do error checking */
151 *id = strtoul(tmp, &endptr, 10);
153 if (endptr[0] != '\0')
159 /* pull pwent info for a given user */
161 static bool wbinfo_get_userinfo(char *user)
163 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
164 struct passwd *pwd = NULL;
166 wbc_status = wbcGetpwnam(user, &pwd);
167 if (!WBC_ERROR_IS_OK(wbc_status)) {
171 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
174 (unsigned int)pwd->pw_uid,
175 (unsigned int)pwd->pw_gid,
183 /* pull pwent info for a given uid */
184 static bool wbinfo_get_uidinfo(int uid)
186 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
187 struct passwd *pwd = NULL;
189 wbc_status = wbcGetpwuid(uid, &pwd);
190 if (!WBC_ERROR_IS_OK(wbc_status)) {
194 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
197 (unsigned int)pwd->pw_uid,
198 (unsigned int)pwd->pw_gid,
206 static bool wbinfo_get_user_sidinfo(const char *sid_str)
208 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
209 struct passwd *pwd = NULL;
210 struct wbcDomainSid sid;
212 wbc_status = wbcStringToSid(sid_str, &sid);
213 wbc_status = wbcGetpwsid(&sid, &pwd);
214 if (!WBC_ERROR_IS_OK(wbc_status)) {
218 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
221 (unsigned int)pwd->pw_uid,
222 (unsigned int)pwd->pw_gid,
231 /* pull grent for a given group */
232 static bool wbinfo_get_groupinfo(const char *group)
234 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
238 wbc_status = wbcGetgrnam(group, &grp);
239 if (!WBC_ERROR_IS_OK(wbc_status)) {
243 d_printf("%s:%s:%u:",
246 (unsigned int)grp->gr_gid);
249 while (*mem != NULL) {
250 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
260 /* pull grent for a given gid */
261 static bool wbinfo_get_gidinfo(int gid)
263 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
267 wbc_status = wbcGetgrgid(gid, &grp);
268 if (!WBC_ERROR_IS_OK(wbc_status)) {
272 d_printf("%s:%s:%u:",
275 (unsigned int)grp->gr_gid);
278 while (*mem != NULL) {
279 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
289 /* List groups a user is a member of */
291 static bool wbinfo_get_usergroups(const char *user)
293 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
296 gid_t *groups = NULL;
300 wbc_status = wbcGetGroups(user, &num_groups, &groups);
301 if (!WBC_ERROR_IS_OK(wbc_status)) {
305 for (i = 0; i < num_groups; i++) {
306 d_printf("%d\n", (int)groups[i]);
309 wbcFreeMemory(groups);
315 /* List group SIDs a user SID is a member of */
316 static bool wbinfo_get_usersids(const char *user_sid_str)
318 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
321 struct wbcDomainSid user_sid, *sids = NULL;
325 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
326 if (!WBC_ERROR_IS_OK(wbc_status)) {
330 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
331 if (!WBC_ERROR_IS_OK(wbc_status)) {
335 for (i = 0; i < num_sids; i++) {
337 wbc_status = wbcSidToString(&sids[i], &str);
338 if (!WBC_ERROR_IS_OK(wbc_status)) {
342 d_printf("%s\n", str);
351 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
353 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
356 struct wbcDomainSid user_sid, *sids = NULL;
360 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
361 if (!WBC_ERROR_IS_OK(wbc_status)) {
365 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
366 if (!WBC_ERROR_IS_OK(wbc_status)) {
370 for (i = 0; i < num_sids; i++) {
372 wbc_status = wbcSidToString(&sids[i], &str);
373 if (!WBC_ERROR_IS_OK(wbc_status)) {
377 d_printf("%s\n", str);
386 static bool wbinfo_get_sidaliases(const char *domain,
387 const char *user_sid_str)
389 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
390 struct wbcDomainInfo *dinfo = NULL;
392 struct wbcDomainSid user_sid;
393 uint32_t *alias_rids = NULL;
394 uint32_t num_alias_rids;
395 char *domain_sid_str = NULL;
398 if ((domain == NULL) || (strequal(domain, ".")) ||
399 (domain[0] == '\0')) {
400 domain = get_winbind_domain();
405 wbc_status = wbcDomainInfo(domain, &dinfo);
406 if (!WBC_ERROR_IS_OK(wbc_status)) {
407 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
408 wbcErrorString(wbc_status));
411 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
412 if (!WBC_ERROR_IS_OK(wbc_status)) {
416 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
417 &alias_rids, &num_alias_rids);
418 if (!WBC_ERROR_IS_OK(wbc_status)) {
422 wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
423 if (!WBC_ERROR_IS_OK(wbc_status)) {
427 for (i = 0; i < num_alias_rids; i++) {
428 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
431 wbcFreeMemory(alias_rids);
434 if (domain_sid_str) {
435 wbcFreeMemory(domain_sid_str);
438 wbcFreeMemory(dinfo);
440 return (WBC_ERR_SUCCESS == wbc_status);
444 /* Convert NetBIOS name to IP */
446 static bool wbinfo_wins_byname(const char *name)
448 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
451 wbc_status = wbcResolveWinsByName(name, &ip);
452 if (!WBC_ERROR_IS_OK(wbc_status)) {
456 /* Display response */
458 d_printf("%s\n", ip);
465 /* Convert IP to NetBIOS name */
467 static bool wbinfo_wins_byip(const char *ip)
469 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
472 wbc_status = wbcResolveWinsByIP(ip, &name);
473 if (!WBC_ERROR_IS_OK(wbc_status)) {
477 /* Display response */
479 d_printf("%s\n", name);
486 /* List all/trusted domains */
488 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
490 struct wbcDomainInfo *domain_list = NULL;
492 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
493 bool print_all = !list_all_domains && verbose;
496 wbc_status = wbcListTrusts(&domain_list, &num_domains);
497 if (!WBC_ERROR_IS_OK(wbc_status)) {
502 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
503 "Domain Name", "DNS Domain", "Trust Type",
504 "Transitive", "In", "Out");
507 for (i=0; i<num_domains; i++) {
509 d_printf("%-16s", domain_list[i].short_name);
511 d_printf("%s", domain_list[i].short_name);
516 d_printf("%-24s", domain_list[i].dns_name);
518 switch(domain_list[i].trust_type) {
519 case WBC_DOMINFO_TRUSTTYPE_NONE:
522 case WBC_DOMINFO_TRUSTTYPE_FOREST:
525 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL:
526 d_printf("External ");
528 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST:
529 d_printf("In-Forest ");
533 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_TRANSITIVE) {
539 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_INCOMING) {
545 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_OUTGOING) {
557 /* List own domain */
559 static bool wbinfo_list_own_domain(void)
561 d_printf("%s\n", get_winbind_domain());
566 /* show sequence numbers */
567 static bool wbinfo_show_sequence(const char *domain)
569 d_printf("This command has been deprecated. Please use the "
570 "--online-status option instead.\n");
574 /* show sequence numbers */
575 static bool wbinfo_show_onlinestatus(const char *domain)
577 struct wbcDomainInfo *domain_list = NULL;
579 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
582 wbc_status = wbcListTrusts(&domain_list, &num_domains);
583 if (!WBC_ERROR_IS_OK(wbc_status)) {
587 for (i=0; i<num_domains; i++) {
591 if (!strequal(domain_list[i].short_name, domain)) {
596 is_offline = (domain_list[i].domain_flags &
597 WBC_DOMINFO_DOMAIN_OFFLINE);
599 d_printf("%s : %s\n",
600 domain_list[i].short_name,
601 is_offline ? "offline" : "online" );
608 /* Show domain info */
610 static bool wbinfo_domain_info(const char *domain)
612 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
613 struct wbcDomainInfo *dinfo = NULL;
614 char *sid_str = NULL;
616 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
617 domain = get_winbind_domain();
622 wbc_status = wbcDomainInfo(domain, &dinfo);
623 if (!WBC_ERROR_IS_OK(wbc_status)) {
627 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
628 if (!WBC_ERROR_IS_OK(wbc_status)) {
629 wbcFreeMemory(dinfo);
633 /* Display response */
635 d_printf("Name : %s\n", dinfo->short_name);
636 d_printf("Alt_Name : %s\n", dinfo->dns_name);
638 d_printf("SID : %s\n", sid_str);
640 d_printf("Active Directory : %s\n",
641 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No");
642 d_printf("Native : %s\n",
643 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ?
646 d_printf("Primary : %s\n",
647 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
650 wbcFreeMemory(sid_str);
651 wbcFreeMemory(dinfo);
656 /* Get a foreign DC's name */
657 static bool wbinfo_getdcname(const char *domain_name)
659 struct winbindd_request request;
660 struct winbindd_response response;
662 ZERO_STRUCT(request);
663 ZERO_STRUCT(response);
665 fstrcpy(request.domain_name, domain_name);
669 if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
670 &response) != NSS_STATUS_SUCCESS) {
671 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
675 /* Display response */
677 d_printf("%s\n", response.data.dc_name);
683 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
685 struct winbindd_request request;
686 struct winbindd_response response;
688 ZERO_STRUCT(request);
689 ZERO_STRUCT(response);
691 fstrcpy(request.data.dsgetdcname.domain_name, domain_name);
692 request.data.dsgetdcname.flags = flags;
694 request.flags |= DS_DIRECTORY_SERVICE_REQUIRED;
698 if (winbindd_request_response(WINBINDD_DSGETDCNAME, &request,
699 &response) != NSS_STATUS_SUCCESS) {
700 d_fprintf(stderr, "Could not find dc for %s\n", domain_name);
704 /* Display response */
706 d_printf("%s\n", response.data.dsgetdcname.dc_unc);
707 d_printf("%s\n", response.data.dsgetdcname.dc_address);
708 d_printf("%d\n", response.data.dsgetdcname.dc_address_type);
709 d_printf("%s\n", response.data.dsgetdcname.domain_guid);
710 d_printf("%s\n", response.data.dsgetdcname.domain_name);
711 d_printf("%s\n", response.data.dsgetdcname.forest_name);
712 d_printf("0x%08x\n", response.data.dsgetdcname.dc_flags);
713 d_printf("%s\n", response.data.dsgetdcname.dc_site_name);
714 d_printf("%s\n", response.data.dsgetdcname.client_site_name);
719 /* Check trust account password */
721 static bool wbinfo_check_secret(void)
723 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
724 struct wbcAuthErrorInfo *error = NULL;
726 wbc_status = wbcCheckTrustCredentials(NULL, &error);
728 d_printf("checking the trust secret via RPC calls %s\n",
729 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
731 if (wbc_status == WBC_ERR_AUTH_ERROR) {
732 d_fprintf(stderr, "error code was %s (0x%x)\n",
733 error->nt_string, error->nt_status);
734 wbcFreeMemory(error);
736 if (!WBC_ERROR_IS_OK(wbc_status)) {
743 /* Convert uid to sid */
745 static bool wbinfo_uid_to_sid(uid_t uid)
747 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
748 struct wbcDomainSid sid;
749 char *sid_str = NULL;
753 wbc_status = wbcUidToSid(uid, &sid);
754 if (!WBC_ERROR_IS_OK(wbc_status)) {
758 wbc_status = wbcSidToString(&sid, &sid_str);
759 if (!WBC_ERROR_IS_OK(wbc_status)) {
763 /* Display response */
765 d_printf("%s\n", sid_str);
767 wbcFreeMemory(sid_str);
772 /* Convert gid to sid */
774 static bool wbinfo_gid_to_sid(gid_t gid)
776 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
777 struct wbcDomainSid sid;
778 char *sid_str = NULL;
782 wbc_status = wbcGidToSid(gid, &sid);
783 if (!WBC_ERROR_IS_OK(wbc_status)) {
787 wbc_status = wbcSidToString(&sid, &sid_str);
788 if (!WBC_ERROR_IS_OK(wbc_status)) {
792 /* Display response */
794 d_printf("%s\n", sid_str);
796 wbcFreeMemory(sid_str);
801 /* Convert sid to uid */
803 static bool wbinfo_sid_to_uid(const char *sid_str)
805 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
806 struct wbcDomainSid sid;
811 wbc_status = wbcStringToSid(sid_str, &sid);
812 if (!WBC_ERROR_IS_OK(wbc_status)) {
816 wbc_status = wbcSidToUid(&sid, &uid);
817 if (!WBC_ERROR_IS_OK(wbc_status)) {
821 /* Display response */
823 d_printf("%d\n", (int)uid);
828 static bool wbinfo_sid_to_gid(const char *sid_str)
830 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
831 struct wbcDomainSid sid;
836 wbc_status = wbcStringToSid(sid_str, &sid);
837 if (!WBC_ERROR_IS_OK(wbc_status)) {
841 wbc_status = wbcSidToGid(&sid, &gid);
842 if (!WBC_ERROR_IS_OK(wbc_status)) {
846 /* Display response */
848 d_printf("%d\n", (int)gid);
853 static bool wbinfo_allocate_uid(void)
855 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
860 wbc_status = wbcAllocateUid(&uid);
861 if (!WBC_ERROR_IS_OK(wbc_status)) {
865 /* Display response */
867 d_printf("New uid: %u\n", (unsigned int)uid);
872 static bool wbinfo_allocate_gid(void)
874 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
879 wbc_status = wbcAllocateGid(&gid);
880 if (!WBC_ERROR_IS_OK(wbc_status)) {
884 /* Display response */
886 d_printf("New gid: %u\n", (unsigned int)gid);
891 static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str)
893 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
894 struct wbcDomainSid sid;
898 wbc_status = wbcStringToSid(sid_str, &sid);
899 if (!WBC_ERROR_IS_OK(wbc_status)) {
903 wbc_status = wbcSetUidMapping(uid, &sid);
904 if (!WBC_ERROR_IS_OK(wbc_status)) {
908 /* Display response */
910 d_printf("uid %u now mapped to sid %s\n",
911 (unsigned int)uid, sid_str);
916 static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str)
918 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
919 struct wbcDomainSid sid;
923 wbc_status = wbcStringToSid(sid_str, &sid);
924 if (!WBC_ERROR_IS_OK(wbc_status)) {
928 wbc_status = wbcSetGidMapping(gid, &sid);
929 if (!WBC_ERROR_IS_OK(wbc_status)) {
933 /* Display response */
935 d_printf("gid %u now mapped to sid %s\n",
936 (unsigned int)gid, sid_str);
941 static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
943 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
944 struct wbcDomainSid sid;
948 wbc_status = wbcStringToSid(sid_str, &sid);
949 if (!WBC_ERROR_IS_OK(wbc_status)) {
953 wbc_status = wbcRemoveUidMapping(uid, &sid);
954 if (!WBC_ERROR_IS_OK(wbc_status)) {
958 /* Display response */
960 d_printf("Removed uid %u to sid %s mapping\n",
961 (unsigned int)uid, sid_str);
966 static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
968 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
969 struct wbcDomainSid sid;
973 wbc_status = wbcStringToSid(sid_str, &sid);
974 if (!WBC_ERROR_IS_OK(wbc_status)) {
978 wbc_status = wbcRemoveGidMapping(gid, &sid);
979 if (!WBC_ERROR_IS_OK(wbc_status)) {
983 /* Display response */
985 d_printf("Removed gid %u to sid %s mapping\n",
986 (unsigned int)gid, sid_str);
991 /* Convert sid to string */
993 static bool wbinfo_lookupsid(const char *sid_str)
995 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
996 struct wbcDomainSid sid;
999 enum wbcSidType type;
1001 /* Send off request */
1003 wbc_status = wbcStringToSid(sid_str, &sid);
1004 if (!WBC_ERROR_IS_OK(wbc_status)) {
1008 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1009 if (!WBC_ERROR_IS_OK(wbc_status)) {
1013 /* Display response */
1015 d_printf("%s%c%s %d\n",
1016 domain, winbind_separator(), name, type);
1021 /* Convert sid to fullname */
1023 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1025 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1026 struct wbcDomainSid sid;
1029 enum wbcSidType type;
1031 /* Send off request */
1033 wbc_status = wbcStringToSid(sid_str, &sid);
1034 if (!WBC_ERROR_IS_OK(wbc_status)) {
1038 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1039 if (!WBC_ERROR_IS_OK(wbc_status)) {
1043 /* Display response */
1045 d_printf("%s%c%s %d\n",
1046 domain, winbind_separator(), name, type);
1051 /* Lookup a list of RIDs */
1053 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1055 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1056 struct wbcDomainInfo *dinfo = NULL;
1057 char *domain_name = NULL;
1058 const char **names = NULL;
1059 enum wbcSidType *types = NULL;
1062 uint32_t *rids = NULL;
1065 TALLOC_CTX *mem_ctx = NULL;
1068 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1069 domain = get_winbind_domain();
1074 wbc_status = wbcDomainInfo(domain, &dinfo);
1075 if (!WBC_ERROR_IS_OK(wbc_status)) {
1076 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1077 wbcErrorString(wbc_status));
1081 mem_ctx = talloc_new(NULL);
1082 if (mem_ctx == NULL) {
1083 d_printf("talloc_new failed\n");
1091 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1092 uint32_t rid = strtoul(ridstr, NULL, 10);
1093 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1095 d_printf("talloc_realloc failed\n");
1097 rids[num_rids] = rid;
1102 d_printf("no rids\n");
1106 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
1107 (const char **)&domain_name, &names, &types);
1108 if (!WBC_ERROR_IS_OK(wbc_status)) {
1109 d_printf("winbind_lookup_rids failed: %s\n",
1110 wbcErrorString(wbc_status));
1114 d_printf("Domain: %s\n", domain_name);
1116 for (i=0; i<num_rids; i++) {
1117 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1118 sid_type_lookup(types[i]));
1124 wbcFreeMemory(dinfo);
1127 wbcFreeMemory(domain_name);
1130 wbcFreeMemory(names);
1133 wbcFreeMemory(types);
1135 TALLOC_FREE(mem_ctx);
1139 /* Convert string to sid */
1141 static bool wbinfo_lookupname(const char *full_name)
1143 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1144 struct wbcDomainSid sid;
1146 enum wbcSidType type;
1147 fstring domain_name;
1148 fstring account_name;
1150 /* Send off request */
1152 parse_wbinfo_domain_user(full_name, domain_name,
1155 wbc_status = wbcLookupName(domain_name, account_name,
1157 if (!WBC_ERROR_IS_OK(wbc_status)) {
1161 wbc_status = wbcSidToString(&sid, &sid_str);
1162 if (!WBC_ERROR_IS_OK(wbc_status)) {
1166 /* Display response */
1168 d_printf("%s %s (%d)\n", sid_str, sid_type_lookup(type), type);
1170 wbcFreeMemory(sid_str);
1175 static char *wbinfo_prompt_pass(const char *prefix,
1176 const char *username)
1179 const char *ret = NULL;
1181 prompt = talloc_asprintf(talloc_tos(), "Enter %s's ", username);
1186 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1191 prompt = talloc_asprintf_append(prompt, "password: ");
1196 ret = getpass(prompt);
1197 TALLOC_FREE(prompt);
1199 return SMB_STRDUP(ret);
1202 /* Authenticate a user with a plaintext password */
1204 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1206 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1209 char *password = NULL;
1212 struct wbcLogonUserParams params;
1213 struct wbcLogonUserInfo *info;
1214 struct wbcAuthErrorInfo *error;
1215 struct wbcUserPasswordPolicyInfo *policy;
1217 if ((s = SMB_STRDUP(username)) == NULL) {
1221 if ((p = strchr(s, '%')) != NULL) {
1224 password = SMB_STRDUP(p);
1226 password = wbinfo_prompt_pass(NULL, username);
1233 params.username = name;
1234 params.password = password;
1235 params.num_blobs = 0;
1236 params.blobs = NULL;
1238 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1244 if (!WBC_ERROR_IS_OK(wbc_status)) {
1248 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1254 if (!WBC_ERROR_IS_OK(wbc_status)) {
1258 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1264 if (!WBC_ERROR_IS_OK(wbc_status)) {
1268 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1270 d_printf("plaintext kerberos password authentication for [%s] %s "
1271 "(requesting cctype: %s)\n",
1272 username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1277 "error code was %s (0x%x)\nerror messsage was: %s\n",
1280 error->display_string);
1283 if (WBC_ERROR_IS_OK(wbc_status)) {
1284 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1285 if (info && info->info && info->info->user_flags &
1286 NETLOGON_CACHED_ACCOUNT) {
1287 d_printf("user_flgs: "
1288 "NETLOGON_CACHED_ACCOUNT\n");
1294 for (i=0; i < info->num_blobs; i++) {
1295 if (strequal(info->blobs[i].name,
1297 d_printf("credentials were put "
1300 info->blobs[i].blob.data);
1305 d_printf("no credentials cached\n");
1311 SAFE_FREE(password);
1312 wbcFreeMemory(params.blobs);
1314 return WBC_ERROR_IS_OK(wbc_status);
1317 /* Authenticate a user with a plaintext password */
1319 static bool wbinfo_auth(char *username)
1321 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1324 char *password = NULL;
1327 if ((s = SMB_STRDUP(username)) == NULL) {
1331 if ((p = strchr(s, '%')) != NULL) {
1334 password = SMB_STRDUP(p);
1336 password = wbinfo_prompt_pass(NULL, username);
1341 wbc_status = wbcAuthenticateUser(name, password);
1343 d_printf("plaintext password authentication %s\n",
1344 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1347 if (response.data.auth.nt_status)
1349 "error code was %s (0x%x)\nerror messsage was: %s\n",
1350 response.data.auth.nt_status_string,
1351 response.data.auth.nt_status,
1352 response.data.auth.error_string);
1356 SAFE_FREE(password);
1358 return WBC_ERROR_IS_OK(wbc_status);
1361 /* Authenticate a user with a challenge/response */
1363 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1365 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1366 struct wbcAuthUserParams params;
1367 struct wbcAuthUserInfo *info = NULL;
1368 struct wbcAuthErrorInfo *err = NULL;
1369 DATA_BLOB lm = data_blob_null;
1370 DATA_BLOB nt = data_blob_null;
1372 fstring name_domain;
1376 p = strchr(username, '%');
1380 pass = SMB_STRDUP(p + 1);
1382 pass = wbinfo_prompt_pass(NULL, username);
1385 parse_wbinfo_domain_user(username, name_domain, name_user);
1387 params.account_name = name_user;
1388 params.domain_name = name_domain;
1389 params.workstation_name = NULL;
1392 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1393 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1395 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1397 generate_random_buffer(params.password.response.challenge, 8);
1400 DATA_BLOB server_chal;
1401 DATA_BLOB names_blob;
1403 server_chal = data_blob(params.password.response.challenge, 8);
1405 /* Pretend this is a login to 'us', for blob purposes */
1406 names_blob = NTLMv2_generate_names_blob(NULL,
1407 get_winbind_netbios_name(),
1408 get_winbind_domain());
1410 if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1413 &lm, &nt, NULL, NULL)) {
1414 data_blob_free(&names_blob);
1415 data_blob_free(&server_chal);
1419 data_blob_free(&names_blob);
1420 data_blob_free(&server_chal);
1425 lm = data_blob(NULL, 24);
1426 ok = SMBencrypt(pass,
1427 params.password.response.challenge,
1430 data_blob_free(&lm);
1433 nt = data_blob(NULL, 24);
1434 SMBNTencrypt(pass, params.password.response.challenge,
1438 params.password.response.nt_length = nt.length;
1439 params.password.response.nt_data = nt.data;
1440 params.password.response.lm_length = lm.length;
1441 params.password.response.lm_data = lm.data;
1443 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1445 /* Display response */
1447 d_printf("challenge/response password authentication %s\n",
1448 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1450 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1452 "error code was %s (0x%x)\nerror messsage was: %s\n",
1455 err->display_string);
1457 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1458 wbcFreeMemory(info);
1461 data_blob_free(&nt);
1462 data_blob_free(&lm);
1465 return WBC_ERROR_IS_OK(wbc_status);
1468 /* Authenticate a user with a plaintext password and set a token */
1470 static bool wbinfo_klog(char *username)
1472 struct winbindd_request request;
1473 struct winbindd_response response;
1477 /* Send off request */
1479 ZERO_STRUCT(request);
1480 ZERO_STRUCT(response);
1482 p = strchr(username, '%');
1486 fstrcpy(request.data.auth.user, username);
1487 fstrcpy(request.data.auth.pass, p + 1);
1490 fstrcpy(request.data.auth.user, username);
1491 fstrcpy(request.data.auth.pass, getpass("Password: "));
1494 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1496 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
1499 /* Display response */
1501 d_printf("plaintext password authentication %s\n",
1502 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1504 if (response.data.auth.nt_status)
1506 "error code was %s (0x%x)\nerror messsage was: %s\n",
1507 response.data.auth.nt_status_string,
1508 response.data.auth.nt_status,
1509 response.data.auth.error_string);
1511 if (result != NSS_STATUS_SUCCESS)
1514 if (response.extra_data.data == NULL) {
1515 d_fprintf(stderr, "Did not get token data\n");
1519 if (!afs_settoken_str((char *)response.extra_data.data)) {
1520 d_fprintf(stderr, "Could not set token\n");
1524 d_printf("Successfully created AFS token\n");
1528 /* Print domain users */
1530 static bool print_domain_users(const char *domain)
1532 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1534 uint32_t num_users = 0;
1535 const char **users = NULL;
1537 /* Send request to winbind daemon */
1539 /* '.' is the special sign for our own domain */
1540 if (domain && strcmp(domain, ".") == 0) {
1541 domain = get_winbind_domain();
1544 wbc_status = wbcListUsers(domain, &num_users, &users);
1545 if (!WBC_ERROR_IS_OK(wbc_status)) {
1549 for (i=0; i < num_users; i++) {
1550 d_printf("%s\n", users[i]);
1553 wbcFreeMemory(users);
1558 /* Print domain groups */
1560 static bool print_domain_groups(const char *domain)
1562 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1564 uint32_t num_groups = 0;
1565 const char **groups = NULL;
1567 /* Send request to winbind daemon */
1569 /* '.' is the special sign for our own domain */
1570 if (domain && strcmp(domain, ".") == 0) {
1571 domain = get_winbind_domain();
1574 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1575 if (!WBC_ERROR_IS_OK(wbc_status)) {
1579 for (i=0; i < num_groups; i++) {
1580 d_printf("%s\n", groups[i]);
1583 wbcFreeMemory(groups);
1588 /* Set the authorised user for winbindd access in secrets.tdb */
1590 static bool wbinfo_set_auth_user(char *username)
1592 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1593 "See 'net help setauthuser' for details.\n");
1597 static void wbinfo_get_auth_user(void)
1599 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1600 "See 'net help getauthuser' for details.\n");
1603 static bool wbinfo_ping(void)
1607 wbc_status = wbcPing();
1609 /* Display response */
1611 d_printf("Ping to winbindd %s\n",
1612 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1614 return WBC_ERROR_IS_OK(wbc_status);
1617 static bool wbinfo_change_user_password(const char *username)
1620 char *old_password = NULL;
1621 char *new_password = NULL;
1623 old_password = wbinfo_prompt_pass("old", username);
1624 new_password = wbinfo_prompt_pass("new", username);
1626 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
1628 /* Display response */
1630 d_printf("Password change for user %s %s\n", username,
1631 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1633 SAFE_FREE(old_password);
1634 SAFE_FREE(new_password);
1636 return WBC_ERROR_IS_OK(wbc_status);
1642 OPT_SET_AUTH_USER = 1000,
1653 OPT_SET_UID_MAPPING,
1654 OPT_SET_GID_MAPPING,
1655 OPT_REMOVE_UID_MAPPING,
1656 OPT_REMOVE_GID_MAPPING,
1658 OPT_LIST_ALL_DOMAINS,
1659 OPT_LIST_OWN_DOMAIN,
1666 OPT_CHANGE_USER_PASSWORD,
1667 OPT_SID_TO_FULLNAME,
1672 int main(int argc, char **argv, char **envp)
1675 TALLOC_CTX *frame = talloc_stackframe();
1677 static char *string_arg;
1678 char *string_subarg = NULL;
1679 static char *opt_domain_name;
1681 int int_subarg = -1;
1683 bool verbose = false;
1684 bool use_ntlmv2 = false;
1685 bool use_lanman = false;
1687 struct poptOption long_options[] = {
1690 /* longName, shortName, argInfo, argPtr, value, descrip,
1693 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1694 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1695 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1696 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1697 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1698 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1699 { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
1700 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
1701 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1702 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1703 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1704 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1705 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1706 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1707 "Get a new UID out of idmap" },
1708 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1709 "Get a new GID out of idmap" },
1710 { "set-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_UID_MAPPING, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1711 { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1712 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
1713 { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
1714 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1715 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1716 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1717 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1718 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1719 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
1720 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1721 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1722 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1723 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1724 { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" },
1725 { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" },
1726 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1727 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1728 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1729 { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" },
1730 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1731 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1732 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1733 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1734 "Get a DC name for a foreign domain", "domainname" },
1735 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1736 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1737 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1738 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1739 #ifdef WITH_FAKE_KASERVER
1740 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1743 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1744 /* destroys wbinfo --help output */
1745 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1747 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1748 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1749 { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
1750 { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
1751 { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
1752 POPT_COMMON_CONFIGFILE
1757 /* Samba client initialisation */
1763 pc = poptGetContext("wbinfo", argc, (const char **)argv,
1766 /* Parse command line options */
1769 poptPrintHelp(pc, stderr, 0);
1773 while((opt = poptGetNextOpt(pc)) != -1) {
1774 /* get the generic configuration parameters like --domain */
1788 poptFreeContext(pc);
1795 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1796 POPT_CONTEXT_KEEP_FIRST);
1798 while((opt = poptGetNextOpt(pc)) != -1) {
1801 if (!print_domain_users(opt_domain_name)) {
1803 "Error looking up domain users\n");
1808 if (!print_domain_groups(opt_domain_name)) {
1810 "Error looking up domain groups\n");
1815 if (!wbinfo_lookupsid(string_arg)) {
1817 "Could not lookup sid %s\n",
1822 case OPT_SID_TO_FULLNAME:
1823 if (!wbinfo_lookupsid_fullname(string_arg)) {
1824 d_fprintf(stderr, "Could not lookup sid %s\n",
1830 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
1831 d_fprintf(stderr, "Could not lookup RIDs %s\n",
1837 if (!wbinfo_lookupname(string_arg)) {
1838 d_fprintf(stderr, "Could not lookup name %s\n",
1844 if (!wbinfo_wins_byname(string_arg)) {
1846 "Could not lookup WINS by name %s\n",
1852 if (!wbinfo_wins_byip(string_arg)) {
1854 "Could not lookup WINS by IP %s\n",
1860 if (!wbinfo_uid_to_sid(int_arg)) {
1862 "Could not convert uid %d to sid\n",
1868 if (!wbinfo_gid_to_sid(int_arg)) {
1870 "Could not convert gid %d to sid\n",
1876 if (!wbinfo_sid_to_uid(string_arg)) {
1878 "Could not convert sid %s to uid\n",
1884 if (!wbinfo_sid_to_gid(string_arg)) {
1886 "Could not convert sid %s to gid\n",
1891 case OPT_ALLOCATE_UID:
1892 if (!wbinfo_allocate_uid()) {
1893 d_fprintf(stderr, "Could not allocate a uid\n");
1897 case OPT_ALLOCATE_GID:
1898 if (!wbinfo_allocate_gid()) {
1899 d_fprintf(stderr, "Could not allocate a gid\n");
1903 case OPT_SET_UID_MAPPING:
1904 if (!parse_mapping_arg(string_arg, &int_subarg,
1906 !wbinfo_set_uid_mapping(int_subarg, string_subarg))
1908 d_fprintf(stderr, "Could not create or modify "
1909 "uid to sid mapping\n");
1913 case OPT_SET_GID_MAPPING:
1914 if (!parse_mapping_arg(string_arg, &int_subarg,
1916 !wbinfo_set_gid_mapping(int_subarg, string_subarg))
1918 d_fprintf(stderr, "Could not create or modify "
1919 "gid to sid mapping\n");
1923 case OPT_REMOVE_UID_MAPPING:
1924 if (!parse_mapping_arg(string_arg, &int_subarg,
1926 !wbinfo_remove_uid_mapping(int_subarg,
1929 d_fprintf(stderr, "Could not remove uid to sid "
1934 case OPT_REMOVE_GID_MAPPING:
1935 if (!parse_mapping_arg(string_arg, &int_subarg,
1937 !wbinfo_remove_gid_mapping(int_subarg,
1940 d_fprintf(stderr, "Could not remove gid to sid "
1946 if (!wbinfo_check_secret()) {
1947 d_fprintf(stderr, "Could not check secret\n");
1952 if (!wbinfo_list_domains(false, verbose)) {
1954 "Could not list trusted domains\n");
1959 if (!wbinfo_show_sequence(opt_domain_name)) {
1961 "Could not show sequence numbers\n");
1965 case OPT_ONLINESTATUS:
1966 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
1968 "Could not show online-status\n");
1973 if (!wbinfo_domain_info(string_arg)) {
1975 "Could not get domain info\n");
1980 if (!wbinfo_get_userinfo(string_arg)) {
1982 "Could not get info for user %s\n",
1987 case OPT_USER_SIDINFO:
1988 if ( !wbinfo_get_user_sidinfo(string_arg)) {
1990 "Could not get info for user "
1991 "sid %s\n", string_arg);
1996 if ( !wbinfo_get_uidinfo(int_arg)) {
1997 d_fprintf(stderr, "Could not get info for uid "
2002 case OPT_GROUP_INFO:
2003 if ( !wbinfo_get_groupinfo(string_arg)) {
2004 d_fprintf(stderr, "Could not get info for "
2005 "group %s\n", string_arg);
2010 if ( !wbinfo_get_gidinfo(int_arg)) {
2011 d_fprintf(stderr, "Could not get info for gid "
2017 if (!wbinfo_get_usergroups(string_arg)) {
2019 "Could not get groups for user %s\n",
2025 if (!wbinfo_get_usersids(string_arg)) {
2026 d_fprintf(stderr, "Could not get group SIDs "
2027 "for user SID %s\n",
2032 case OPT_USERDOMGROUPS:
2033 if (!wbinfo_get_userdomgroups(string_arg)) {
2034 d_fprintf(stderr, "Could not get user's domain "
2035 "groups for user SID %s\n",
2040 case OPT_SIDALIASES:
2041 if (!wbinfo_get_sidaliases(opt_domain_name,
2043 d_fprintf(stderr, "Could not get sid aliases "
2044 "for user SID %s\n", string_arg);
2049 bool got_error = false;
2051 if (!wbinfo_auth(string_arg)) {
2053 "Could not authenticate user "
2054 "%s with plaintext "
2055 "password\n", string_arg);
2059 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
2062 "Could not authenticate user "
2063 "%s with challenge/response\n",
2073 uint32_t flags = WBFLAG_PAM_KRB5 |
2074 WBFLAG_PAM_CACHED_LOGIN |
2075 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
2076 WBFLAG_PAM_INFO3_TEXT |
2077 WBFLAG_PAM_CONTACT_TRUSTDOM;
2079 if (!wbinfo_auth_krb5(string_arg, "FILE",
2082 "Could not authenticate user "
2083 "[%s] with Kerberos "
2084 "(ccache: %s)\n", string_arg,
2091 if (!wbinfo_klog(string_arg)) {
2092 d_fprintf(stderr, "Could not klog user\n");
2097 if (!wbinfo_ping()) {
2098 d_fprintf(stderr, "could not ping winbindd!\n");
2102 case OPT_SET_AUTH_USER:
2103 if (!wbinfo_set_auth_user(string_arg)) {
2107 case OPT_GET_AUTH_USER:
2108 wbinfo_get_auth_user();
2112 if (!wbinfo_getdcname(string_arg)) {
2116 case OPT_DSGETDCNAME:
2117 if (!wbinfo_dsgetdcname(string_arg, 0)) {
2121 case OPT_SEPARATOR: {
2122 const char sep = winbind_separator();
2126 d_printf("%c\n", sep);
2129 case OPT_LIST_ALL_DOMAINS:
2130 if (!wbinfo_list_domains(true, verbose)) {
2134 case OPT_LIST_OWN_DOMAIN:
2135 if (!wbinfo_list_own_domain()) {
2139 case OPT_CHANGE_USER_PASSWORD:
2140 if (!wbinfo_change_user_password(string_arg)) {
2142 "Could not change user password "
2143 "for user %s\n", string_arg);
2148 /* generic configuration options */
2149 case OPT_DOMAIN_NAME:
2158 d_fprintf(stderr, "Invalid option\n");
2159 poptPrintHelp(pc, stderr, 0);
2169 talloc_destroy(frame);
2171 poptFreeContext(pc);