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(TALLOC_CTX *mem_ctx,
1177 const char *username)
1180 const char *ret = NULL;
1182 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1187 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1192 prompt = talloc_asprintf_append(prompt, "password: ");
1197 ret = getpass(prompt);
1198 TALLOC_FREE(prompt);
1200 return talloc_strdup(mem_ctx, ret);
1203 /* Authenticate a user with a plaintext password */
1205 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1207 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1210 char *password = NULL;
1213 struct wbcLogonUserParams params;
1214 struct wbcLogonUserInfo *info;
1215 struct wbcAuthErrorInfo *error;
1216 struct wbcUserPasswordPolicyInfo *policy;
1217 TALLOC_CTX *frame = talloc_tos();
1219 if ((s = talloc_strdup(frame, username)) == NULL) {
1223 if ((p = strchr(s, '%')) != NULL) {
1226 password = talloc_strdup(frame, p);
1228 password = wbinfo_prompt_pass(frame, NULL, username);
1235 params.username = name;
1236 params.password = password;
1237 params.num_blobs = 0;
1238 params.blobs = NULL;
1240 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1246 if (!WBC_ERROR_IS_OK(wbc_status)) {
1250 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1256 if (!WBC_ERROR_IS_OK(wbc_status)) {
1260 wbc_status = wbcAddNamedBlob(¶ms.num_blobs,
1266 if (!WBC_ERROR_IS_OK(wbc_status)) {
1270 wbc_status = wbcLogonUser(¶ms, &info, &error, &policy);
1272 d_printf("plaintext kerberos password authentication for [%s] %s "
1273 "(requesting cctype: %s)\n",
1274 username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1279 "error code was %s (0x%x)\nerror messsage was: %s\n",
1282 error->display_string);
1285 if (WBC_ERROR_IS_OK(wbc_status)) {
1286 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1287 if (info && info->info && info->info->user_flags &
1288 NETLOGON_CACHED_ACCOUNT) {
1289 d_printf("user_flgs: "
1290 "NETLOGON_CACHED_ACCOUNT\n");
1296 for (i=0; i < info->num_blobs; i++) {
1297 if (strequal(info->blobs[i].name,
1299 d_printf("credentials were put "
1302 info->blobs[i].blob.data);
1307 d_printf("no credentials cached\n");
1313 wbcFreeMemory(params.blobs);
1315 return WBC_ERROR_IS_OK(wbc_status);
1318 /* Authenticate a user with a plaintext password */
1320 static bool wbinfo_auth(char *username)
1322 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1325 char *password = NULL;
1327 TALLOC_CTX *frame = talloc_tos();
1329 if ((s = talloc_strdup(frame, username)) == NULL) {
1333 if ((p = strchr(s, '%')) != NULL) {
1336 password = talloc_strdup(frame, p);
1338 password = wbinfo_prompt_pass(frame, NULL, username);
1343 wbc_status = wbcAuthenticateUser(name, password);
1345 d_printf("plaintext password authentication %s\n",
1346 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1349 if (response.data.auth.nt_status)
1351 "error code was %s (0x%x)\nerror messsage was: %s\n",
1352 response.data.auth.nt_status_string,
1353 response.data.auth.nt_status,
1354 response.data.auth.error_string);
1359 return WBC_ERROR_IS_OK(wbc_status);
1362 /* Authenticate a user with a challenge/response */
1364 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1366 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1367 struct wbcAuthUserParams params;
1368 struct wbcAuthUserInfo *info = NULL;
1369 struct wbcAuthErrorInfo *err = NULL;
1370 DATA_BLOB lm = data_blob_null;
1371 DATA_BLOB nt = data_blob_null;
1373 fstring name_domain;
1376 TALLOC_CTX *frame = talloc_tos();
1378 p = strchr(username, '%');
1382 pass = talloc_strdup(frame, p + 1);
1384 pass = wbinfo_prompt_pass(frame, NULL, username);
1387 parse_wbinfo_domain_user(username, name_domain, name_user);
1389 params.account_name = name_user;
1390 params.domain_name = name_domain;
1391 params.workstation_name = NULL;
1394 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1395 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1397 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1399 generate_random_buffer(params.password.response.challenge, 8);
1402 DATA_BLOB server_chal;
1403 DATA_BLOB names_blob;
1405 server_chal = data_blob(params.password.response.challenge, 8);
1407 /* Pretend this is a login to 'us', for blob purposes */
1408 names_blob = NTLMv2_generate_names_blob(NULL,
1409 get_winbind_netbios_name(),
1410 get_winbind_domain());
1412 if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1415 &lm, &nt, NULL, NULL)) {
1416 data_blob_free(&names_blob);
1417 data_blob_free(&server_chal);
1421 data_blob_free(&names_blob);
1422 data_blob_free(&server_chal);
1427 lm = data_blob(NULL, 24);
1428 ok = SMBencrypt(pass,
1429 params.password.response.challenge,
1432 data_blob_free(&lm);
1435 nt = data_blob(NULL, 24);
1436 SMBNTencrypt(pass, params.password.response.challenge,
1440 params.password.response.nt_length = nt.length;
1441 params.password.response.nt_data = nt.data;
1442 params.password.response.lm_length = lm.length;
1443 params.password.response.lm_data = lm.data;
1445 wbc_status = wbcAuthenticateUserEx(¶ms, &info, &err);
1447 /* Display response */
1449 d_printf("challenge/response password authentication %s\n",
1450 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1452 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1454 "error code was %s (0x%x)\nerror messsage was: %s\n",
1457 err->display_string);
1459 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1460 wbcFreeMemory(info);
1463 data_blob_free(&nt);
1464 data_blob_free(&lm);
1467 return WBC_ERROR_IS_OK(wbc_status);
1470 /* Authenticate a user with a plaintext password and set a token */
1472 static bool wbinfo_klog(char *username)
1474 struct winbindd_request request;
1475 struct winbindd_response response;
1479 /* Send off request */
1481 ZERO_STRUCT(request);
1482 ZERO_STRUCT(response);
1484 p = strchr(username, '%');
1488 fstrcpy(request.data.auth.user, username);
1489 fstrcpy(request.data.auth.pass, p + 1);
1492 fstrcpy(request.data.auth.user, username);
1493 fstrcpy(request.data.auth.pass, getpass("Password: "));
1496 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1498 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
1501 /* Display response */
1503 d_printf("plaintext password authentication %s\n",
1504 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1506 if (response.data.auth.nt_status)
1508 "error code was %s (0x%x)\nerror messsage was: %s\n",
1509 response.data.auth.nt_status_string,
1510 response.data.auth.nt_status,
1511 response.data.auth.error_string);
1513 if (result != NSS_STATUS_SUCCESS)
1516 if (response.extra_data.data == NULL) {
1517 d_fprintf(stderr, "Did not get token data\n");
1521 if (!afs_settoken_str((char *)response.extra_data.data)) {
1522 d_fprintf(stderr, "Could not set token\n");
1526 d_printf("Successfully created AFS token\n");
1530 /* Print domain users */
1532 static bool print_domain_users(const char *domain)
1534 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1536 uint32_t num_users = 0;
1537 const char **users = NULL;
1539 /* Send request to winbind daemon */
1541 /* '.' is the special sign for our own domain */
1542 if (domain && strcmp(domain, ".") == 0) {
1543 domain = get_winbind_domain();
1546 wbc_status = wbcListUsers(domain, &num_users, &users);
1547 if (!WBC_ERROR_IS_OK(wbc_status)) {
1551 for (i=0; i < num_users; i++) {
1552 d_printf("%s\n", users[i]);
1555 wbcFreeMemory(users);
1560 /* Print domain groups */
1562 static bool print_domain_groups(const char *domain)
1564 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1566 uint32_t num_groups = 0;
1567 const char **groups = NULL;
1569 /* Send request to winbind daemon */
1571 /* '.' is the special sign for our own domain */
1572 if (domain && strcmp(domain, ".") == 0) {
1573 domain = get_winbind_domain();
1576 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1577 if (!WBC_ERROR_IS_OK(wbc_status)) {
1581 for (i=0; i < num_groups; i++) {
1582 d_printf("%s\n", groups[i]);
1585 wbcFreeMemory(groups);
1590 /* Set the authorised user for winbindd access in secrets.tdb */
1592 static bool wbinfo_set_auth_user(char *username)
1594 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1595 "See 'net help setauthuser' for details.\n");
1599 static void wbinfo_get_auth_user(void)
1601 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1602 "See 'net help getauthuser' for details.\n");
1605 static bool wbinfo_ping(void)
1609 wbc_status = wbcPing();
1611 /* Display response */
1613 d_printf("Ping to winbindd %s\n",
1614 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1616 return WBC_ERROR_IS_OK(wbc_status);
1619 static bool wbinfo_change_user_password(const char *username)
1622 char *old_password = NULL;
1623 char *new_password = NULL;
1624 TALLOC_CTX *frame = talloc_tos();
1626 old_password = wbinfo_prompt_pass(frame, "old", username);
1627 new_password = wbinfo_prompt_pass(frame, "new", username);
1629 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
1631 /* Display response */
1633 d_printf("Password change for user %s %s\n", username,
1634 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1638 return WBC_ERROR_IS_OK(wbc_status);
1644 OPT_SET_AUTH_USER = 1000,
1655 OPT_SET_UID_MAPPING,
1656 OPT_SET_GID_MAPPING,
1657 OPT_REMOVE_UID_MAPPING,
1658 OPT_REMOVE_GID_MAPPING,
1660 OPT_LIST_ALL_DOMAINS,
1661 OPT_LIST_OWN_DOMAIN,
1668 OPT_CHANGE_USER_PASSWORD,
1669 OPT_SID_TO_FULLNAME,
1674 int main(int argc, char **argv, char **envp)
1677 TALLOC_CTX *frame = talloc_stackframe();
1679 static char *string_arg;
1680 char *string_subarg = NULL;
1681 static char *opt_domain_name;
1683 int int_subarg = -1;
1685 bool verbose = false;
1686 bool use_ntlmv2 = false;
1687 bool use_lanman = false;
1689 struct poptOption long_options[] = {
1692 /* longName, shortName, argInfo, argPtr, value, descrip,
1695 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1696 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1697 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1698 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1699 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1700 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1701 { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
1702 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
1703 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1704 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1705 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1706 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1707 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1708 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1709 "Get a new UID out of idmap" },
1710 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1711 "Get a new GID out of idmap" },
1712 { "set-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_UID_MAPPING, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1713 { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1714 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
1715 { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
1716 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1717 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1718 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1719 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1720 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1721 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
1722 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1723 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1724 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1725 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1726 { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" },
1727 { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" },
1728 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1729 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1730 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1731 { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" },
1732 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1733 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1734 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1735 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1736 "Get a DC name for a foreign domain", "domainname" },
1737 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1738 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1739 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1740 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1741 #ifdef WITH_FAKE_KASERVER
1742 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1745 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1746 /* destroys wbinfo --help output */
1747 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1749 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1750 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1751 { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
1752 { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
1753 { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
1754 POPT_COMMON_CONFIGFILE
1759 /* Samba client initialisation */
1765 pc = poptGetContext("wbinfo", argc, (const char **)argv,
1768 /* Parse command line options */
1771 poptPrintHelp(pc, stderr, 0);
1775 while((opt = poptGetNextOpt(pc)) != -1) {
1776 /* get the generic configuration parameters like --domain */
1790 poptFreeContext(pc);
1797 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1798 POPT_CONTEXT_KEEP_FIRST);
1800 while((opt = poptGetNextOpt(pc)) != -1) {
1803 if (!print_domain_users(opt_domain_name)) {
1805 "Error looking up domain users\n");
1810 if (!print_domain_groups(opt_domain_name)) {
1812 "Error looking up domain groups\n");
1817 if (!wbinfo_lookupsid(string_arg)) {
1819 "Could not lookup sid %s\n",
1824 case OPT_SID_TO_FULLNAME:
1825 if (!wbinfo_lookupsid_fullname(string_arg)) {
1826 d_fprintf(stderr, "Could not lookup sid %s\n",
1832 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
1833 d_fprintf(stderr, "Could not lookup RIDs %s\n",
1839 if (!wbinfo_lookupname(string_arg)) {
1840 d_fprintf(stderr, "Could not lookup name %s\n",
1846 if (!wbinfo_wins_byname(string_arg)) {
1848 "Could not lookup WINS by name %s\n",
1854 if (!wbinfo_wins_byip(string_arg)) {
1856 "Could not lookup WINS by IP %s\n",
1862 if (!wbinfo_uid_to_sid(int_arg)) {
1864 "Could not convert uid %d to sid\n",
1870 if (!wbinfo_gid_to_sid(int_arg)) {
1872 "Could not convert gid %d to sid\n",
1878 if (!wbinfo_sid_to_uid(string_arg)) {
1880 "Could not convert sid %s to uid\n",
1886 if (!wbinfo_sid_to_gid(string_arg)) {
1888 "Could not convert sid %s to gid\n",
1893 case OPT_ALLOCATE_UID:
1894 if (!wbinfo_allocate_uid()) {
1895 d_fprintf(stderr, "Could not allocate a uid\n");
1899 case OPT_ALLOCATE_GID:
1900 if (!wbinfo_allocate_gid()) {
1901 d_fprintf(stderr, "Could not allocate a gid\n");
1905 case OPT_SET_UID_MAPPING:
1906 if (!parse_mapping_arg(string_arg, &int_subarg,
1908 !wbinfo_set_uid_mapping(int_subarg, string_subarg))
1910 d_fprintf(stderr, "Could not create or modify "
1911 "uid to sid mapping\n");
1915 case OPT_SET_GID_MAPPING:
1916 if (!parse_mapping_arg(string_arg, &int_subarg,
1918 !wbinfo_set_gid_mapping(int_subarg, string_subarg))
1920 d_fprintf(stderr, "Could not create or modify "
1921 "gid to sid mapping\n");
1925 case OPT_REMOVE_UID_MAPPING:
1926 if (!parse_mapping_arg(string_arg, &int_subarg,
1928 !wbinfo_remove_uid_mapping(int_subarg,
1931 d_fprintf(stderr, "Could not remove uid to sid "
1936 case OPT_REMOVE_GID_MAPPING:
1937 if (!parse_mapping_arg(string_arg, &int_subarg,
1939 !wbinfo_remove_gid_mapping(int_subarg,
1942 d_fprintf(stderr, "Could not remove gid to sid "
1948 if (!wbinfo_check_secret()) {
1949 d_fprintf(stderr, "Could not check secret\n");
1954 if (!wbinfo_list_domains(false, verbose)) {
1956 "Could not list trusted domains\n");
1961 if (!wbinfo_show_sequence(opt_domain_name)) {
1963 "Could not show sequence numbers\n");
1967 case OPT_ONLINESTATUS:
1968 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
1970 "Could not show online-status\n");
1975 if (!wbinfo_domain_info(string_arg)) {
1977 "Could not get domain info\n");
1982 if (!wbinfo_get_userinfo(string_arg)) {
1984 "Could not get info for user %s\n",
1989 case OPT_USER_SIDINFO:
1990 if ( !wbinfo_get_user_sidinfo(string_arg)) {
1992 "Could not get info for user "
1993 "sid %s\n", string_arg);
1998 if ( !wbinfo_get_uidinfo(int_arg)) {
1999 d_fprintf(stderr, "Could not get info for uid "
2004 case OPT_GROUP_INFO:
2005 if ( !wbinfo_get_groupinfo(string_arg)) {
2006 d_fprintf(stderr, "Could not get info for "
2007 "group %s\n", string_arg);
2012 if ( !wbinfo_get_gidinfo(int_arg)) {
2013 d_fprintf(stderr, "Could not get info for gid "
2019 if (!wbinfo_get_usergroups(string_arg)) {
2021 "Could not get groups for user %s\n",
2027 if (!wbinfo_get_usersids(string_arg)) {
2028 d_fprintf(stderr, "Could not get group SIDs "
2029 "for user SID %s\n",
2034 case OPT_USERDOMGROUPS:
2035 if (!wbinfo_get_userdomgroups(string_arg)) {
2036 d_fprintf(stderr, "Could not get user's domain "
2037 "groups for user SID %s\n",
2042 case OPT_SIDALIASES:
2043 if (!wbinfo_get_sidaliases(opt_domain_name,
2045 d_fprintf(stderr, "Could not get sid aliases "
2046 "for user SID %s\n", string_arg);
2051 bool got_error = false;
2053 if (!wbinfo_auth(string_arg)) {
2055 "Could not authenticate user "
2056 "%s with plaintext "
2057 "password\n", string_arg);
2061 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
2064 "Could not authenticate user "
2065 "%s with challenge/response\n",
2075 uint32_t flags = WBFLAG_PAM_KRB5 |
2076 WBFLAG_PAM_CACHED_LOGIN |
2077 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
2078 WBFLAG_PAM_INFO3_TEXT |
2079 WBFLAG_PAM_CONTACT_TRUSTDOM;
2081 if (!wbinfo_auth_krb5(string_arg, "FILE",
2084 "Could not authenticate user "
2085 "[%s] with Kerberos "
2086 "(ccache: %s)\n", string_arg,
2093 if (!wbinfo_klog(string_arg)) {
2094 d_fprintf(stderr, "Could not klog user\n");
2099 if (!wbinfo_ping()) {
2100 d_fprintf(stderr, "could not ping winbindd!\n");
2104 case OPT_SET_AUTH_USER:
2105 if (!wbinfo_set_auth_user(string_arg)) {
2109 case OPT_GET_AUTH_USER:
2110 wbinfo_get_auth_user();
2114 if (!wbinfo_getdcname(string_arg)) {
2118 case OPT_DSGETDCNAME:
2119 if (!wbinfo_dsgetdcname(string_arg, 0)) {
2123 case OPT_SEPARATOR: {
2124 const char sep = winbind_separator();
2128 d_printf("%c\n", sep);
2131 case OPT_LIST_ALL_DOMAINS:
2132 if (!wbinfo_list_domains(true, verbose)) {
2136 case OPT_LIST_OWN_DOMAIN:
2137 if (!wbinfo_list_own_domain()) {
2141 case OPT_CHANGE_USER_PASSWORD:
2142 if (!wbinfo_change_user_password(string_arg)) {
2144 "Could not change user password "
2145 "for user %s\n", string_arg);
2150 /* generic configuration options */
2151 case OPT_DOMAIN_NAME:
2160 d_fprintf(stderr, "Invalid option\n");
2161 poptPrintHelp(pc, stderr, 0);
2173 poptFreeContext(pc);