2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "libwbclient/wbclient.h"
26 #include "winbind_struct_protocol.h"
27 #include "libwbclient/wbclient_internal.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #include "lib/cmdline/cmdline.h"
30 #include "lib/afs/afs_settoken.h"
31 #include "lib/util/smb_strtox.h"
32 #include "lib/util/string_wrappers.h"
36 #define DBGC_CLASS DBGC_WINBIND
39 static struct wbcInterfaceDetails
*init_interface_details(void)
41 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
42 static struct wbcInterfaceDetails
*details
;
48 wbc_status
= wbcInterfaceDetails(&details
);
49 if (!WBC_ERROR_IS_OK(wbc_status
)) {
50 d_fprintf(stderr
, "could not obtain winbind interface "
51 "details: %s\n", wbcErrorString(wbc_status
));
57 static char winbind_separator(void)
59 struct wbcInterfaceDetails
*details
;
66 details
= init_interface_details();
69 d_fprintf(stderr
, "could not obtain winbind separator!\n");
73 sep
= details
->winbind_separator
;
77 d_fprintf(stderr
, "winbind separator was NULL!\n");
84 static const char *get_winbind_domain(void)
86 static struct wbcInterfaceDetails
*details
;
88 details
= init_interface_details();
91 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
95 return details
->netbios_domain
;
98 static const char *get_winbind_netbios_name(void)
100 static struct wbcInterfaceDetails
*details
;
102 details
= init_interface_details();
105 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
109 return details
->netbios_name
;
112 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
113 form DOMAIN/user into a domain and a user */
115 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
119 char *p
= strchr(domuser
,winbind_separator());
122 /* Maybe it was a UPN? */
123 p
= strchr(domuser
, '@');
126 fstrcpy(user
, domuser
);
130 fstrcpy(user
, domuser
);
131 fstrcpy(domain
, get_winbind_domain());
136 fstrcpy(domain
, domuser
);
137 domain
[PTR_DIFF(p
, domuser
)] = 0;
142 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
143 * Return true if input was valid, false otherwise. */
144 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
152 tmp
= strtok(arg
, ",");
153 *sid
= strtok(NULL
, ",");
155 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
158 /* Because atoi() can return 0 on invalid input, which would be a valid
159 * UID/GID we must use strtoul() and do error checking */
160 *id
= smb_strtoul(tmp
, NULL
, 10, &error
, SMB_STR_FULL_STR_CONV
);
167 /* pull pwent info for a given user */
169 static bool wbinfo_get_userinfo(char *user
)
171 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
172 struct passwd
*pwd
= NULL
;
174 wbc_status
= wbcGetpwnam(user
, &pwd
);
175 if (!WBC_ERROR_IS_OK(wbc_status
)) {
176 d_fprintf(stderr
, "failed to call wbcGetpwnam: %s\n",
177 wbcErrorString(wbc_status
));
181 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
184 (unsigned int)pwd
->pw_uid
,
185 (unsigned int)pwd
->pw_gid
,
195 /* pull pwent info for a given uid */
196 static bool wbinfo_get_uidinfo(int uid
)
198 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
199 struct passwd
*pwd
= NULL
;
201 wbc_status
= wbcGetpwuid(uid
, &pwd
);
202 if (!WBC_ERROR_IS_OK(wbc_status
)) {
203 d_fprintf(stderr
, "failed to call wbcGetpwuid: %s\n",
204 wbcErrorString(wbc_status
));
208 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
211 (unsigned int)pwd
->pw_uid
,
212 (unsigned int)pwd
->pw_gid
,
222 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
224 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
225 struct passwd
*pwd
= NULL
;
226 struct wbcDomainSid sid
;
228 wbc_status
= wbcStringToSid(sid_str
, &sid
);
229 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
230 if (!WBC_ERROR_IS_OK(wbc_status
)) {
231 d_fprintf(stderr
, "failed to call wbcGetpwsid: %s\n",
232 wbcErrorString(wbc_status
));
236 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
239 (unsigned int)pwd
->pw_uid
,
240 (unsigned int)pwd
->pw_gid
,
251 /* pull grent for a given group */
252 static bool wbinfo_get_groupinfo(const char *group
)
254 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
258 wbc_status
= wbcGetgrnam(group
, &grp
);
259 if (!WBC_ERROR_IS_OK(wbc_status
)) {
260 d_fprintf(stderr
, "failed to call wbcGetgrnam: %s\n",
261 wbcErrorString(wbc_status
));
265 d_printf("%s:%s:%u:",
268 (unsigned int)grp
->gr_gid
);
271 while (*mem
!= NULL
) {
272 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
282 /* pull grent for a given gid */
283 static bool wbinfo_get_gidinfo(int gid
)
285 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
289 wbc_status
= wbcGetgrgid(gid
, &grp
);
290 if (!WBC_ERROR_IS_OK(wbc_status
)) {
291 d_fprintf(stderr
, "failed to call wbcGetgrgid: %s\n",
292 wbcErrorString(wbc_status
));
296 d_printf("%s:%s:%u:",
299 (unsigned int)grp
->gr_gid
);
302 while (*mem
!= NULL
) {
303 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
313 /* List groups a user is a member of */
315 static bool wbinfo_get_usergroups(const char *user
)
317 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
320 gid_t
*groups
= NULL
;
324 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
325 if (!WBC_ERROR_IS_OK(wbc_status
)) {
326 d_fprintf(stderr
, "failed to call wbcGetGroups: %s\n",
327 wbcErrorString(wbc_status
));
331 for (i
= 0; i
< num_groups
; i
++) {
332 d_printf("%d\n", (int)groups
[i
]);
335 wbcFreeMemory(groups
);
341 /* List group SIDs a user SID is a member of */
342 static bool wbinfo_get_usersids(const char *user_sid_str
)
344 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
347 struct wbcDomainSid user_sid
, *sids
= NULL
;
351 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
352 if (!WBC_ERROR_IS_OK(wbc_status
)) {
353 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
354 wbcErrorString(wbc_status
));
358 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
359 if (!WBC_ERROR_IS_OK(wbc_status
)) {
360 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
361 wbcErrorString(wbc_status
));
365 for (i
= 0; i
< num_sids
; i
++) {
366 char str
[WBC_SID_STRING_BUFLEN
];
367 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
368 d_printf("%s\n", str
);
376 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
378 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
381 struct wbcDomainSid user_sid
, *sids
= NULL
;
385 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
386 if (!WBC_ERROR_IS_OK(wbc_status
)) {
387 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
388 wbcErrorString(wbc_status
));
392 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
393 if (!WBC_ERROR_IS_OK(wbc_status
)) {
394 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
395 wbcErrorString(wbc_status
));
399 for (i
= 0; i
< num_sids
; i
++) {
400 char str
[WBC_SID_STRING_BUFLEN
];
401 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
402 d_printf("%s\n", str
);
410 static bool wbinfo_get_sidaliases(const char *domain
,
411 const char *user_sid_str
)
413 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
414 struct wbcDomainInfo
*dinfo
= NULL
;
416 struct wbcDomainSid user_sid
;
417 uint32_t *alias_rids
= NULL
;
418 uint32_t num_alias_rids
;
419 char domain_sid_str
[WBC_SID_STRING_BUFLEN
];
422 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
423 (domain
[0] == '\0')) {
424 domain
= get_winbind_domain();
429 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
430 if (!WBC_ERROR_IS_OK(wbc_status
)) {
431 d_fprintf(stderr
, "wbcDomainInfo(%s) failed: %s\n", domain
,
432 wbcErrorString(wbc_status
));
435 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
436 if (!WBC_ERROR_IS_OK(wbc_status
)) {
440 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
441 &alias_rids
, &num_alias_rids
);
442 if (!WBC_ERROR_IS_OK(wbc_status
)) {
446 wbcSidToStringBuf(&dinfo
->sid
, domain_sid_str
, sizeof(domain_sid_str
));
448 for (i
= 0; i
< num_alias_rids
; i
++) {
449 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
452 wbcFreeMemory(alias_rids
);
455 wbcFreeMemory(dinfo
);
456 return (WBC_ERR_SUCCESS
== wbc_status
);
460 /* Convert NetBIOS name to IP */
462 static bool wbinfo_wins_byname(const char *name
)
464 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
467 wbc_status
= wbcResolveWinsByName(name
, &ip
);
468 if (!WBC_ERROR_IS_OK(wbc_status
)) {
469 d_fprintf(stderr
, "failed to call wbcResolveWinsByName: %s\n",
470 wbcErrorString(wbc_status
));
474 /* Display response */
476 d_printf("%s\n", ip
);
483 /* Convert IP to NetBIOS name */
485 static bool wbinfo_wins_byip(const char *ip
)
487 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
490 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
491 if (!WBC_ERROR_IS_OK(wbc_status
)) {
492 d_fprintf(stderr
, "failed to call wbcResolveWinsByIP: %s\n",
493 wbcErrorString(wbc_status
));
497 /* Display response */
499 d_printf("%s\n", name
);
506 /* List all/trusted domains */
508 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
510 struct wbcDomainInfo
*domain_list
= NULL
;
511 size_t i
, num_domains
;
512 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
513 bool print_all
= !list_all_domains
&& verbose
;
515 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
516 if (!WBC_ERROR_IS_OK(wbc_status
)) {
517 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
518 wbcErrorString(wbc_status
));
523 d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
524 "Domain Name", "DNS Domain", "Trust Type",
525 "Transitive", "In", "Out");
528 for (i
=0; i
<num_domains
; i
++) {
530 d_printf("%-16s", domain_list
[i
].short_name
);
532 d_printf("%s", domain_list
[i
].short_name
);
537 d_printf("%-65s", domain_list
[i
].dns_name
);
539 switch(domain_list
[i
].trust_type
) {
540 case WBC_DOMINFO_TRUSTTYPE_NONE
:
541 if (domain_list
[i
].trust_routing
!= NULL
) {
542 d_printf("%s\n", domain_list
[i
].trust_routing
);
547 case WBC_DOMINFO_TRUSTTYPE_LOCAL
:
550 case WBC_DOMINFO_TRUSTTYPE_RWDC
:
553 case WBC_DOMINFO_TRUSTTYPE_RODC
:
556 case WBC_DOMINFO_TRUSTTYPE_PDC
:
559 case WBC_DOMINFO_TRUSTTYPE_WKSTA
:
560 d_printf("Workstation ");
562 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
565 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
566 d_printf("External ");
568 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
569 d_printf("In-Forest ");
573 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
579 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
585 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
594 wbcFreeMemory(domain_list
);
599 /* List own domain */
601 static bool wbinfo_list_own_domain(void)
603 d_printf("%s\n", get_winbind_domain());
608 /* show sequence numbers */
609 static bool wbinfo_show_sequence(const char *domain
)
611 d_printf("This command has been deprecated. Please use the "
612 "--online-status option instead.\n");
616 /* show sequence numbers */
617 static bool wbinfo_show_onlinestatus(const char *domain
)
619 struct wbcDomainInfo
*domain_list
= NULL
;
620 size_t i
, num_domains
;
621 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
623 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
624 if (!WBC_ERROR_IS_OK(wbc_status
)) {
625 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
626 wbcErrorString(wbc_status
));
630 for (i
=0; i
<num_domains
; i
++) {
634 if (!strequal(domain_list
[i
].short_name
, domain
)) {
639 is_offline
= (domain_list
[i
].domain_flags
&
640 WBC_DOMINFO_DOMAIN_OFFLINE
);
642 d_printf("%s : %s\n",
643 domain_list
[i
].short_name
,
644 is_offline
? "no active connection" : "active connection" );
647 wbcFreeMemory(domain_list
);
653 /* Show domain info */
655 static bool wbinfo_domain_info(const char *domain
)
657 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
658 struct wbcDomainInfo
*dinfo
= NULL
;
659 char sid_str
[WBC_SID_STRING_BUFLEN
];
661 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
662 domain
= get_winbind_domain();
667 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
668 if (!WBC_ERROR_IS_OK(wbc_status
)) {
669 d_fprintf(stderr
, "failed to call wbcDomainInfo: %s\n",
670 wbcErrorString(wbc_status
));
674 wbcSidToStringBuf(&dinfo
->sid
, sid_str
, sizeof(sid_str
));
676 /* Display response */
678 d_printf("Name : %s\n", dinfo
->short_name
);
679 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
681 d_printf("SID : %s\n", sid_str
);
683 d_printf("Active Directory : %s\n",
684 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
685 d_printf("Native : %s\n",
686 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ?
689 d_printf("Primary : %s\n",
690 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ?
693 wbcFreeMemory(dinfo
);
698 /* Get a foreign DC's name */
699 static bool wbinfo_getdcname(const char *domain_name
)
701 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
702 struct winbindd_request request
;
703 struct winbindd_response response
;
705 ZERO_STRUCT(request
);
706 ZERO_STRUCT(response
);
708 fstrcpy(request
.domain_name
, domain_name
);
712 wbc_status
= wbcRequestResponse(NULL
, WINBINDD_GETDCNAME
,
713 &request
, &response
);
714 if (!WBC_ERROR_IS_OK(wbc_status
)) {
715 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
719 /* Display response */
721 d_printf("%s\n", response
.data
.dc_name
);
727 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
729 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
730 struct wbcDomainControllerInfoEx
*dc_info
;
733 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
734 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
736 if (!WBC_ERROR_IS_OK(wbc_status
)) {
737 printf("Could not find dc for %s\n", domain_name
);
741 wbcGuidToString(dc_info
->domain_guid
, &str
);
743 d_printf("%s\n", dc_info
->dc_unc
);
744 d_printf("%s\n", dc_info
->dc_address
);
745 d_printf("%d\n", dc_info
->dc_address_type
);
746 d_printf("%s\n", str
);
747 d_printf("%s\n", dc_info
->domain_name
);
748 d_printf("%s\n", dc_info
->forest_name
);
749 d_printf("0x%08x\n", dc_info
->dc_flags
);
750 d_printf("%s\n", dc_info
->dc_site_name
);
751 d_printf("%s\n", dc_info
->client_site_name
);
754 wbcFreeMemory(dc_info
);
759 /* Check trust account password */
761 static bool wbinfo_check_secret(const char *domain
)
763 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
764 struct wbcAuthErrorInfo
*error
= NULL
;
765 const char *domain_name
;
768 domain_name
= domain
;
770 domain_name
= get_winbind_domain();
773 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
775 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
777 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
779 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
780 d_fprintf(stderr
, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
781 domain_name
, error
->nt_string
, error
->nt_status
);
782 wbcFreeMemory(error
);
784 if (!WBC_ERROR_IS_OK(wbc_status
)) {
785 d_fprintf(stderr
, "failed to call wbcCheckTrustCredentials: "
786 "%s\n", wbcErrorString(wbc_status
));
793 /* Find the currently connected DCs */
795 static bool wbinfo_dc_info(const char *domain_name
)
797 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
799 const char **dc_names
, **dc_ips
;
801 wbc_status
= wbcDcInfo(domain_name
, &num_dcs
,
803 if (!WBC_ERROR_IS_OK(wbc_status
)) {
804 printf("Could not find dc info %s\n",
805 domain_name
? domain_name
: "our domain");
809 for (i
=0; i
<num_dcs
; i
++) {
810 printf("%s (%s)\n", dc_names
[i
], dc_ips
[i
]);
812 wbcFreeMemory(dc_names
);
813 wbcFreeMemory(dc_ips
);
818 /* Change trust account password */
820 static bool wbinfo_change_secret(const char *domain
)
822 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
823 struct wbcAuthErrorInfo
*error
= NULL
;
824 const char *domain_name
;
827 domain_name
= domain
;
829 domain_name
= get_winbind_domain();
832 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
834 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
836 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
838 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
839 d_fprintf(stderr
, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
840 domain_name
, error
->nt_string
, error
->nt_status
);
841 wbcFreeMemory(error
);
843 if (!WBC_ERROR_IS_OK(wbc_status
)) {
844 d_fprintf(stderr
, "failed to call wbcChangeTrustCredentials: "
845 "%s\n", wbcErrorString(wbc_status
));
852 /* Check DC connection */
854 static bool wbinfo_ping_dc(const char *domain
)
856 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
857 struct wbcAuthErrorInfo
*error
= NULL
;
860 const char *domain_name
;
863 domain_name
= domain
;
865 domain_name
= get_winbind_domain();
868 wbc_status
= wbcPingDc2(domain_name
, &error
, &dcname
);
870 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
871 domain_name
? domain_name
: "",
872 dcname
? dcname
: "",
873 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
875 wbcFreeMemory(dcname
);
876 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
877 d_fprintf(stderr
, "wbcPingDc2(%s): error code was %s (0x%x)\n",
878 domain_name
, error
->nt_string
, error
->nt_status
);
879 wbcFreeMemory(error
);
882 if (!WBC_ERROR_IS_OK(wbc_status
)) {
883 d_fprintf(stderr
, "failed to call wbcPingDc: %s\n",
884 wbcErrorString(wbc_status
));
891 /* Convert uid to sid */
893 static bool wbinfo_uid_to_sid(uid_t uid
)
895 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
896 struct wbcDomainSid sid
;
897 char sid_str
[WBC_SID_STRING_BUFLEN
];
901 wbc_status
= wbcUidToSid(uid
, &sid
);
902 if (!WBC_ERROR_IS_OK(wbc_status
)) {
903 d_fprintf(stderr
, "failed to call wbcUidToSid: %s\n",
904 wbcErrorString(wbc_status
));
908 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
910 /* Display response */
912 d_printf("%s\n", sid_str
);
917 /* Convert gid to sid */
919 static bool wbinfo_gid_to_sid(gid_t gid
)
921 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
922 struct wbcDomainSid sid
;
923 char sid_str
[WBC_SID_STRING_BUFLEN
];
927 wbc_status
= wbcGidToSid(gid
, &sid
);
928 if (!WBC_ERROR_IS_OK(wbc_status
)) {
929 d_fprintf(stderr
, "failed to call wbcGidToSid: %s\n",
930 wbcErrorString(wbc_status
));
934 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
936 /* Display response */
938 d_printf("%s\n", sid_str
);
943 /* Convert sid to uid */
945 static bool wbinfo_sid_to_uid(const char *sid_str
)
947 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
948 struct wbcDomainSid sid
;
953 wbc_status
= wbcStringToSid(sid_str
, &sid
);
954 if (!WBC_ERROR_IS_OK(wbc_status
)) {
955 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
956 wbcErrorString(wbc_status
));
960 wbc_status
= wbcSidToUid(&sid
, &uid
);
961 if (!WBC_ERROR_IS_OK(wbc_status
)) {
962 d_fprintf(stderr
, "failed to call wbcSidToUid: %s\n",
963 wbcErrorString(wbc_status
));
967 /* Display response */
969 d_printf("%d\n", (int)uid
);
974 static bool wbinfo_sid_to_gid(const char *sid_str
)
976 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
977 struct wbcDomainSid sid
;
982 wbc_status
= wbcStringToSid(sid_str
, &sid
);
983 if (!WBC_ERROR_IS_OK(wbc_status
)) {
984 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
985 wbcErrorString(wbc_status
));
989 wbc_status
= wbcSidToGid(&sid
, &gid
);
990 if (!WBC_ERROR_IS_OK(wbc_status
)) {
991 d_fprintf(stderr
, "failed to call wbcSidToGid: %s\n",
992 wbcErrorString(wbc_status
));
996 /* Display response */
998 d_printf("%d\n", (int)gid
);
1003 static bool wbinfo_sids_to_unix_ids(const char *arg
)
1005 char sidstr
[WBC_SID_STRING_BUFLEN
];
1006 struct wbcDomainSid
*sids
;
1007 struct wbcUnixId
*unix_ids
;
1017 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1018 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1021 d_fprintf(stderr
, "talloc failed\n");
1024 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1025 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1026 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1027 sidstr
, wbcErrorString(wbc_status
));
1034 unix_ids
= talloc_array(talloc_tos(), struct wbcUnixId
, num_sids
);
1035 if (unix_ids
== NULL
) {
1040 wbc_status
= wbcSidsToUnixIds(sids
, num_sids
, unix_ids
);
1041 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1042 d_fprintf(stderr
, "wbcSidsToUnixIds failed: %s\n",
1043 wbcErrorString(wbc_status
));
1048 for (i
=0; i
<num_sids
; i
++) {
1050 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1052 switch(unix_ids
[i
].type
) {
1053 case WBC_ID_TYPE_UID
:
1054 d_printf("%s -> uid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1056 case WBC_ID_TYPE_GID
:
1057 d_printf("%s -> gid %d\n", sidstr
, unix_ids
[i
].id
.gid
);
1059 case WBC_ID_TYPE_BOTH
:
1060 d_printf("%s -> uid/gid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1063 d_printf("%s -> unmapped\n", sidstr
);
1069 TALLOC_FREE(unix_ids
);
1074 static bool wbinfo_xids_to_sids(const char *arg
)
1077 struct wbcUnixId
*xids
= NULL
;
1078 struct wbcDomainSid
*sids
;
1086 while (next_token(&p
, idstr
, LIST_SEP
, sizeof(idstr
))) {
1087 xids
= talloc_realloc(talloc_tos(), xids
, struct wbcUnixId
,
1090 d_fprintf(stderr
, "talloc failed\n");
1096 xids
[num_xids
] = (struct wbcUnixId
) {
1097 .type
= WBC_ID_TYPE_UID
,
1098 .id
.uid
= atoi(&idstr
[1])
1102 xids
[num_xids
] = (struct wbcUnixId
) {
1103 .type
= WBC_ID_TYPE_GID
,
1104 .id
.gid
= atoi(&idstr
[1])
1108 d_fprintf(stderr
, "%s is an invalid id\n", idstr
);
1115 sids
= talloc_array(talloc_tos(), struct wbcDomainSid
, num_xids
);
1117 d_fprintf(stderr
, "talloc failed\n");
1122 wbc_status
= wbcUnixIdsToSids(xids
, num_xids
, sids
);
1123 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1124 d_fprintf(stderr
, "wbcUnixIdsToSids failed: %s\n",
1125 wbcErrorString(wbc_status
));
1131 for (i
=0; i
<num_xids
; i
++) {
1132 char str
[WBC_SID_STRING_BUFLEN
];
1133 struct wbcDomainSid null_sid
= { 0 };
1135 if (memcmp(&null_sid
, &sids
[i
], sizeof(struct wbcDomainSid
)) == 0) {
1136 d_printf("NOT MAPPED\n");
1139 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
1140 d_printf("%s\n", str
);
1146 static bool wbinfo_allocate_uid(void)
1148 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1153 wbc_status
= wbcAllocateUid(&uid
);
1154 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1155 d_fprintf(stderr
, "failed to call wbcAllocateUid: %s\n",
1156 wbcErrorString(wbc_status
));
1160 /* Display response */
1162 d_printf("New uid: %u\n", (unsigned int)uid
);
1167 static bool wbinfo_allocate_gid(void)
1169 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1174 wbc_status
= wbcAllocateGid(&gid
);
1175 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1176 d_fprintf(stderr
, "failed to call wbcAllocateGid: %s\n",
1177 wbcErrorString(wbc_status
));
1181 /* Display response */
1183 d_printf("New gid: %u\n", (unsigned int)gid
);
1188 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
1190 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1191 struct wbcDomainSid sid
;
1195 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1196 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1197 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1198 wbcErrorString(wbc_status
));
1202 wbc_status
= wbcSetUidMapping(uid
, &sid
);
1203 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1204 d_fprintf(stderr
, "failed to call wbcSetUidMapping: %s\n",
1205 wbcErrorString(wbc_status
));
1209 /* Display response */
1211 d_printf("uid %u now mapped to sid %s\n",
1212 (unsigned int)uid
, sid_str
);
1217 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
1219 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1220 struct wbcDomainSid sid
;
1224 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1225 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1226 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1227 wbcErrorString(wbc_status
));
1231 wbc_status
= wbcSetGidMapping(gid
, &sid
);
1232 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1233 d_fprintf(stderr
, "failed to call wbcSetGidMapping: %s\n",
1234 wbcErrorString(wbc_status
));
1238 /* Display response */
1240 d_printf("gid %u now mapped to sid %s\n",
1241 (unsigned int)gid
, sid_str
);
1246 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1248 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1249 struct wbcDomainSid sid
;
1253 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1254 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1255 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1256 wbcErrorString(wbc_status
));
1260 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1261 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1262 d_fprintf(stderr
, "failed to call wbcRemoveUidMapping: %s\n",
1263 wbcErrorString(wbc_status
));
1267 /* Display response */
1269 d_printf("Removed uid %u to sid %s mapping\n",
1270 (unsigned int)uid
, sid_str
);
1275 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1277 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1278 struct wbcDomainSid sid
;
1282 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1283 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1284 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1285 wbcErrorString(wbc_status
));
1289 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1290 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1291 d_fprintf(stderr
, "failed to call wbcRemoveGidMapping: %s\n",
1292 wbcErrorString(wbc_status
));
1296 /* Display response */
1298 d_printf("Removed gid %u to sid %s mapping\n",
1299 (unsigned int)gid
, sid_str
);
1304 /* Convert sid to string */
1306 static bool wbinfo_lookupsid(const char *sid_str
)
1308 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1309 struct wbcDomainSid sid
;
1312 enum wbcSidType type
;
1314 /* Send off request */
1316 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1317 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1318 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1319 wbcErrorString(wbc_status
));
1323 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1324 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1325 d_fprintf(stderr
, "failed to call wbcLookupSid: %s\n",
1326 wbcErrorString(wbc_status
));
1330 /* Display response */
1332 if (type
== WBC_SID_NAME_DOMAIN
) {
1333 d_printf("%s %d\n", domain
, type
);
1335 d_printf("%s%c%s %d\n",
1336 domain
, winbind_separator(), name
, type
);
1339 wbcFreeMemory(domain
);
1340 wbcFreeMemory(name
);
1345 /* Convert sid to fullname */
1347 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1349 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1350 struct wbcDomainSid sid
;
1353 enum wbcSidType type
;
1355 /* Send off request */
1357 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1358 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1359 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1360 wbcErrorString(wbc_status
));
1364 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1365 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1366 d_fprintf(stderr
, "failed to call wbcGetDisplayName: %s\n",
1367 wbcErrorString(wbc_status
));
1371 /* Display response */
1373 d_printf("%s%c%s %d\n",
1374 domain
, winbind_separator(), name
, type
);
1376 wbcFreeMemory(domain
);
1377 wbcFreeMemory(name
);
1382 /* Lookup a list of RIDs */
1384 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1386 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1387 struct wbcDomainSid dsid
;
1388 char *domain_name
= NULL
;
1389 const char **names
= NULL
;
1390 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();
1402 wbc_status
= wbcStringToSid(domain
, &dsid
);
1403 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1404 struct wbcDomainInfo
*dinfo
= NULL
;
1406 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1407 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1408 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1409 wbcErrorString(wbc_status
));
1414 wbcFreeMemory(dinfo
);
1417 mem_ctx
= talloc_new(NULL
);
1418 if (mem_ctx
== NULL
) {
1419 d_printf("talloc_new failed\n");
1427 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1431 rid
= smb_strtoul(ridstr
, NULL
, 10, &error
, SMB_STR_STANDARD
);
1433 d_printf("failed to convert rid\n");
1436 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1438 d_printf("talloc_realloc failed\n");
1440 rids
[num_rids
] = rid
;
1445 d_printf("no rids\n");
1449 wbc_status
= wbcLookupRids(
1450 &dsid
, num_rids
, rids
, &p
, &names
, &types
);
1451 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1452 d_printf("winbind_lookup_rids failed: %s\n",
1453 wbcErrorString(wbc_status
));
1457 domain_name
= discard_const_p(char, p
);
1458 d_printf("Domain: %s\n", domain_name
);
1460 for (i
=0; i
<num_rids
; i
++) {
1461 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1462 wbcSidTypeString(types
[i
]));
1467 wbcFreeMemory(domain_name
);
1468 wbcFreeMemory(names
);
1469 wbcFreeMemory(types
);
1470 TALLOC_FREE(mem_ctx
);
1474 static bool wbinfo_lookup_sids(const char *arg
)
1476 char sidstr
[WBC_SID_STRING_BUFLEN
];
1477 struct wbcDomainSid
*sids
;
1478 struct wbcDomainInfo
*domains
;
1479 struct wbcTranslatedName
*names
;
1490 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1491 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1494 d_fprintf(stderr
, "talloc failed\n");
1497 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1498 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1499 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1500 sidstr
, wbcErrorString(wbc_status
));
1507 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1509 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1510 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1511 wbcErrorString(wbc_status
));
1516 for (i
=0; i
<num_sids
; i
++) {
1517 const char *domain
= NULL
;
1519 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1521 if (names
[i
].domain_index
>= num_domains
) {
1523 } else if (names
[i
].domain_index
< 0) {
1526 domain
= domains
[names
[i
].domain_index
].short_name
;
1529 if (names
[i
].type
== WBC_SID_NAME_DOMAIN
) {
1530 d_printf("%s -> %s %d\n", sidstr
,
1534 d_printf("%s -> %s%c%s %d\n", sidstr
,
1536 winbind_separator(),
1537 names
[i
].name
, names
[i
].type
);
1540 wbcFreeMemory(names
);
1541 wbcFreeMemory(domains
);
1545 /* Convert string to sid */
1547 static bool wbinfo_lookupname(const char *full_name
)
1549 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1550 struct wbcDomainSid sid
;
1551 char sid_str
[WBC_SID_STRING_BUFLEN
];
1552 enum wbcSidType type
;
1553 fstring domain_name
;
1554 fstring account_name
;
1556 /* Send off request */
1558 parse_wbinfo_domain_user(full_name
, domain_name
,
1561 wbc_status
= wbcLookupName(domain_name
, account_name
,
1563 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1564 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1565 wbcErrorString(wbc_status
));
1569 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1571 /* Display response */
1573 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1578 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1580 const char *username
)
1583 char buf
[1024] = {0};
1586 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1591 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1596 prompt
= talloc_asprintf_append(prompt
, "password: ");
1601 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1602 TALLOC_FREE(prompt
);
1607 return talloc_strdup(mem_ctx
, buf
);
1610 /* Authenticate a user with a plaintext password */
1612 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1614 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1617 char *password
= NULL
;
1619 char *local_cctype
= NULL
;
1621 struct wbcLogonUserParams params
;
1622 struct wbcLogonUserInfo
*info
;
1623 struct wbcAuthErrorInfo
*error
;
1624 struct wbcUserPasswordPolicyInfo
*policy
;
1625 TALLOC_CTX
*frame
= talloc_tos();
1627 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1631 if ((p
= strchr(s
, '%')) != NULL
) {
1634 password
= talloc_strdup(frame
, p
);
1636 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1639 local_cctype
= talloc_strdup(frame
, cctype
);
1645 params
.username
= name
;
1646 params
.password
= password
;
1647 params
.num_blobs
= 0;
1648 params
.blobs
= NULL
;
1650 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1656 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1657 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1658 wbcErrorString(wbc_status
));
1662 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1668 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1669 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1670 wbcErrorString(wbc_status
));
1674 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1678 (uint8_t *)local_cctype
,
1680 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1681 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1682 wbcErrorString(wbc_status
));
1686 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1688 d_printf("plaintext kerberos password authentication for [%s] %s "
1689 "(requesting cctype: %s)\n",
1690 name
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1695 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1696 "error message was: %s\n",
1697 params
.username
, error
->nt_string
,
1699 error
->display_string
);
1702 if (WBC_ERROR_IS_OK(wbc_status
)) {
1703 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1704 if (info
&& info
->info
&& info
->info
->user_flags
&
1705 NETLOGON_CACHED_ACCOUNT
) {
1706 d_printf("user_flgs: "
1707 "NETLOGON_CACHED_ACCOUNT\n");
1713 for (i
=0; i
< info
->num_blobs
; i
++) {
1714 if (strequal(info
->blobs
[i
].name
,
1716 d_printf("credentials were put "
1719 info
->blobs
[i
].blob
.data
);
1724 d_printf("no credentials cached\n");
1729 wbcFreeMemory(params
.blobs
);
1731 return WBC_ERROR_IS_OK(wbc_status
);
1734 /* Authenticate a user with a plaintext password */
1736 static bool wbinfo_auth(char *username
)
1738 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1741 char *password
= NULL
;
1743 TALLOC_CTX
*frame
= talloc_tos();
1745 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1749 if ((p
= strchr(s
, '%')) != NULL
) {
1752 password
= talloc_strdup(frame
, p
);
1754 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1759 wbc_status
= wbcAuthenticateUser(name
, password
);
1761 d_printf("plaintext password authentication %s\n",
1762 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1765 if (response
.data
.auth
.nt_status
)
1767 "error code was %s (0x%x)\nerror message was: %s\n",
1768 response
.data
.auth
.nt_status_string
,
1769 response
.data
.auth
.nt_status
,
1770 response
.data
.auth
.error_string
);
1773 return WBC_ERROR_IS_OK(wbc_status
);
1776 /* Authenticate a user with a challenge/response */
1778 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1780 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1781 struct wbcAuthUserParams params
;
1782 struct wbcAuthUserInfo
*info
= NULL
;
1783 struct wbcAuthErrorInfo
*err
= NULL
;
1784 DATA_BLOB lm
= data_blob_null
;
1785 DATA_BLOB nt
= data_blob_null
;
1787 fstring name_domain
;
1790 TALLOC_CTX
*frame
= talloc_tos();
1792 p
= strchr(username
, '%');
1796 pass
= talloc_strdup(frame
, p
+ 1);
1798 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1801 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1803 params
.account_name
= name_user
;
1804 params
.domain_name
= name_domain
;
1805 params
.workstation_name
= NULL
;
1808 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1809 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1811 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1813 generate_random_buffer(params
.password
.response
.challenge
, 8);
1816 DATA_BLOB server_chal
;
1817 DATA_BLOB names_blob
;
1818 const char *netbios_name
= NULL
;
1819 const char *domain
= NULL
;
1821 netbios_name
= get_winbind_netbios_name(),
1822 domain
= get_winbind_domain();
1823 if (domain
== NULL
) {
1824 d_fprintf(stderr
, "Failed to get domain from winbindd\n");
1828 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1830 /* Pretend this is a login to 'us', for blob purposes */
1831 names_blob
= NTLMv2_generate_names_blob(NULL
,
1836 !SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1839 &lm
, &nt
, NULL
, NULL
)) {
1840 data_blob_free(&names_blob
);
1841 data_blob_free(&server_chal
);
1845 data_blob_free(&names_blob
);
1846 data_blob_free(&server_chal
);
1851 lm
= data_blob(NULL
, 24);
1852 ok
= SMBencrypt(pass
,
1853 params
.password
.response
.challenge
,
1856 data_blob_free(&lm
);
1859 nt
= data_blob(NULL
, 24);
1860 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1864 params
.password
.response
.nt_length
= nt
.length
;
1865 params
.password
.response
.nt_data
= nt
.data
;
1866 params
.password
.response
.lm_length
= lm
.length
;
1867 params
.password
.response
.lm_data
= lm
.data
;
1869 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1871 /* Display response */
1873 d_printf("challenge/response password authentication %s\n",
1874 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1876 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1878 "wbcAuthenticateUserEx(%s%c%s): error code was "
1879 "%s (0x%x, authoritative=%"PRIu8
")\n"
1880 "error message was: %s\n",
1882 winbind_separator(),
1887 err
->display_string
);
1889 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1890 wbcFreeMemory(info
);
1893 data_blob_free(&nt
);
1894 data_blob_free(&lm
);
1896 return WBC_ERROR_IS_OK(wbc_status
);
1899 /* Authenticate a user with a plaintext password */
1901 static bool wbinfo_pam_logon(char *username
, bool verbose
)
1903 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1904 struct wbcLogonUserParams params
;
1905 struct wbcLogonUserInfo
*info
= NULL
;
1906 struct wbcAuthErrorInfo
*error
= NULL
;
1909 TALLOC_CTX
*frame
= talloc_tos();
1913 ZERO_STRUCT(params
);
1915 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1919 if ((p
= strchr(s
, '%')) != NULL
) {
1922 params
.password
= talloc_strdup(frame
, p
);
1924 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1926 params
.username
= s
;
1928 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1930 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1932 (uint8_t *)&flags
, sizeof(flags
));
1933 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1934 d_printf("wbcAddNamedBlob failed: %s\n",
1935 wbcErrorString(wbc_status
));
1941 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1943 (uint8_t *)&uid
, sizeof(uid
));
1944 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1945 d_printf("wbcAddNamedBlob failed: %s\n",
1946 wbcErrorString(wbc_status
));
1950 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, NULL
);
1952 if (verbose
&& (info
!= NULL
)) {
1953 struct wbcAuthUserInfo
*i
= info
->info
;
1956 if (i
->account_name
!= NULL
) {
1957 d_printf("account_name: %s\n", i
->account_name
);
1959 if (i
->user_principal
!= NULL
) {
1960 d_printf("user_principal: %s\n", i
->user_principal
);
1962 if (i
->full_name
!= NULL
) {
1963 d_printf("full_name: %s\n", i
->full_name
);
1965 if (i
->domain_name
!= NULL
) {
1966 d_printf("domain_name: %s\n", i
->domain_name
);
1968 if (i
->dns_domain_name
!= NULL
) {
1969 d_printf("dns_domain_name: %s\n", i
->dns_domain_name
);
1971 if (i
->logon_server
!= NULL
) {
1972 d_printf("logon_server: %s\n", i
->logon_server
);
1974 if (i
->logon_script
!= NULL
) {
1975 d_printf("logon_script: %s\n", i
->logon_script
);
1977 if (i
->profile_path
!= NULL
) {
1978 d_printf("profile_path: %s\n", i
->profile_path
);
1980 if (i
->home_directory
!= NULL
) {
1981 d_printf("home_directory: %s\n", i
->home_directory
);
1983 if (i
->home_drive
!= NULL
) {
1984 d_printf("home_drive: %s\n", i
->home_drive
);
1989 for (j
=0; j
<i
->num_sids
; j
++) {
1990 char buf
[WBC_SID_STRING_BUFLEN
];
1991 wbcSidToStringBuf(&i
->sids
[j
].sid
, buf
, sizeof(buf
));
1992 d_printf(" %s", buf
);
1996 wbcFreeMemory(info
);
2000 wbcFreeMemory(params
.blobs
);
2002 d_printf("plaintext password authentication %s\n",
2003 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2005 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
2007 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2008 "error message was: %s\n",
2011 (int)error
->nt_status
,
2012 error
->display_string
);
2013 wbcFreeMemory(error
);
2015 return WBC_ERROR_IS_OK(wbc_status
);
2018 /* Save creds with winbind */
2020 static bool wbinfo_ccache_save(char *username
)
2022 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2025 char *password
= NULL
;
2027 TALLOC_CTX
*frame
= talloc_stackframe();
2029 s
= talloc_strdup(frame
, username
);
2038 password
= talloc_strdup(frame
, p
);
2040 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
2045 wbc_status
= wbcCredentialSave(name
, password
);
2047 d_printf("saving creds %s\n",
2048 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2052 return WBC_ERROR_IS_OK(wbc_status
);
2055 #ifdef WITH_FAKE_KASERVER
2056 /* Authenticate a user with a plaintext password and set a token */
2058 static bool wbinfo_klog(char *username
)
2060 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2061 struct winbindd_request request
;
2062 struct winbindd_response response
;
2065 /* Send off request */
2067 ZERO_STRUCT(request
);
2068 ZERO_STRUCT(response
);
2070 p
= strchr(username
, '%');
2074 fstrcpy(request
.data
.auth
.user
, username
);
2075 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
2078 fstrcpy(request
.data
.auth
.user
, username
);
2079 (void) samba_getpass("Password: ",
2080 request
.data
.auth
.pass
,
2081 sizeof(request
.data
.auth
.pass
),
2085 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
2087 wbc_status
= wbcRequestResponse(NULL
, WINBINDD_PAM_AUTH
,
2088 &request
, &response
);
2090 /* Display response */
2092 d_printf("plaintext password authentication %s\n",
2093 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2095 if (response
.data
.auth
.nt_status
)
2097 "error code was %s (0x%x)\nerror message was: %s\n",
2098 response
.data
.auth
.nt_status_string
,
2099 response
.data
.auth
.nt_status
,
2100 response
.data
.auth
.error_string
);
2102 if (!WBC_ERROR_IS_OK(wbc_status
))
2105 if (response
.extra_data
.data
== NULL
) {
2106 d_fprintf(stderr
, "Did not get token data\n");
2110 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
2111 winbindd_free_response(&response
);
2112 d_fprintf(stderr
, "Could not set token\n");
2116 winbindd_free_response(&response
);
2117 d_printf("Successfully created AFS token\n");
2121 static bool wbinfo_klog(char *username
)
2123 d_fprintf(stderr
, "No AFS support compiled in.\n");
2128 /* Print domain users */
2130 static bool print_domain_users(const char *domain
)
2132 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2134 uint32_t num_users
= 0;
2135 const char **users
= NULL
;
2137 /* Send request to winbind daemon */
2139 if (domain
== NULL
) {
2140 domain
= get_winbind_domain();
2142 /* '.' is the special sign for our own domain */
2143 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2144 domain
= get_winbind_domain();
2145 /* '*' is the special sign for all domains */
2146 } else if (strcmp(domain
, "*") == 0) {
2151 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
2152 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2156 for (i
=0; i
< num_users
; i
++) {
2157 d_printf("%s\n", users
[i
]);
2160 wbcFreeMemory(users
);
2165 /* Print domain groups */
2167 static bool print_domain_groups(const char *domain
)
2169 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2171 uint32_t num_groups
= 0;
2172 const char **groups
= NULL
;
2174 /* Send request to winbind daemon */
2176 if (domain
== NULL
) {
2177 domain
= get_winbind_domain();
2179 /* '.' is the special sign for our own domain */
2180 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2181 domain
= get_winbind_domain();
2182 /* '*' is the special sign for all domains */
2183 } else if (strcmp(domain
, "*") == 0) {
2188 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
2189 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2190 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
2191 wbcErrorString(wbc_status
));
2195 for (i
=0; i
< num_groups
; i
++) {
2196 d_printf("%s\n", groups
[i
]);
2199 wbcFreeMemory(groups
);
2204 /* Set the authorised user for winbindd access in secrets.tdb */
2206 static bool wbinfo_set_auth_user(char *username
)
2208 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2209 "See 'net help setauthuser' for details.\n");
2213 static void wbinfo_get_auth_user(void)
2215 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2216 "See 'net help getauthuser' for details.\n");
2219 static bool wbinfo_ping(void)
2223 wbc_status
= wbcPing();
2225 /* Display response */
2227 d_printf("Ping to winbindd %s\n",
2228 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2230 return WBC_ERROR_IS_OK(wbc_status
);
2233 static bool wbinfo_change_user_password(const char *username
)
2236 char *old_password
= NULL
;
2237 char *new_password
= NULL
;
2238 TALLOC_CTX
*frame
= talloc_tos();
2240 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2241 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2243 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2245 /* Display response */
2247 d_printf("Password change for user %s %s\n", username
,
2248 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2250 return WBC_ERROR_IS_OK(wbc_status
);
2256 OPT_SET_AUTH_USER
= 1000,
2269 OPT_SET_UID_MAPPING
,
2270 OPT_SET_GID_MAPPING
,
2271 OPT_REMOVE_UID_MAPPING
,
2272 OPT_REMOVE_GID_MAPPING
,
2276 OPT_LIST_ALL_DOMAINS
,
2277 OPT_LIST_OWN_DOMAIN
,
2284 OPT_CHANGE_USER_PASSWORD
,
2286 OPT_SID_TO_FULLNAME
,
2297 int main(int argc
, const char **argv
, char **envp
)
2300 TALLOC_CTX
*frame
= talloc_stackframe();
2302 static char *string_arg
;
2303 char *string_subarg
= NULL
;
2304 static char *opt_domain_name
;
2306 int int_subarg
= -1;
2308 bool verbose
= false;
2309 bool use_ntlmv2
= true;
2310 bool use_lanman
= false;
2311 char *logoff_user
= getenv("USER");
2312 int logoff_uid
= geteuid();
2313 const char *opt_krb5ccname
= "FILE";
2315 struct poptOption long_options
[] = {
2318 /* longName, shortName, argInfo, argPtr, value, descrip,
2322 .longName
= "domain-users",
2324 .argInfo
= POPT_ARG_NONE
,
2326 .descrip
= "Lists all domain users",
2327 .argDescrip
= "domain"
2330 .longName
= "domain-groups",
2332 .argInfo
= POPT_ARG_NONE
,
2334 .descrip
= "Lists all domain groups",
2335 .argDescrip
= "domain"
2338 .longName
= "WINS-by-name",
2340 .argInfo
= POPT_ARG_STRING
,
2343 .descrip
= "Converts NetBIOS name to IP",
2344 .argDescrip
= "NETBIOS-NAME"
2347 .longName
= "WINS-by-ip",
2349 .argInfo
= POPT_ARG_STRING
,
2352 .descrip
= "Converts IP address to NetBIOS name",
2356 .longName
= "name-to-sid",
2358 .argInfo
= POPT_ARG_STRING
,
2361 .descrip
= "Converts name to sid",
2362 .argDescrip
= "NAME"
2365 .longName
= "sid-to-name",
2367 .argInfo
= POPT_ARG_STRING
,
2370 .descrip
= "Converts sid to name",
2374 .longName
= "sid-to-fullname",
2375 .argInfo
= POPT_ARG_STRING
,
2377 .val
= OPT_SID_TO_FULLNAME
,
2378 .descrip
= "Converts sid to fullname",
2382 .longName
= "lookup-rids",
2384 .argInfo
= POPT_ARG_STRING
,
2387 .descrip
= "Converts RIDs to names",
2388 .argDescrip
= "RIDs"
2391 .longName
= "lookup-sids",
2392 .argInfo
= POPT_ARG_STRING
,
2394 .val
= OPT_LOOKUP_SIDS
,
2395 .descrip
= "Converts SIDs to types and names",
2396 .argDescrip
= "Sid-List"
2399 .longName
= "uid-to-sid",
2401 .argInfo
= POPT_ARG_INT
,
2404 .descrip
= "Converts uid to sid",
2408 .longName
= "gid-to-sid",
2410 .argInfo
= POPT_ARG_INT
,
2413 .descrip
= "Converts gid to sid",
2417 .longName
= "sid-to-uid",
2419 .argInfo
= POPT_ARG_STRING
,
2422 .descrip
= "Converts sid to uid",
2426 .longName
= "sid-to-gid",
2428 .argInfo
= POPT_ARG_STRING
,
2431 .descrip
= "Converts sid to gid",
2435 .longName
= "allocate-uid",
2436 .argInfo
= POPT_ARG_NONE
,
2437 .val
= OPT_ALLOCATE_UID
,
2438 .descrip
= "Get a new UID out of idmap"
2441 .longName
= "allocate-gid",
2442 .argInfo
= POPT_ARG_NONE
,
2443 .val
= OPT_ALLOCATE_GID
,
2444 .descrip
= "Get a new GID out of idmap"
2447 .longName
= "set-uid-mapping",
2448 .argInfo
= POPT_ARG_STRING
,
2450 .val
= OPT_SET_UID_MAPPING
,
2451 .descrip
= "Create or modify uid to sid mapping in "
2453 .argDescrip
= "UID,SID"
2456 .longName
= "set-gid-mapping",
2457 .argInfo
= POPT_ARG_STRING
,
2459 .val
= OPT_SET_GID_MAPPING
,
2460 .descrip
= "Create or modify gid to sid mapping in "
2462 .argDescrip
= "GID,SID"
2465 .longName
= "remove-uid-mapping",
2466 .argInfo
= POPT_ARG_STRING
,
2468 .val
= OPT_REMOVE_UID_MAPPING
,
2469 .descrip
= "Remove uid to sid mapping in idmap",
2470 .argDescrip
= "UID,SID"
2473 .longName
= "remove-gid-mapping",
2474 .argInfo
= POPT_ARG_STRING
,
2476 .val
= OPT_REMOVE_GID_MAPPING
,
2477 .descrip
= "Remove gid to sid mapping in idmap",
2478 .argDescrip
= "GID,SID",
2481 .longName
= "sids-to-unix-ids",
2482 .argInfo
= POPT_ARG_STRING
,
2484 .val
= OPT_SIDS_TO_XIDS
,
2485 .descrip
= "Translate SIDs to Unix IDs",
2486 .argDescrip
= "Sid-List",
2489 .longName
= "unix-ids-to-sids",
2490 .argInfo
= POPT_ARG_STRING
,
2492 .val
= OPT_XIDS_TO_SIDS
,
2493 .descrip
= "Translate Unix IDs to SIDs",
2494 .argDescrip
= "ID-List (u<num> g<num>)",
2497 .longName
= "check-secret",
2499 .argInfo
= POPT_ARG_NONE
,
2501 .descrip
= "Check shared secret",
2504 .longName
= "change-secret",
2506 .argInfo
= POPT_ARG_NONE
,
2508 .descrip
= "Change shared secret",
2511 .longName
= "ping-dc",
2513 .argInfo
= POPT_ARG_NONE
,
2515 .descrip
= "Check the NETLOGON connection",
2518 .longName
= "trusted-domains",
2520 .argInfo
= POPT_ARG_NONE
,
2522 .descrip
= "List trusted domains",
2525 .longName
= "all-domains",
2526 .argInfo
= POPT_ARG_NONE
,
2527 .val
= OPT_LIST_ALL_DOMAINS
,
2528 .descrip
= "List all domains (trusted and own "
2532 .longName
= "own-domain",
2533 .argInfo
= POPT_ARG_NONE
,
2534 .val
= OPT_LIST_OWN_DOMAIN
,
2535 .descrip
= "List own domain",
2538 .longName
= "sequence",
2539 .argInfo
= POPT_ARG_NONE
,
2540 .val
= OPT_SEQUENCE
,
2541 .descrip
= "Deprecated command, see --online-status",
2544 .longName
= "online-status",
2545 .argInfo
= POPT_ARG_NONE
,
2546 .val
= OPT_ONLINESTATUS
,
2547 .descrip
= "Show whether domains maintain an active "
2551 .longName
= "domain-info",
2553 .argInfo
= POPT_ARG_STRING
,
2556 .descrip
= "Show most of the info we have about the "
2560 .longName
= "user-info",
2562 .argInfo
= POPT_ARG_STRING
,
2565 .descrip
= "Get user info",
2566 .argDescrip
= "USER",
2569 .longName
= "uid-info",
2570 .argInfo
= POPT_ARG_INT
,
2572 .val
= OPT_UID_INFO
,
2573 .descrip
= "Get user info from uid",
2574 .argDescrip
= "UID",
2577 .longName
= "group-info",
2578 .argInfo
= POPT_ARG_STRING
,
2580 .val
= OPT_GROUP_INFO
,
2581 .descrip
= "Get group info",
2582 .argDescrip
= "GROUP",
2585 .longName
= "user-sidinfo",
2586 .argInfo
= POPT_ARG_STRING
,
2588 .val
= OPT_USER_SIDINFO
,
2589 .descrip
= "Get user info from sid",
2590 .argDescrip
= "SID",
2593 .longName
= "gid-info",
2594 .argInfo
= POPT_ARG_INT
,
2596 .val
= OPT_GID_INFO
,
2597 .descrip
= "Get group info from gid",
2598 .argDescrip
= "GID",
2601 .longName
= "user-groups",
2603 .argInfo
= POPT_ARG_STRING
,
2606 .descrip
= "Get user groups",
2607 .argDescrip
= "USER",
2610 .longName
= "user-domgroups",
2611 .argInfo
= POPT_ARG_STRING
,
2613 .val
= OPT_USERDOMGROUPS
,
2614 .descrip
= "Get user domain groups",
2615 .argDescrip
= "SID",
2618 .longName
= "sid-aliases",
2619 .argInfo
= POPT_ARG_STRING
,
2621 .val
= OPT_SIDALIASES
,
2622 .descrip
= "Get sid aliases",
2623 .argDescrip
= "SID",
2626 .longName
= "user-sids",
2627 .argInfo
= POPT_ARG_STRING
,
2629 .val
= OPT_USERSIDS
,
2630 .descrip
= "Get user group sids for user SID",
2631 .argDescrip
= "SID",
2634 .longName
= "authenticate",
2636 .argInfo
= POPT_ARG_STRING
,
2639 .descrip
= "authenticate user",
2640 .argDescrip
= "user%password",
2643 .longName
= "pam-logon",
2644 .argInfo
= POPT_ARG_STRING
,
2646 .val
= OPT_PAM_LOGON
,
2647 .descrip
= "do a pam logon equivalent",
2648 .argDescrip
= "user%password",
2651 .longName
= "logoff",
2652 .argInfo
= POPT_ARG_NONE
,
2654 .descrip
= "log off user",
2655 .argDescrip
= "uid",
2658 .longName
= "logoff-user",
2659 .argInfo
= POPT_ARG_STRING
,
2660 .arg
= &logoff_user
,
2661 .val
= OPT_LOGOFF_USER
,
2662 .descrip
= "username to log off"
2665 .longName
= "logoff-uid",
2666 .argInfo
= POPT_ARG_INT
,
2668 .val
= OPT_LOGOFF_UID
,
2669 .descrip
= "uid to log off",
2672 .longName
= "set-auth-user",
2673 .argInfo
= POPT_ARG_STRING
,
2675 .val
= OPT_SET_AUTH_USER
,
2676 .descrip
= "Store user and password used by "
2677 "winbindd (root only)",
2678 .argDescrip
= "user%password",
2681 .longName
= "ccache-save",
2683 .argInfo
= POPT_ARG_STRING
,
2685 .val
= OPT_CCACHE_SAVE
,
2686 .descrip
= "Store user and password for ccache "
2688 .argDescrip
= "user%password",
2691 .longName
= "getdcname",
2692 .argInfo
= POPT_ARG_STRING
,
2694 .val
= OPT_GETDCNAME
,
2695 .descrip
= "Get a DC name for a foreign domain",
2696 .argDescrip
= "domainname",
2699 .longName
= "dsgetdcname",
2700 .argInfo
= POPT_ARG_STRING
,
2702 .val
= OPT_DSGETDCNAME
,
2703 .descrip
= "Find a DC for a domain",
2704 .argDescrip
= "domainname",
2707 .longName
= "dc-info",
2708 .argInfo
= POPT_ARG_STRING
,
2711 .descrip
= "Find the currently known DCs",
2712 .argDescrip
= "domainname",
2715 .longName
= "get-auth-user",
2716 .argInfo
= POPT_ARG_NONE
,
2717 .val
= OPT_GET_AUTH_USER
,
2718 .descrip
= "Retrieve user and password used by "
2719 "winbindd (root only)",
2724 .argInfo
= POPT_ARG_NONE
,
2727 .descrip
= "Ping winbindd to see if it is alive",
2730 .longName
= "domain",
2732 .argInfo
= POPT_ARG_STRING
,
2733 .arg
= &opt_domain_name
,
2734 .val
= OPT_DOMAIN_NAME
,
2735 .descrip
= "Define to the domain to restrict "
2737 .argDescrip
= "domain",
2739 #ifdef WITH_FAKE_KASERVER
2743 .argInfo
= POPT_ARG_STRING
,
2746 .descrip
= "set an AFS token from winbind",
2747 .argDescrip
= "user%password",
2752 .longName
= "krb5auth",
2754 .argInfo
= POPT_ARG_STRING
,
2757 .descrip
= "authenticate user using Kerberos",
2758 .argDescrip
= "user%password",
2760 /* destroys wbinfo --help output */
2761 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2764 .longName
= "krb5ccname",
2765 .argInfo
= POPT_ARG_STRING
,
2766 .arg
= &opt_krb5ccname
,
2767 .val
= OPT_KRB5CCNAME
,
2768 .descrip
= "authenticate user using Kerberos and "
2769 "specific credential cache type",
2770 .argDescrip
= "krb5ccname",
2774 .longName
= "separator",
2775 .argInfo
= POPT_ARG_NONE
,
2776 .val
= OPT_SEPARATOR
,
2777 .descrip
= "Get the active winbind separator",
2780 .longName
= "verbose",
2781 .argInfo
= POPT_ARG_NONE
,
2783 .descrip
= "Print additional information per command",
2786 .longName
= "change-user-password",
2787 .argInfo
= POPT_ARG_STRING
,
2789 .val
= OPT_CHANGE_USER_PASSWORD
,
2790 .descrip
= "Change the password for a user",
2793 .longName
= "ntlmv1",
2794 .argInfo
= POPT_ARG_NONE
,
2796 .descrip
= "Use NTLMv1 cryptography for user authentication",
2799 .longName
= "ntlmv2",
2800 .argInfo
= POPT_ARG_NONE
,
2802 .descrip
= "Use NTLMv2 cryptography for user authentication",
2805 .longName
= "lanman",
2806 .argInfo
= POPT_ARG_NONE
,
2808 .descrip
= "Use lanman cryptography for user authentication",
2814 /* Samba client initialisation */
2820 pc
= samba_popt_get_context(getprogname(),
2826 DBG_ERR("Failed to setup popt context!\n");
2830 /* Parse command line options */
2833 poptPrintHelp(pc
, stderr
, 0);
2837 while((opt
= poptGetNextOpt(pc
)) != -1) {
2838 /* get the generic configuration parameters like --domain */
2852 poptFreeContext(pc
);
2854 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2855 POPT_CONTEXT_KEEP_FIRST
);
2857 while((opt
= poptGetNextOpt(pc
)) != -1) {
2860 if (!print_domain_users(opt_domain_name
)) {
2862 "Error looking up domain users\n");
2867 if (!print_domain_groups(opt_domain_name
)) {
2869 "Error looking up domain groups\n");
2874 if (!wbinfo_lookupsid(string_arg
)) {
2876 "Could not lookup sid %s\n",
2881 case OPT_SID_TO_FULLNAME
:
2882 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2883 d_fprintf(stderr
, "Could not lookup sid %s\n",
2889 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2890 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2895 case OPT_LOOKUP_SIDS
:
2896 if (!wbinfo_lookup_sids(string_arg
)) {
2897 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2903 if (!wbinfo_lookupname(string_arg
)) {
2904 d_fprintf(stderr
, "Could not lookup name %s\n",
2910 if (!wbinfo_wins_byname(string_arg
)) {
2912 "Could not lookup WINS by name %s\n",
2918 if (!wbinfo_wins_byip(string_arg
)) {
2920 "Could not lookup WINS by IP %s\n",
2926 if (!wbinfo_uid_to_sid(int_arg
)) {
2928 "Could not convert uid %d to sid\n",
2934 if (!wbinfo_gid_to_sid(int_arg
)) {
2936 "Could not convert gid %d to sid\n",
2942 if (!wbinfo_sid_to_uid(string_arg
)) {
2944 "Could not convert sid %s to uid\n",
2950 if (!wbinfo_sid_to_gid(string_arg
)) {
2952 "Could not convert sid %s to gid\n",
2957 case OPT_ALLOCATE_UID
:
2958 if (!wbinfo_allocate_uid()) {
2959 d_fprintf(stderr
, "Could not allocate a uid\n");
2963 case OPT_ALLOCATE_GID
:
2964 if (!wbinfo_allocate_gid()) {
2965 d_fprintf(stderr
, "Could not allocate a gid\n");
2969 case OPT_SET_UID_MAPPING
:
2970 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2972 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2974 d_fprintf(stderr
, "Could not create or modify "
2975 "uid to sid mapping\n");
2979 case OPT_SET_GID_MAPPING
:
2980 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2982 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2984 d_fprintf(stderr
, "Could not create or modify "
2985 "gid to sid mapping\n");
2989 case OPT_REMOVE_UID_MAPPING
:
2990 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2992 !wbinfo_remove_uid_mapping(int_subarg
,
2995 d_fprintf(stderr
, "Could not remove uid to sid "
3000 case OPT_REMOVE_GID_MAPPING
:
3001 if (!parse_mapping_arg(string_arg
, &int_subarg
,
3003 !wbinfo_remove_gid_mapping(int_subarg
,
3006 d_fprintf(stderr
, "Could not remove gid to sid "
3011 case OPT_SIDS_TO_XIDS
:
3012 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
3013 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
3018 case OPT_XIDS_TO_SIDS
:
3019 if (!wbinfo_xids_to_sids(string_arg
)) {
3020 d_fprintf(stderr
, "wbinfo_xids_to_sids "
3026 if (!wbinfo_check_secret(opt_domain_name
)) {
3027 d_fprintf(stderr
, "Could not check secret\n");
3032 if (!wbinfo_change_secret(opt_domain_name
)) {
3033 d_fprintf(stderr
, "Could not change secret\n");
3038 if (!wbinfo_ping_dc(opt_domain_name
)) {
3043 if (!wbinfo_list_domains(false, verbose
)) {
3045 "Could not list trusted domains\n");
3050 if (!wbinfo_show_sequence(opt_domain_name
)) {
3052 "Could not show sequence numbers\n");
3056 case OPT_ONLINESTATUS
:
3057 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
3059 "Could not show online-status\n");
3064 if (!wbinfo_domain_info(string_arg
)) {
3066 "Could not get domain info\n");
3071 if (!wbinfo_get_userinfo(string_arg
)) {
3073 "Could not get info for user %s\n",
3078 case OPT_USER_SIDINFO
:
3079 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
3081 "Could not get info for user "
3082 "sid %s\n", string_arg
);
3087 if ( !wbinfo_get_uidinfo(int_arg
)) {
3088 d_fprintf(stderr
, "Could not get info for uid "
3093 case OPT_GROUP_INFO
:
3094 if ( !wbinfo_get_groupinfo(string_arg
)) {
3095 d_fprintf(stderr
, "Could not get info for "
3096 "group %s\n", string_arg
);
3101 if ( !wbinfo_get_gidinfo(int_arg
)) {
3102 d_fprintf(stderr
, "Could not get info for gid "
3108 if (!wbinfo_get_usergroups(string_arg
)) {
3110 "Could not get groups for user %s\n",
3116 if (!wbinfo_get_usersids(string_arg
)) {
3117 d_fprintf(stderr
, "Could not get group SIDs "
3118 "for user SID %s\n",
3123 case OPT_USERDOMGROUPS
:
3124 if (!wbinfo_get_userdomgroups(string_arg
)) {
3125 d_fprintf(stderr
, "Could not get user's domain "
3126 "groups for user SID %s\n",
3131 case OPT_SIDALIASES
:
3132 if (!wbinfo_get_sidaliases(opt_domain_name
,
3134 d_fprintf(stderr
, "Could not get sid aliases "
3135 "for user SID %s\n", string_arg
);
3140 bool got_error
= false;
3142 if (!wbinfo_auth(string_arg
)) {
3144 "Could not authenticate user "
3145 "%s with plaintext "
3146 "password\n", string_arg
);
3150 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
3153 "Could not authenticate user "
3154 "%s with challenge/response\n",
3164 if (!wbinfo_pam_logon(string_arg
, verbose
)) {
3165 d_fprintf(stderr
, "pam_logon failed for %s\n",
3174 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
3176 d_printf("Logoff %s (%d): %s\n", logoff_user
,
3177 logoff_uid
, wbcErrorString(wbc_status
));
3181 uint32_t flags
= WBFLAG_PAM_KRB5
|
3182 WBFLAG_PAM_CACHED_LOGIN
|
3183 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
3184 WBFLAG_PAM_INFO3_TEXT
|
3185 WBFLAG_PAM_CONTACT_TRUSTDOM
;
3187 if (!wbinfo_auth_krb5(string_arg
, opt_krb5ccname
,
3190 "Could not authenticate user "
3191 "[%s] with Kerberos "
3192 "(ccache: %s)\n", string_arg
,
3199 if (!wbinfo_klog(string_arg
)) {
3200 d_fprintf(stderr
, "Could not klog user\n");
3205 if (!wbinfo_ping()) {
3206 d_fprintf(stderr
, "could not ping winbindd!\n");
3210 case OPT_SET_AUTH_USER
:
3211 if (!wbinfo_set_auth_user(string_arg
)) {
3215 case OPT_GET_AUTH_USER
:
3216 wbinfo_get_auth_user();
3219 case OPT_CCACHE_SAVE
:
3220 if (!wbinfo_ccache_save(string_arg
)) {
3225 if (!wbinfo_getdcname(string_arg
)) {
3229 case OPT_DSGETDCNAME
:
3230 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
3235 if (!wbinfo_dc_info(string_arg
)) {
3239 case OPT_SEPARATOR
: {
3240 const char sep
= winbind_separator();
3244 d_printf("%c\n", sep
);
3247 case OPT_LIST_ALL_DOMAINS
:
3248 if (!wbinfo_list_domains(true, verbose
)) {
3252 case OPT_LIST_OWN_DOMAIN
:
3253 if (!wbinfo_list_own_domain()) {
3257 case OPT_CHANGE_USER_PASSWORD
:
3258 if (!wbinfo_change_user_password(string_arg
)) {
3260 "Could not change user password "
3261 "for user %s\n", string_arg
);
3266 /* generic configuration options */
3267 case OPT_DOMAIN_NAME
:
3272 case OPT_LOGOFF_USER
:
3273 case OPT_LOGOFF_UID
:
3274 case OPT_KRB5CCNAME
:
3277 d_fprintf(stderr
, "Invalid option\n");
3278 poptPrintHelp(pc
, stderr
, 0);
3290 poptFreeContext(pc
);