2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "winbind_client.h"
26 #include "libwbclient/wbclient.h"
27 #include "lib/popt/popt.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #if (_SAMBA_BUILD_) >= 4
30 #include "lib/cmdline/popt_common.h"
35 #define DBGC_CLASS DBGC_WINBIND
38 static struct wbcInterfaceDetails
*init_interface_details(void)
40 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
41 static struct wbcInterfaceDetails
*details
;
47 wbc_status
= wbcInterfaceDetails(&details
);
48 if (!WBC_ERROR_IS_OK(wbc_status
)) {
49 d_fprintf(stderr
, "could not obtain winbind interface "
56 static char winbind_separator(void)
58 struct wbcInterfaceDetails
*details
;
65 details
= init_interface_details();
68 d_fprintf(stderr
, "could not obtain winbind separator!\n");
72 sep
= details
->winbind_separator
;
75 wbcFreeMemory(details
);
78 d_fprintf(stderr
, "winbind separator was NULL!\n");
85 static const char *get_winbind_domain(void)
87 static struct wbcInterfaceDetails
*details
;
89 details
= init_interface_details();
92 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
96 return details
->netbios_domain
;
99 static const char *get_winbind_netbios_name(void)
101 static struct wbcInterfaceDetails
*details
;
103 details
= init_interface_details();
106 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
110 return details
->netbios_name
;
113 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
114 form DOMAIN/user into a domain and a user */
116 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
120 char *p
= strchr(domuser
,winbind_separator());
123 /* Maybe it was a UPN? */
124 if ((p
= strchr(domuser
, '@')) != NULL
) {
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;
143 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
144 * Return true if input was valid, false otherwise. */
145 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
= strtoul(tmp
, &endptr
, 10);
162 if (endptr
[0] != '\0')
168 /* pull pwent info for a given user */
170 static bool wbinfo_get_userinfo(char *user
)
172 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
173 struct passwd
*pwd
= NULL
;
175 wbc_status
= wbcGetpwnam(user
, &pwd
);
176 if (!WBC_ERROR_IS_OK(wbc_status
)) {
180 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
183 (unsigned int)pwd
->pw_uid
,
184 (unsigned int)pwd
->pw_gid
,
192 /* pull pwent info for a given uid */
193 static bool wbinfo_get_uidinfo(int uid
)
195 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
196 struct passwd
*pwd
= NULL
;
198 wbc_status
= wbcGetpwuid(uid
, &pwd
);
199 if (!WBC_ERROR_IS_OK(wbc_status
)) {
203 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
206 (unsigned int)pwd
->pw_uid
,
207 (unsigned int)pwd
->pw_gid
,
215 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
217 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
218 struct passwd
*pwd
= NULL
;
219 struct wbcDomainSid sid
;
221 wbc_status
= wbcStringToSid(sid_str
, &sid
);
222 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
223 if (!WBC_ERROR_IS_OK(wbc_status
)) {
227 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
230 (unsigned int)pwd
->pw_uid
,
231 (unsigned int)pwd
->pw_gid
,
240 /* pull grent for a given group */
241 static bool wbinfo_get_groupinfo(const char *group
)
243 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
247 wbc_status
= wbcGetgrnam(group
, &grp
);
248 if (!WBC_ERROR_IS_OK(wbc_status
)) {
252 d_printf("%s:%s:%u:",
255 (unsigned int)grp
->gr_gid
);
258 while (*mem
!= NULL
) {
259 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
269 /* pull grent for a given gid */
270 static bool wbinfo_get_gidinfo(int gid
)
272 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
276 wbc_status
= wbcGetgrgid(gid
, &grp
);
277 if (!WBC_ERROR_IS_OK(wbc_status
)) {
281 d_printf("%s:%s:%u:",
284 (unsigned int)grp
->gr_gid
);
287 while (*mem
!= NULL
) {
288 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
298 /* List groups a user is a member of */
300 static bool wbinfo_get_usergroups(const char *user
)
302 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
305 gid_t
*groups
= NULL
;
309 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
310 if (!WBC_ERROR_IS_OK(wbc_status
)) {
314 for (i
= 0; i
< num_groups
; i
++) {
315 d_printf("%d\n", (int)groups
[i
]);
318 wbcFreeMemory(groups
);
324 /* List group SIDs a user SID is a member of */
325 static bool wbinfo_get_usersids(const char *user_sid_str
)
327 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
330 struct wbcDomainSid user_sid
, *sids
= NULL
;
334 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
335 if (!WBC_ERROR_IS_OK(wbc_status
)) {
339 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
340 if (!WBC_ERROR_IS_OK(wbc_status
)) {
344 for (i
= 0; i
< num_sids
; i
++) {
346 wbc_status
= wbcSidToString(&sids
[i
], &str
);
347 if (!WBC_ERROR_IS_OK(wbc_status
)) {
351 d_printf("%s\n", str
);
360 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
362 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
365 struct wbcDomainSid user_sid
, *sids
= NULL
;
369 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
370 if (!WBC_ERROR_IS_OK(wbc_status
)) {
374 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
375 if (!WBC_ERROR_IS_OK(wbc_status
)) {
379 for (i
= 0; i
< num_sids
; i
++) {
381 wbc_status
= wbcSidToString(&sids
[i
], &str
);
382 if (!WBC_ERROR_IS_OK(wbc_status
)) {
386 d_printf("%s\n", str
);
395 static bool wbinfo_get_sidaliases(const char *domain
,
396 const char *user_sid_str
)
398 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
399 struct wbcDomainInfo
*dinfo
= NULL
;
401 struct wbcDomainSid user_sid
;
402 uint32_t *alias_rids
= NULL
;
403 uint32_t num_alias_rids
;
404 char *domain_sid_str
= NULL
;
407 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
408 (domain
[0] == '\0')) {
409 domain
= get_winbind_domain();
414 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
415 if (!WBC_ERROR_IS_OK(wbc_status
)) {
416 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
417 wbcErrorString(wbc_status
));
420 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
421 if (!WBC_ERROR_IS_OK(wbc_status
)) {
425 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
426 &alias_rids
, &num_alias_rids
);
427 if (!WBC_ERROR_IS_OK(wbc_status
)) {
431 wbc_status
= wbcSidToString(&dinfo
->sid
, &domain_sid_str
);
432 if (!WBC_ERROR_IS_OK(wbc_status
)) {
436 for (i
= 0; i
< num_alias_rids
; i
++) {
437 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
440 wbcFreeMemory(alias_rids
);
443 if (domain_sid_str
) {
444 wbcFreeMemory(domain_sid_str
);
447 wbcFreeMemory(dinfo
);
449 return (WBC_ERR_SUCCESS
== wbc_status
);
453 /* Convert NetBIOS name to IP */
455 static bool wbinfo_wins_byname(const char *name
)
457 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
460 wbc_status
= wbcResolveWinsByName(name
, &ip
);
461 if (!WBC_ERROR_IS_OK(wbc_status
)) {
465 /* Display response */
467 d_printf("%s\n", ip
);
474 /* Convert IP to NetBIOS name */
476 static bool wbinfo_wins_byip(const char *ip
)
478 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
481 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
482 if (!WBC_ERROR_IS_OK(wbc_status
)) {
486 /* Display response */
488 d_printf("%s\n", name
);
495 /* List all/trusted domains */
497 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
499 struct wbcDomainInfo
*domain_list
= NULL
;
501 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
502 bool print_all
= !list_all_domains
&& verbose
;
505 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
506 if (!WBC_ERROR_IS_OK(wbc_status
)) {
511 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
512 "Domain Name", "DNS Domain", "Trust Type",
513 "Transitive", "In", "Out");
516 for (i
=0; i
<num_domains
; i
++) {
518 d_printf("%-16s", domain_list
[i
].short_name
);
520 d_printf("%s", domain_list
[i
].short_name
);
525 d_printf("%-24s", domain_list
[i
].dns_name
);
527 switch(domain_list
[i
].trust_type
) {
528 case WBC_DOMINFO_TRUSTTYPE_NONE
:
531 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
534 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
535 d_printf("External ");
537 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
538 d_printf("In-Forest ");
542 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
548 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
554 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
566 /* List own domain */
568 static bool wbinfo_list_own_domain(void)
570 d_printf("%s\n", get_winbind_domain());
575 /* show sequence numbers */
576 static bool wbinfo_show_sequence(const char *domain
)
578 d_printf("This command has been deprecated. Please use the "
579 "--online-status option instead.\n");
583 /* show sequence numbers */
584 static bool wbinfo_show_onlinestatus(const char *domain
)
586 struct wbcDomainInfo
*domain_list
= NULL
;
588 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
591 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
592 if (!WBC_ERROR_IS_OK(wbc_status
)) {
596 for (i
=0; i
<num_domains
; i
++) {
600 if (!strequal(domain_list
[i
].short_name
, domain
)) {
605 is_offline
= (domain_list
[i
].domain_flags
&
606 WBC_DOMINFO_DOMAIN_OFFLINE
);
608 d_printf("%s : %s\n",
609 domain_list
[i
].short_name
,
610 is_offline
? "offline" : "online" );
617 /* Show domain info */
619 static bool wbinfo_domain_info(const char *domain
)
621 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
622 struct wbcDomainInfo
*dinfo
= NULL
;
623 char *sid_str
= NULL
;
625 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
626 domain
= get_winbind_domain();
631 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
632 if (!WBC_ERROR_IS_OK(wbc_status
)) {
636 wbc_status
= wbcSidToString(&dinfo
->sid
, &sid_str
);
637 if (!WBC_ERROR_IS_OK(wbc_status
)) {
638 wbcFreeMemory(dinfo
);
642 /* Display response */
644 d_printf("Name : %s\n", dinfo
->short_name
);
645 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
647 d_printf("SID : %s\n", sid_str
);
649 d_printf("Active Directory : %s\n",
650 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
651 d_printf("Native : %s\n",
652 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ?
655 d_printf("Primary : %s\n",
656 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ?
659 wbcFreeMemory(sid_str
);
660 wbcFreeMemory(dinfo
);
665 /* Get a foreign DC's name */
666 static bool wbinfo_getdcname(const char *domain_name
)
668 struct winbindd_request request
;
669 struct winbindd_response response
;
671 ZERO_STRUCT(request
);
672 ZERO_STRUCT(response
);
674 fstrcpy(request
.domain_name
, domain_name
);
678 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
,
679 &response
) != NSS_STATUS_SUCCESS
) {
680 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
684 /* Display response */
686 d_printf("%s\n", response
.data
.dc_name
);
692 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
694 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
695 struct wbcDomainControllerInfoEx
*dc_info
;
698 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
699 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
701 if (!WBC_ERROR_IS_OK(wbc_status
)) {
702 printf("Could not find dc for %s\n", domain_name
);
706 wbcGuidToString(dc_info
->domain_guid
, &str
);
708 d_printf("%s\n", dc_info
->dc_unc
);
709 d_printf("%s\n", dc_info
->dc_address
);
710 d_printf("%d\n", dc_info
->dc_address_type
);
711 d_printf("%s\n", str
);
712 d_printf("%s\n", dc_info
->domain_name
);
713 d_printf("%s\n", dc_info
->forest_name
);
714 d_printf("0x%08x\n", dc_info
->dc_flags
);
715 d_printf("%s\n", dc_info
->dc_site_name
);
716 d_printf("%s\n", dc_info
->client_site_name
);
721 /* Check trust account password */
723 static bool wbinfo_check_secret(const char *domain
)
725 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
726 struct wbcAuthErrorInfo
*error
= NULL
;
727 const char *domain_name
;
730 domain_name
= domain
;
732 domain_name
= get_winbind_domain();
735 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
737 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
739 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
741 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
742 d_fprintf(stderr
, "error code was %s (0x%x)\n",
743 error
->nt_string
, error
->nt_status
);
744 wbcFreeMemory(error
);
746 if (!WBC_ERROR_IS_OK(wbc_status
)) {
753 /* Change trust account password */
755 static bool wbinfo_change_secret(const char *domain
)
757 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
758 struct wbcAuthErrorInfo
*error
= NULL
;
759 const char *domain_name
;
762 domain_name
= domain
;
764 domain_name
= get_winbind_domain();
767 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
769 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
771 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
773 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
774 d_fprintf(stderr
, "error code was %s (0x%x)\n",
775 error
->nt_string
, error
->nt_status
);
776 wbcFreeMemory(error
);
778 if (!WBC_ERROR_IS_OK(wbc_status
)) {
785 /* Check DC connection */
787 static bool wbinfo_ping_dc(void)
789 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
790 struct wbcAuthErrorInfo
*error
= NULL
;
792 wbc_status
= wbcPingDc(NULL
, &error
);
794 d_printf("checking the NETLOGON dc connection %s\n",
795 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
797 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
798 d_fprintf(stderr
, "error code was %s (0x%x)\n",
799 error
->nt_string
, error
->nt_status
);
800 wbcFreeMemory(error
);
802 if (!WBC_ERROR_IS_OK(wbc_status
)) {
809 /* Convert uid to sid */
811 static bool wbinfo_uid_to_sid(uid_t uid
)
813 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
814 struct wbcDomainSid sid
;
815 char *sid_str
= NULL
;
819 wbc_status
= wbcUidToSid(uid
, &sid
);
820 if (!WBC_ERROR_IS_OK(wbc_status
)) {
824 wbc_status
= wbcSidToString(&sid
, &sid_str
);
825 if (!WBC_ERROR_IS_OK(wbc_status
)) {
829 /* Display response */
831 d_printf("%s\n", sid_str
);
833 wbcFreeMemory(sid_str
);
838 /* Convert gid to sid */
840 static bool wbinfo_gid_to_sid(gid_t gid
)
842 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
843 struct wbcDomainSid sid
;
844 char *sid_str
= NULL
;
848 wbc_status
= wbcGidToSid(gid
, &sid
);
849 if (!WBC_ERROR_IS_OK(wbc_status
)) {
853 wbc_status
= wbcSidToString(&sid
, &sid_str
);
854 if (!WBC_ERROR_IS_OK(wbc_status
)) {
858 /* Display response */
860 d_printf("%s\n", sid_str
);
862 wbcFreeMemory(sid_str
);
867 /* Convert sid to uid */
869 static bool wbinfo_sid_to_uid(const char *sid_str
)
871 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
872 struct wbcDomainSid sid
;
877 wbc_status
= wbcStringToSid(sid_str
, &sid
);
878 if (!WBC_ERROR_IS_OK(wbc_status
)) {
882 wbc_status
= wbcSidToUid(&sid
, &uid
);
883 if (!WBC_ERROR_IS_OK(wbc_status
)) {
887 /* Display response */
889 d_printf("%d\n", (int)uid
);
894 static bool wbinfo_sid_to_gid(const char *sid_str
)
896 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
897 struct wbcDomainSid sid
;
902 wbc_status
= wbcStringToSid(sid_str
, &sid
);
903 if (!WBC_ERROR_IS_OK(wbc_status
)) {
907 wbc_status
= wbcSidToGid(&sid
, &gid
);
908 if (!WBC_ERROR_IS_OK(wbc_status
)) {
912 /* Display response */
914 d_printf("%d\n", (int)gid
);
919 static bool wbinfo_allocate_uid(void)
921 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
926 wbc_status
= wbcAllocateUid(&uid
);
927 if (!WBC_ERROR_IS_OK(wbc_status
)) {
931 /* Display response */
933 d_printf("New uid: %u\n", (unsigned int)uid
);
938 static bool wbinfo_allocate_gid(void)
940 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
945 wbc_status
= wbcAllocateGid(&gid
);
946 if (!WBC_ERROR_IS_OK(wbc_status
)) {
950 /* Display response */
952 d_printf("New gid: %u\n", (unsigned int)gid
);
957 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
959 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
960 struct wbcDomainSid sid
;
964 wbc_status
= wbcStringToSid(sid_str
, &sid
);
965 if (!WBC_ERROR_IS_OK(wbc_status
)) {
969 wbc_status
= wbcSetUidMapping(uid
, &sid
);
970 if (!WBC_ERROR_IS_OK(wbc_status
)) {
974 /* Display response */
976 d_printf("uid %u now mapped to sid %s\n",
977 (unsigned int)uid
, sid_str
);
982 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
984 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
985 struct wbcDomainSid sid
;
989 wbc_status
= wbcStringToSid(sid_str
, &sid
);
990 if (!WBC_ERROR_IS_OK(wbc_status
)) {
994 wbc_status
= wbcSetGidMapping(gid
, &sid
);
995 if (!WBC_ERROR_IS_OK(wbc_status
)) {
999 /* Display response */
1001 d_printf("gid %u now mapped to sid %s\n",
1002 (unsigned int)gid
, sid_str
);
1007 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1009 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1010 struct wbcDomainSid sid
;
1014 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1015 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1019 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1020 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1024 /* Display response */
1026 d_printf("Removed uid %u to sid %s mapping\n",
1027 (unsigned int)uid
, sid_str
);
1032 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1034 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1035 struct wbcDomainSid sid
;
1039 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1040 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1044 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1045 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1049 /* Display response */
1051 d_printf("Removed gid %u to sid %s mapping\n",
1052 (unsigned int)gid
, sid_str
);
1057 /* Convert sid to string */
1059 static bool wbinfo_lookupsid(const char *sid_str
)
1061 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1062 struct wbcDomainSid sid
;
1065 enum wbcSidType type
;
1067 /* Send off request */
1069 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1070 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1074 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1075 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1079 /* Display response */
1081 d_printf("%s%c%s %d\n",
1082 domain
, winbind_separator(), name
, type
);
1087 /* Convert sid to fullname */
1089 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1091 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1092 struct wbcDomainSid sid
;
1095 enum wbcSidType type
;
1097 /* Send off request */
1099 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1100 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1104 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1105 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1109 /* Display response */
1111 d_printf("%s%c%s %d\n",
1112 domain
, winbind_separator(), name
, type
);
1117 /* Lookup a list of RIDs */
1119 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1121 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1122 struct wbcDomainInfo
*dinfo
= NULL
;
1123 char *domain_name
= NULL
;
1124 const char **names
= NULL
;
1125 enum wbcSidType
*types
= NULL
;
1128 uint32_t *rids
= NULL
;
1131 TALLOC_CTX
*mem_ctx
= NULL
;
1134 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1135 domain
= get_winbind_domain();
1140 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1141 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1142 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1143 wbcErrorString(wbc_status
));
1147 mem_ctx
= talloc_new(NULL
);
1148 if (mem_ctx
== NULL
) {
1149 d_printf("talloc_new failed\n");
1157 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1158 uint32_t rid
= strtoul(ridstr
, NULL
, 10);
1159 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1161 d_printf("talloc_realloc failed\n");
1163 rids
[num_rids
] = rid
;
1168 d_printf("no rids\n");
1172 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
1173 (const char **)&domain_name
, &names
, &types
);
1174 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1175 d_printf("winbind_lookup_rids failed: %s\n",
1176 wbcErrorString(wbc_status
));
1180 d_printf("Domain: %s\n", domain_name
);
1182 for (i
=0; i
<num_rids
; i
++) {
1183 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1184 wbcSidTypeString(types
[i
]));
1190 wbcFreeMemory(dinfo
);
1193 wbcFreeMemory(domain_name
);
1196 wbcFreeMemory(names
);
1199 wbcFreeMemory(types
);
1201 TALLOC_FREE(mem_ctx
);
1205 /* Convert string to sid */
1207 static bool wbinfo_lookupname(const char *full_name
)
1209 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1210 struct wbcDomainSid sid
;
1212 enum wbcSidType type
;
1213 fstring domain_name
;
1214 fstring account_name
;
1216 /* Send off request */
1218 parse_wbinfo_domain_user(full_name
, domain_name
,
1221 wbc_status
= wbcLookupName(domain_name
, account_name
,
1223 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1227 wbc_status
= wbcSidToString(&sid
, &sid_str
);
1228 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1232 /* Display response */
1234 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1236 wbcFreeMemory(sid_str
);
1241 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1243 const char *username
)
1246 const char *ret
= NULL
;
1248 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1253 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1258 prompt
= talloc_asprintf_append(prompt
, "password: ");
1263 ret
= getpass(prompt
);
1264 TALLOC_FREE(prompt
);
1266 return talloc_strdup(mem_ctx
, ret
);
1269 /* Authenticate a user with a plaintext password */
1271 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1273 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1276 char *password
= NULL
;
1278 char *local_cctype
= NULL
;
1280 struct wbcLogonUserParams params
;
1281 struct wbcLogonUserInfo
*info
;
1282 struct wbcAuthErrorInfo
*error
;
1283 struct wbcUserPasswordPolicyInfo
*policy
;
1284 TALLOC_CTX
*frame
= talloc_tos();
1286 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1290 if ((p
= strchr(s
, '%')) != NULL
) {
1293 password
= talloc_strdup(frame
, p
);
1295 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1298 local_cctype
= talloc_strdup(frame
, cctype
);
1304 params
.username
= name
;
1305 params
.password
= password
;
1306 params
.num_blobs
= 0;
1307 params
.blobs
= NULL
;
1309 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1315 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1319 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1325 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1329 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1333 (uint8_t *)local_cctype
,
1335 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1339 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1341 d_printf("plaintext kerberos password authentication for [%s] %s "
1342 "(requesting cctype: %s)\n",
1343 username
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1348 "error code was %s (0x%x)\nerror messsage was: %s\n",
1351 error
->display_string
);
1354 if (WBC_ERROR_IS_OK(wbc_status
)) {
1355 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1356 if (info
&& info
->info
&& info
->info
->user_flags
&
1357 NETLOGON_CACHED_ACCOUNT
) {
1358 d_printf("user_flgs: "
1359 "NETLOGON_CACHED_ACCOUNT\n");
1365 for (i
=0; i
< info
->num_blobs
; i
++) {
1366 if (strequal(info
->blobs
[i
].name
,
1368 d_printf("credentials were put "
1371 info
->blobs
[i
].blob
.data
);
1376 d_printf("no credentials cached\n");
1381 wbcFreeMemory(params
.blobs
);
1383 return WBC_ERROR_IS_OK(wbc_status
);
1386 /* Authenticate a user with a plaintext password */
1388 static bool wbinfo_auth(char *username
)
1390 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1393 char *password
= NULL
;
1395 TALLOC_CTX
*frame
= talloc_tos();
1397 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1401 if ((p
= strchr(s
, '%')) != NULL
) {
1404 password
= talloc_strdup(frame
, p
);
1406 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1411 wbc_status
= wbcAuthenticateUser(name
, password
);
1413 d_printf("plaintext password authentication %s\n",
1414 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1417 if (response
.data
.auth
.nt_status
)
1419 "error code was %s (0x%x)\nerror messsage was: %s\n",
1420 response
.data
.auth
.nt_status_string
,
1421 response
.data
.auth
.nt_status
,
1422 response
.data
.auth
.error_string
);
1425 return WBC_ERROR_IS_OK(wbc_status
);
1428 /* Authenticate a user with a challenge/response */
1430 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1432 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1433 struct wbcAuthUserParams params
;
1434 struct wbcAuthUserInfo
*info
= NULL
;
1435 struct wbcAuthErrorInfo
*err
= NULL
;
1436 DATA_BLOB lm
= data_blob_null
;
1437 DATA_BLOB nt
= data_blob_null
;
1439 fstring name_domain
;
1442 TALLOC_CTX
*frame
= talloc_tos();
1444 p
= strchr(username
, '%');
1448 pass
= talloc_strdup(frame
, p
+ 1);
1450 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1453 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1455 params
.account_name
= name_user
;
1456 params
.domain_name
= name_domain
;
1457 params
.workstation_name
= NULL
;
1460 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1461 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1463 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1465 generate_random_buffer(params
.password
.response
.challenge
, 8);
1468 DATA_BLOB server_chal
;
1469 DATA_BLOB names_blob
;
1471 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1473 /* Pretend this is a login to 'us', for blob purposes */
1474 names_blob
= NTLMv2_generate_names_blob(NULL
,
1475 get_winbind_netbios_name(),
1476 get_winbind_domain());
1478 if (!SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1481 &lm
, &nt
, NULL
, NULL
)) {
1482 data_blob_free(&names_blob
);
1483 data_blob_free(&server_chal
);
1487 data_blob_free(&names_blob
);
1488 data_blob_free(&server_chal
);
1493 lm
= data_blob(NULL
, 24);
1494 ok
= SMBencrypt(pass
,
1495 params
.password
.response
.challenge
,
1498 data_blob_free(&lm
);
1501 nt
= data_blob(NULL
, 24);
1502 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1506 params
.password
.response
.nt_length
= nt
.length
;
1507 params
.password
.response
.nt_data
= nt
.data
;
1508 params
.password
.response
.lm_length
= lm
.length
;
1509 params
.password
.response
.lm_data
= lm
.data
;
1511 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1513 /* Display response */
1515 d_printf("challenge/response password authentication %s\n",
1516 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1518 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1520 "error code was %s (0x%x)\nerror messsage was: %s\n",
1523 err
->display_string
);
1525 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1526 wbcFreeMemory(info
);
1529 data_blob_free(&nt
);
1530 data_blob_free(&lm
);
1532 return WBC_ERROR_IS_OK(wbc_status
);
1535 /* Authenticate a user with a plaintext password */
1537 static bool wbinfo_pam_logon(char *username
)
1539 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1540 struct wbcLogonUserParams params
;
1541 struct wbcAuthErrorInfo
*error
;
1544 TALLOC_CTX
*frame
= talloc_tos();
1548 ZERO_STRUCT(params
);
1550 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1554 if ((p
= strchr(s
, '%')) != NULL
) {
1557 params
.password
= talloc_strdup(frame
, p
);
1559 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1561 params
.username
= s
;
1563 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1565 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1567 (uint8_t *)&flags
, sizeof(flags
));
1568 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1569 d_printf("wbcAddNamedBlob failed: %s\n",
1570 wbcErrorString(wbc_status
));
1576 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1578 (uint8_t *)&uid
, sizeof(uid
));
1579 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1580 d_printf("wbcAddNamedBlob failed: %s\n",
1581 wbcErrorString(wbc_status
));
1585 wbc_status
= wbcLogonUser(¶ms
, NULL
, &error
, NULL
);
1587 wbcFreeMemory(params
.blobs
);
1589 d_printf("plaintext password authentication %s\n",
1590 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1592 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1594 "error code was %s (0x%x)\nerror messsage was: %s\n",
1596 (int)error
->nt_status
,
1597 error
->display_string
);
1598 wbcFreeMemory(error
);
1604 /* Save creds with winbind */
1606 static bool wbinfo_ccache_save(char *username
)
1608 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1611 char *password
= NULL
;
1613 TALLOC_CTX
*frame
= talloc_stackframe();
1615 s
= talloc_strdup(frame
, username
);
1624 password
= talloc_strdup(frame
, p
);
1626 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1631 wbc_status
= wbcCredentialSave(name
, password
);
1633 d_printf("saving creds %s\n",
1634 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1638 return WBC_ERROR_IS_OK(wbc_status
);
1641 #ifdef WITH_FAKE_KASERVER
1642 /* Authenticate a user with a plaintext password and set a token */
1644 static bool wbinfo_klog(char *username
)
1646 struct winbindd_request request
;
1647 struct winbindd_response response
;
1651 /* Send off request */
1653 ZERO_STRUCT(request
);
1654 ZERO_STRUCT(response
);
1656 p
= strchr(username
, '%');
1660 fstrcpy(request
.data
.auth
.user
, username
);
1661 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
1664 fstrcpy(request
.data
.auth
.user
, username
);
1665 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
1668 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
1670 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
,
1673 /* Display response */
1675 d_printf("plaintext password authentication %s\n",
1676 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
1678 if (response
.data
.auth
.nt_status
)
1680 "error code was %s (0x%x)\nerror messsage was: %s\n",
1681 response
.data
.auth
.nt_status_string
,
1682 response
.data
.auth
.nt_status
,
1683 response
.data
.auth
.error_string
);
1685 if (result
!= NSS_STATUS_SUCCESS
)
1688 if (response
.extra_data
.data
== NULL
) {
1689 d_fprintf(stderr
, "Did not get token data\n");
1693 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
1694 d_fprintf(stderr
, "Could not set token\n");
1698 d_printf("Successfully created AFS token\n");
1702 static bool wbinfo_klog(char *username
)
1704 d_fprintf(stderr
, "No AFS support compiled in.\n");
1709 /* Print domain users */
1711 static bool print_domain_users(const char *domain
)
1713 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1715 uint32_t num_users
= 0;
1716 const char **users
= NULL
;
1718 /* Send request to winbind daemon */
1720 /* '.' is the special sign for our own domain */
1721 if (domain
&& strcmp(domain
, ".") == 0) {
1722 domain
= get_winbind_domain();
1725 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
1726 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1730 for (i
=0; i
< num_users
; i
++) {
1731 d_printf("%s\n", users
[i
]);
1734 wbcFreeMemory(users
);
1739 /* Print domain groups */
1741 static bool print_domain_groups(const char *domain
)
1743 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1745 uint32_t num_groups
= 0;
1746 const char **groups
= NULL
;
1748 /* Send request to winbind daemon */
1750 /* '.' is the special sign for our own domain */
1751 if (domain
&& strcmp(domain
, ".") == 0) {
1752 domain
= get_winbind_domain();
1755 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
1756 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1760 for (i
=0; i
< num_groups
; i
++) {
1761 d_printf("%s\n", groups
[i
]);
1764 wbcFreeMemory(groups
);
1769 /* Set the authorised user for winbindd access in secrets.tdb */
1771 static bool wbinfo_set_auth_user(char *username
)
1773 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1774 "See 'net help setauthuser' for details.\n");
1778 static void wbinfo_get_auth_user(void)
1780 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1781 "See 'net help getauthuser' for details.\n");
1784 static bool wbinfo_ping(void)
1788 wbc_status
= wbcPing();
1790 /* Display response */
1792 d_printf("Ping to winbindd %s\n",
1793 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1795 return WBC_ERROR_IS_OK(wbc_status
);
1798 static bool wbinfo_change_user_password(const char *username
)
1801 char *old_password
= NULL
;
1802 char *new_password
= NULL
;
1803 TALLOC_CTX
*frame
= talloc_tos();
1805 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
1806 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
1808 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
1810 /* Display response */
1812 d_printf("Password change for user %s %s\n", username
,
1813 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1815 return WBC_ERROR_IS_OK(wbc_status
);
1821 OPT_SET_AUTH_USER
= 1000,
1832 OPT_SET_UID_MAPPING
,
1833 OPT_SET_GID_MAPPING
,
1834 OPT_REMOVE_UID_MAPPING
,
1835 OPT_REMOVE_GID_MAPPING
,
1837 OPT_LIST_ALL_DOMAINS
,
1838 OPT_LIST_OWN_DOMAIN
,
1845 OPT_CHANGE_USER_PASSWORD
,
1848 OPT_SID_TO_FULLNAME
,
1857 int main(int argc
, char **argv
, char **envp
)
1860 TALLOC_CTX
*frame
= talloc_stackframe();
1862 static char *string_arg
;
1863 char *string_subarg
= NULL
;
1864 static char *opt_domain_name
;
1866 int int_subarg
= -1;
1868 bool verbose
= false;
1869 bool use_ntlmv2
= false;
1870 bool use_lanman
= false;
1871 char *logoff_user
= getenv("USER");
1872 int logoff_uid
= geteuid();
1874 struct poptOption long_options
[] = {
1877 /* longName, shortName, argInfo, argPtr, value, descrip,
1880 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1881 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1882 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1883 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1884 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1885 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1886 { "sid-to-fullname", 0, POPT_ARG_STRING
, &string_arg
,
1887 OPT_SID_TO_FULLNAME
, "Converts sid to fullname", "SID" },
1888 { "lookup-rids", 'R', POPT_ARG_STRING
, &string_arg
, 'R', "Converts RIDs to names", "RIDs" },
1889 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1890 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1891 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1892 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1893 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1894 "Get a new UID out of idmap" },
1895 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1896 "Get a new GID out of idmap" },
1897 { "set-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_UID_MAPPING
, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1898 { "set-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_GID_MAPPING
, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1899 { "remove-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_UID_MAPPING
, "Remove uid to sid mapping in idmap", "UID,SID" },
1900 { "remove-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_GID_MAPPING
, "Remove gid to sid mapping in idmap", "GID,SID" },
1901 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1902 { "change-secret", 'c', POPT_ARG_NONE
, 0, 'c', "Change shared secret" },
1903 { "ping-dc", 0, POPT_ARG_NONE
, 0, OPT_PING_DC
,
1904 "Check the NETLOGON connection" },
1905 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1906 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1907 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
1908 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1909 { "online-status", 0, POPT_ARG_NONE
, 0, OPT_ONLINESTATUS
, "Show whether domains are marked as online or offline"},
1910 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1911 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1912 { "uid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_UID_INFO
, "Get user info from uid", "UID" },
1913 { "group-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_GROUP_INFO
, "Get group info", "GROUP" },
1914 { "user-sidinfo", 0, POPT_ARG_STRING
, &string_arg
, OPT_USER_SIDINFO
, "Get user info from sid", "SID" },
1915 { "gid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_GID_INFO
, "Get group info from gid", "GID" },
1916 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1917 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1918 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1919 { "sid-aliases", 0, POPT_ARG_STRING
, &string_arg
, OPT_SIDALIASES
, "Get sid aliases", "SID" },
1920 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1921 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1922 { "pam-logon", 0, POPT_ARG_STRING
, string_arg
, OPT_PAM_LOGON
,
1923 "do a pam logon equivalent", "user%password" },
1924 { "logoff", 0, POPT_ARG_NONE
, NULL
, OPT_LOGOFF
,
1925 "log off user", "uid" },
1926 { "logoff-user", 0, POPT_ARG_STRING
, &logoff_user
,
1927 OPT_LOGOFF_USER
, "username to log off" },
1928 { "logoff-uid", 0, POPT_ARG_INT
, &logoff_uid
,
1929 OPT_LOGOFF_UID
, "uid to log off" },
1930 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1931 { "ccache-save", 0, POPT_ARG_STRING
, &string_arg
,
1932 OPT_CCACHE_SAVE
, "Store user and password for ccache "
1933 "operation", "user%password" },
1934 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1935 "Get a DC name for a foreign domain", "domainname" },
1936 { "dsgetdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_DSGETDCNAME
, "Find a DC for a domain", "domainname" },
1937 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1938 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1939 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1940 #ifdef WITH_FAKE_KASERVER
1941 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1944 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1945 /* destroys wbinfo --help output */
1946 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1948 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1949 { "verbose", 0, POPT_ARG_NONE
, 0, OPT_VERBOSE
, "Print additional information per command", NULL
},
1950 { "change-user-password", 0, POPT_ARG_STRING
, &string_arg
, OPT_CHANGE_USER_PASSWORD
, "Change the password for a user", NULL
},
1951 { "ntlmv2", 0, POPT_ARG_NONE
, 0, OPT_NTLMV2
, "Use NTLMv2 cryptography for user authentication", NULL
},
1952 { "lanman", 0, POPT_ARG_NONE
, 0, OPT_LANMAN
, "Use lanman cryptography for user authentication", NULL
},
1957 /* Samba client initialisation */
1963 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
,
1966 /* Parse command line options */
1969 poptPrintHelp(pc
, stderr
, 0);
1973 while((opt
= poptGetNextOpt(pc
)) != -1) {
1974 /* get the generic configuration parameters like --domain */
1988 poptFreeContext(pc
);
1990 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1991 POPT_CONTEXT_KEEP_FIRST
);
1993 while((opt
= poptGetNextOpt(pc
)) != -1) {
1996 if (!print_domain_users(opt_domain_name
)) {
1998 "Error looking up domain users\n");
2003 if (!print_domain_groups(opt_domain_name
)) {
2005 "Error looking up domain groups\n");
2010 if (!wbinfo_lookupsid(string_arg
)) {
2012 "Could not lookup sid %s\n",
2017 case OPT_SID_TO_FULLNAME
:
2018 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2019 d_fprintf(stderr
, "Could not lookup sid %s\n",
2025 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2026 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2032 if (!wbinfo_lookupname(string_arg
)) {
2033 d_fprintf(stderr
, "Could not lookup name %s\n",
2039 if (!wbinfo_wins_byname(string_arg
)) {
2041 "Could not lookup WINS by name %s\n",
2047 if (!wbinfo_wins_byip(string_arg
)) {
2049 "Could not lookup WINS by IP %s\n",
2055 if (!wbinfo_uid_to_sid(int_arg
)) {
2057 "Could not convert uid %d to sid\n",
2063 if (!wbinfo_gid_to_sid(int_arg
)) {
2065 "Could not convert gid %d to sid\n",
2071 if (!wbinfo_sid_to_uid(string_arg
)) {
2073 "Could not convert sid %s to uid\n",
2079 if (!wbinfo_sid_to_gid(string_arg
)) {
2081 "Could not convert sid %s to gid\n",
2086 case OPT_ALLOCATE_UID
:
2087 if (!wbinfo_allocate_uid()) {
2088 d_fprintf(stderr
, "Could not allocate a uid\n");
2092 case OPT_ALLOCATE_GID
:
2093 if (!wbinfo_allocate_gid()) {
2094 d_fprintf(stderr
, "Could not allocate a gid\n");
2098 case OPT_SET_UID_MAPPING
:
2099 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2101 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2103 d_fprintf(stderr
, "Could not create or modify "
2104 "uid to sid mapping\n");
2108 case OPT_SET_GID_MAPPING
:
2109 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2111 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2113 d_fprintf(stderr
, "Could not create or modify "
2114 "gid to sid mapping\n");
2118 case OPT_REMOVE_UID_MAPPING
:
2119 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2121 !wbinfo_remove_uid_mapping(int_subarg
,
2124 d_fprintf(stderr
, "Could not remove uid to sid "
2129 case OPT_REMOVE_GID_MAPPING
:
2130 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2132 !wbinfo_remove_gid_mapping(int_subarg
,
2135 d_fprintf(stderr
, "Could not remove gid to sid "
2141 if (!wbinfo_check_secret(opt_domain_name
)) {
2142 d_fprintf(stderr
, "Could not check secret\n");
2147 if (!wbinfo_change_secret(opt_domain_name
)) {
2148 d_fprintf(stderr
, "Could not change secret\n");
2153 if (!wbinfo_ping_dc()) {
2154 d_fprintf(stderr
, "Could not ping our DC\n");
2159 if (!wbinfo_list_domains(false, verbose
)) {
2161 "Could not list trusted domains\n");
2166 if (!wbinfo_show_sequence(opt_domain_name
)) {
2168 "Could not show sequence numbers\n");
2172 case OPT_ONLINESTATUS
:
2173 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
2175 "Could not show online-status\n");
2180 if (!wbinfo_domain_info(string_arg
)) {
2182 "Could not get domain info\n");
2187 if (!wbinfo_get_userinfo(string_arg
)) {
2189 "Could not get info for user %s\n",
2194 case OPT_USER_SIDINFO
:
2195 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
2197 "Could not get info for user "
2198 "sid %s\n", string_arg
);
2203 if ( !wbinfo_get_uidinfo(int_arg
)) {
2204 d_fprintf(stderr
, "Could not get info for uid "
2209 case OPT_GROUP_INFO
:
2210 if ( !wbinfo_get_groupinfo(string_arg
)) {
2211 d_fprintf(stderr
, "Could not get info for "
2212 "group %s\n", string_arg
);
2217 if ( !wbinfo_get_gidinfo(int_arg
)) {
2218 d_fprintf(stderr
, "Could not get info for gid "
2224 if (!wbinfo_get_usergroups(string_arg
)) {
2226 "Could not get groups for user %s\n",
2232 if (!wbinfo_get_usersids(string_arg
)) {
2233 d_fprintf(stderr
, "Could not get group SIDs "
2234 "for user SID %s\n",
2239 case OPT_USERDOMGROUPS
:
2240 if (!wbinfo_get_userdomgroups(string_arg
)) {
2241 d_fprintf(stderr
, "Could not get user's domain "
2242 "groups for user SID %s\n",
2247 case OPT_SIDALIASES
:
2248 if (!wbinfo_get_sidaliases(opt_domain_name
,
2250 d_fprintf(stderr
, "Could not get sid aliases "
2251 "for user SID %s\n", string_arg
);
2256 bool got_error
= false;
2258 if (!wbinfo_auth(string_arg
)) {
2260 "Could not authenticate user "
2261 "%s with plaintext "
2262 "password\n", string_arg
);
2266 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
2269 "Could not authenticate user "
2270 "%s with challenge/response\n",
2280 if (!wbinfo_pam_logon(string_arg
)) {
2281 d_fprintf(stderr
, "pam_logon failed for %s\n",
2289 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
2291 d_printf("Logoff %s (%d): %s\n", logoff_user
,
2292 logoff_uid
, wbcErrorString(wbc_status
));
2296 uint32_t flags
= WBFLAG_PAM_KRB5
|
2297 WBFLAG_PAM_CACHED_LOGIN
|
2298 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
2299 WBFLAG_PAM_INFO3_TEXT
|
2300 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2302 if (!wbinfo_auth_krb5(string_arg
, "FILE",
2305 "Could not authenticate user "
2306 "[%s] with Kerberos "
2307 "(ccache: %s)\n", string_arg
,
2314 if (!wbinfo_klog(string_arg
)) {
2315 d_fprintf(stderr
, "Could not klog user\n");
2320 if (!wbinfo_ping()) {
2321 d_fprintf(stderr
, "could not ping winbindd!\n");
2325 case OPT_SET_AUTH_USER
:
2326 if (!wbinfo_set_auth_user(string_arg
)) {
2330 case OPT_GET_AUTH_USER
:
2331 wbinfo_get_auth_user();
2334 case OPT_CCACHE_SAVE
:
2335 if (!wbinfo_ccache_save(string_arg
)) {
2340 if (!wbinfo_getdcname(string_arg
)) {
2344 case OPT_DSGETDCNAME
:
2345 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
2349 case OPT_SEPARATOR
: {
2350 const char sep
= winbind_separator();
2354 d_printf("%c\n", sep
);
2357 case OPT_LIST_ALL_DOMAINS
:
2358 if (!wbinfo_list_domains(true, verbose
)) {
2362 case OPT_LIST_OWN_DOMAIN
:
2363 if (!wbinfo_list_own_domain()) {
2367 case OPT_CHANGE_USER_PASSWORD
:
2368 if (!wbinfo_change_user_password(string_arg
)) {
2370 "Could not change user password "
2371 "for user %s\n", string_arg
);
2376 /* generic configuration options */
2377 case OPT_DOMAIN_NAME
:
2381 case OPT_LOGOFF_USER
:
2382 case OPT_LOGOFF_UID
:
2385 d_fprintf(stderr
, "Invalid option\n");
2386 poptPrintHelp(pc
, stderr
, 0);
2398 poptFreeContext(pc
);