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_VERSION_) < 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
;
76 d_fprintf(stderr
, "winbind separator was NULL!\n");
83 static const char *get_winbind_domain(void)
85 static struct wbcInterfaceDetails
*details
;
87 details
= init_interface_details();
90 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
94 return details
->netbios_domain
;
97 static const char *get_winbind_netbios_name(void)
99 static struct wbcInterfaceDetails
*details
;
101 details
= init_interface_details();
104 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
108 return details
->netbios_name
;
111 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
112 form DOMAIN/user into a domain and a user */
114 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
118 char *p
= strchr(domuser
,winbind_separator());
121 /* Maybe it was a UPN? */
122 if ((p
= strchr(domuser
, '@')) != NULL
) {
124 fstrcpy(user
, domuser
);
128 fstrcpy(user
, domuser
);
129 fstrcpy(domain
, get_winbind_domain());
134 fstrcpy(domain
, domuser
);
135 domain
[PTR_DIFF(p
, domuser
)] = 0;
141 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
142 * Return true if input was valid, false otherwise. */
143 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
150 tmp
= strtok(arg
, ",");
151 *sid
= strtok(NULL
, ",");
153 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
156 /* Because atoi() can return 0 on invalid input, which would be a valid
157 * UID/GID we must use strtoul() and do error checking */
158 *id
= strtoul(tmp
, &endptr
, 10);
160 if (endptr
[0] != '\0')
166 /* pull pwent info for a given user */
168 static bool wbinfo_get_userinfo(char *user
)
170 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
171 struct passwd
*pwd
= NULL
;
173 wbc_status
= wbcGetpwnam(user
, &pwd
);
174 if (!WBC_ERROR_IS_OK(wbc_status
)) {
178 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
181 (unsigned int)pwd
->pw_uid
,
182 (unsigned int)pwd
->pw_gid
,
190 /* pull pwent info for a given uid */
191 static bool wbinfo_get_uidinfo(int uid
)
193 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
194 struct passwd
*pwd
= NULL
;
196 wbc_status
= wbcGetpwuid(uid
, &pwd
);
197 if (!WBC_ERROR_IS_OK(wbc_status
)) {
201 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
204 (unsigned int)pwd
->pw_uid
,
205 (unsigned int)pwd
->pw_gid
,
213 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
215 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
216 struct passwd
*pwd
= NULL
;
217 struct wbcDomainSid sid
;
219 wbc_status
= wbcStringToSid(sid_str
, &sid
);
220 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
221 if (!WBC_ERROR_IS_OK(wbc_status
)) {
225 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
228 (unsigned int)pwd
->pw_uid
,
229 (unsigned int)pwd
->pw_gid
,
238 /* pull grent for a given group */
239 static bool wbinfo_get_groupinfo(const char *group
)
241 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
245 wbc_status
= wbcGetgrnam(group
, &grp
);
246 if (!WBC_ERROR_IS_OK(wbc_status
)) {
250 d_printf("%s:%s:%u:",
253 (unsigned int)grp
->gr_gid
);
256 while (*mem
!= NULL
) {
257 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
267 /* pull grent for a given gid */
268 static bool wbinfo_get_gidinfo(int gid
)
270 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
274 wbc_status
= wbcGetgrgid(gid
, &grp
);
275 if (!WBC_ERROR_IS_OK(wbc_status
)) {
279 d_printf("%s:%s:%u:",
282 (unsigned int)grp
->gr_gid
);
285 while (*mem
!= NULL
) {
286 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
296 /* List groups a user is a member of */
298 static bool wbinfo_get_usergroups(const char *user
)
300 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
303 gid_t
*groups
= NULL
;
307 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
308 if (!WBC_ERROR_IS_OK(wbc_status
)) {
312 for (i
= 0; i
< num_groups
; i
++) {
313 d_printf("%d\n", (int)groups
[i
]);
316 wbcFreeMemory(groups
);
322 /* List group SIDs a user SID is a member of */
323 static bool wbinfo_get_usersids(const char *user_sid_str
)
325 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
328 struct wbcDomainSid user_sid
, *sids
= NULL
;
332 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
333 if (!WBC_ERROR_IS_OK(wbc_status
)) {
337 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
338 if (!WBC_ERROR_IS_OK(wbc_status
)) {
342 for (i
= 0; i
< num_sids
; i
++) {
344 wbc_status
= wbcSidToString(&sids
[i
], &str
);
345 if (!WBC_ERROR_IS_OK(wbc_status
)) {
349 d_printf("%s\n", str
);
358 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
360 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
363 struct wbcDomainSid user_sid
, *sids
= NULL
;
367 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
368 if (!WBC_ERROR_IS_OK(wbc_status
)) {
372 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
373 if (!WBC_ERROR_IS_OK(wbc_status
)) {
377 for (i
= 0; i
< num_sids
; i
++) {
379 wbc_status
= wbcSidToString(&sids
[i
], &str
);
380 if (!WBC_ERROR_IS_OK(wbc_status
)) {
384 d_printf("%s\n", str
);
393 static bool wbinfo_get_sidaliases(const char *domain
,
394 const char *user_sid_str
)
396 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
397 struct wbcDomainInfo
*dinfo
= NULL
;
399 struct wbcDomainSid user_sid
;
400 uint32_t *alias_rids
= NULL
;
401 uint32_t num_alias_rids
;
402 char *domain_sid_str
= NULL
;
405 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
406 (domain
[0] == '\0')) {
407 domain
= get_winbind_domain();
412 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
413 if (!WBC_ERROR_IS_OK(wbc_status
)) {
414 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
415 wbcErrorString(wbc_status
));
418 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
419 if (!WBC_ERROR_IS_OK(wbc_status
)) {
423 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
424 &alias_rids
, &num_alias_rids
);
425 if (!WBC_ERROR_IS_OK(wbc_status
)) {
429 wbc_status
= wbcSidToString(&dinfo
->sid
, &domain_sid_str
);
430 if (!WBC_ERROR_IS_OK(wbc_status
)) {
434 for (i
= 0; i
< num_alias_rids
; i
++) {
435 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
438 wbcFreeMemory(alias_rids
);
441 if (domain_sid_str
) {
442 wbcFreeMemory(domain_sid_str
);
445 wbcFreeMemory(dinfo
);
447 return (WBC_ERR_SUCCESS
== wbc_status
);
451 /* Convert NetBIOS name to IP */
453 static bool wbinfo_wins_byname(const char *name
)
455 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
458 wbc_status
= wbcResolveWinsByName(name
, &ip
);
459 if (!WBC_ERROR_IS_OK(wbc_status
)) {
463 /* Display response */
465 d_printf("%s\n", ip
);
472 /* Convert IP to NetBIOS name */
474 static bool wbinfo_wins_byip(const char *ip
)
476 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
479 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
480 if (!WBC_ERROR_IS_OK(wbc_status
)) {
484 /* Display response */
486 d_printf("%s\n", name
);
493 /* List all/trusted domains */
495 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
497 struct wbcDomainInfo
*domain_list
= NULL
;
499 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
500 bool print_all
= !list_all_domains
&& verbose
;
503 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
504 if (!WBC_ERROR_IS_OK(wbc_status
)) {
509 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
510 "Domain Name", "DNS Domain", "Trust Type",
511 "Transitive", "In", "Out");
514 for (i
=0; i
<num_domains
; i
++) {
516 d_printf("%-16s", domain_list
[i
].short_name
);
518 d_printf("%s", domain_list
[i
].short_name
);
523 d_printf("%-24s", domain_list
[i
].dns_name
);
525 switch(domain_list
[i
].trust_type
) {
526 case WBC_DOMINFO_TRUSTTYPE_NONE
:
529 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
532 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
533 d_printf("External ");
535 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
536 d_printf("In-Forest ");
540 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
546 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
552 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
564 /* List own domain */
566 static bool wbinfo_list_own_domain(void)
568 d_printf("%s\n", get_winbind_domain());
573 /* show sequence numbers */
574 static bool wbinfo_show_sequence(const char *domain
)
576 d_printf("This command has been deprecated. Please use the "
577 "--online-status option instead.\n");
581 /* show sequence numbers */
582 static bool wbinfo_show_onlinestatus(const char *domain
)
584 struct wbcDomainInfo
*domain_list
= NULL
;
586 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
589 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
590 if (!WBC_ERROR_IS_OK(wbc_status
)) {
594 for (i
=0; i
<num_domains
; i
++) {
598 if (!strequal(domain_list
[i
].short_name
, domain
)) {
603 is_offline
= (domain_list
[i
].domain_flags
&
604 WBC_DOMINFO_DOMAIN_OFFLINE
);
606 d_printf("%s : %s\n",
607 domain_list
[i
].short_name
,
608 is_offline
? "offline" : "online" );
615 /* Show domain info */
617 static bool wbinfo_domain_info(const char *domain
)
619 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
620 struct wbcDomainInfo
*dinfo
= NULL
;
621 char *sid_str
= NULL
;
623 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
624 domain
= get_winbind_domain();
629 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
630 if (!WBC_ERROR_IS_OK(wbc_status
)) {
634 wbc_status
= wbcSidToString(&dinfo
->sid
, &sid_str
);
635 if (!WBC_ERROR_IS_OK(wbc_status
)) {
636 wbcFreeMemory(dinfo
);
640 /* Display response */
642 d_printf("Name : %s\n", dinfo
->short_name
);
643 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
645 d_printf("SID : %s\n", sid_str
);
647 d_printf("Active Directory : %s\n",
648 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
649 d_printf("Native : %s\n",
650 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ?
653 d_printf("Primary : %s\n",
654 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ?
657 wbcFreeMemory(sid_str
);
658 wbcFreeMemory(dinfo
);
663 /* Get a foreign DC's name */
664 static bool wbinfo_getdcname(const char *domain_name
)
666 struct winbindd_request request
;
667 struct winbindd_response response
;
669 ZERO_STRUCT(request
);
670 ZERO_STRUCT(response
);
672 fstrcpy(request
.domain_name
, domain_name
);
676 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
,
677 &response
) != NSS_STATUS_SUCCESS
) {
678 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
682 /* Display response */
684 d_printf("%s\n", response
.data
.dc_name
);
690 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
692 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
693 struct wbcDomainControllerInfoEx
*dc_info
;
696 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
697 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
699 if (!WBC_ERROR_IS_OK(wbc_status
)) {
700 printf("Could not find dc for %s\n", domain_name
);
704 wbcGuidToString(dc_info
->domain_guid
, &str
);
706 d_printf("%s\n", dc_info
->dc_unc
);
707 d_printf("%s\n", dc_info
->dc_address
);
708 d_printf("%d\n", dc_info
->dc_address_type
);
709 d_printf("%s\n", str
);
710 d_printf("%s\n", dc_info
->domain_name
);
711 d_printf("%s\n", dc_info
->forest_name
);
712 d_printf("0x%08x\n", dc_info
->dc_flags
);
713 d_printf("%s\n", dc_info
->dc_site_name
);
714 d_printf("%s\n", dc_info
->client_site_name
);
719 /* Check trust account password */
721 static bool wbinfo_check_secret(const char *domain
)
723 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
724 struct wbcAuthErrorInfo
*error
= NULL
;
725 const char *domain_name
;
728 domain_name
= domain
;
730 domain_name
= get_winbind_domain();
733 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
735 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
737 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
739 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
740 d_fprintf(stderr
, "error code was %s (0x%x)\n",
741 error
->nt_string
, error
->nt_status
);
742 wbcFreeMemory(error
);
744 if (!WBC_ERROR_IS_OK(wbc_status
)) {
751 /* Change trust account password */
753 static bool wbinfo_change_secret(const char *domain
)
755 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
756 struct wbcAuthErrorInfo
*error
= NULL
;
757 const char *domain_name
;
760 domain_name
= domain
;
762 domain_name
= get_winbind_domain();
765 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
767 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
769 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
771 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
772 d_fprintf(stderr
, "error code was %s (0x%x)\n",
773 error
->nt_string
, error
->nt_status
);
774 wbcFreeMemory(error
);
776 if (!WBC_ERROR_IS_OK(wbc_status
)) {
783 /* Check DC connection */
785 static bool wbinfo_ping_dc(void)
787 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
788 struct wbcAuthErrorInfo
*error
= NULL
;
790 wbc_status
= wbcPingDc(NULL
, &error
);
792 d_printf("checking the NETLOGON dc connection %s\n",
793 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
795 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
796 d_fprintf(stderr
, "error code was %s (0x%x)\n",
797 error
->nt_string
, error
->nt_status
);
798 wbcFreeMemory(error
);
800 if (!WBC_ERROR_IS_OK(wbc_status
)) {
807 /* Convert uid to sid */
809 static bool wbinfo_uid_to_sid(uid_t uid
)
811 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
812 struct wbcDomainSid sid
;
813 char *sid_str
= NULL
;
817 wbc_status
= wbcUidToSid(uid
, &sid
);
818 if (!WBC_ERROR_IS_OK(wbc_status
)) {
822 wbc_status
= wbcSidToString(&sid
, &sid_str
);
823 if (!WBC_ERROR_IS_OK(wbc_status
)) {
827 /* Display response */
829 d_printf("%s\n", sid_str
);
831 wbcFreeMemory(sid_str
);
836 /* Convert gid to sid */
838 static bool wbinfo_gid_to_sid(gid_t gid
)
840 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
841 struct wbcDomainSid sid
;
842 char *sid_str
= NULL
;
846 wbc_status
= wbcGidToSid(gid
, &sid
);
847 if (!WBC_ERROR_IS_OK(wbc_status
)) {
851 wbc_status
= wbcSidToString(&sid
, &sid_str
);
852 if (!WBC_ERROR_IS_OK(wbc_status
)) {
856 /* Display response */
858 d_printf("%s\n", sid_str
);
860 wbcFreeMemory(sid_str
);
865 /* Convert sid to uid */
867 static bool wbinfo_sid_to_uid(const char *sid_str
)
869 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
870 struct wbcDomainSid sid
;
875 wbc_status
= wbcStringToSid(sid_str
, &sid
);
876 if (!WBC_ERROR_IS_OK(wbc_status
)) {
880 wbc_status
= wbcSidToUid(&sid
, &uid
);
881 if (!WBC_ERROR_IS_OK(wbc_status
)) {
885 /* Display response */
887 d_printf("%d\n", (int)uid
);
892 static bool wbinfo_sid_to_gid(const char *sid_str
)
894 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
895 struct wbcDomainSid sid
;
900 wbc_status
= wbcStringToSid(sid_str
, &sid
);
901 if (!WBC_ERROR_IS_OK(wbc_status
)) {
905 wbc_status
= wbcSidToGid(&sid
, &gid
);
906 if (!WBC_ERROR_IS_OK(wbc_status
)) {
910 /* Display response */
912 d_printf("%d\n", (int)gid
);
917 static bool wbinfo_allocate_uid(void)
919 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
924 wbc_status
= wbcAllocateUid(&uid
);
925 if (!WBC_ERROR_IS_OK(wbc_status
)) {
929 /* Display response */
931 d_printf("New uid: %u\n", (unsigned int)uid
);
936 static bool wbinfo_allocate_gid(void)
938 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
943 wbc_status
= wbcAllocateGid(&gid
);
944 if (!WBC_ERROR_IS_OK(wbc_status
)) {
948 /* Display response */
950 d_printf("New gid: %u\n", (unsigned int)gid
);
955 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
957 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
958 struct wbcDomainSid sid
;
962 wbc_status
= wbcStringToSid(sid_str
, &sid
);
963 if (!WBC_ERROR_IS_OK(wbc_status
)) {
967 wbc_status
= wbcSetUidMapping(uid
, &sid
);
968 if (!WBC_ERROR_IS_OK(wbc_status
)) {
972 /* Display response */
974 d_printf("uid %u now mapped to sid %s\n",
975 (unsigned int)uid
, sid_str
);
980 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
982 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
983 struct wbcDomainSid sid
;
987 wbc_status
= wbcStringToSid(sid_str
, &sid
);
988 if (!WBC_ERROR_IS_OK(wbc_status
)) {
992 wbc_status
= wbcSetGidMapping(gid
, &sid
);
993 if (!WBC_ERROR_IS_OK(wbc_status
)) {
997 /* Display response */
999 d_printf("gid %u now mapped to sid %s\n",
1000 (unsigned int)gid
, sid_str
);
1005 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1007 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1008 struct wbcDomainSid sid
;
1012 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1013 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1017 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1018 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1022 /* Display response */
1024 d_printf("Removed uid %u to sid %s mapping\n",
1025 (unsigned int)uid
, sid_str
);
1030 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1032 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1033 struct wbcDomainSid sid
;
1037 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1038 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1042 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1043 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1047 /* Display response */
1049 d_printf("Removed gid %u to sid %s mapping\n",
1050 (unsigned int)gid
, sid_str
);
1055 /* Convert sid to string */
1057 static bool wbinfo_lookupsid(const char *sid_str
)
1059 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1060 struct wbcDomainSid sid
;
1063 enum wbcSidType type
;
1065 /* Send off request */
1067 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1068 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1072 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1073 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1077 /* Display response */
1079 d_printf("%s%c%s %d\n",
1080 domain
, winbind_separator(), name
, type
);
1085 /* Convert sid to fullname */
1087 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1089 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1090 struct wbcDomainSid sid
;
1093 enum wbcSidType type
;
1095 /* Send off request */
1097 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1098 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1102 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1103 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1107 /* Display response */
1109 d_printf("%s%c%s %d\n",
1110 domain
, winbind_separator(), name
, type
);
1115 /* Lookup a list of RIDs */
1117 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1119 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1120 struct wbcDomainInfo
*dinfo
= NULL
;
1121 char *domain_name
= NULL
;
1122 const char **names
= NULL
;
1123 enum wbcSidType
*types
= NULL
;
1126 uint32_t *rids
= NULL
;
1129 TALLOC_CTX
*mem_ctx
= NULL
;
1132 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1133 domain
= get_winbind_domain();
1138 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1139 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1140 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1141 wbcErrorString(wbc_status
));
1145 mem_ctx
= talloc_new(NULL
);
1146 if (mem_ctx
== NULL
) {
1147 d_printf("talloc_new failed\n");
1155 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1156 uint32_t rid
= strtoul(ridstr
, NULL
, 10);
1157 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1159 d_printf("talloc_realloc failed\n");
1161 rids
[num_rids
] = rid
;
1166 d_printf("no rids\n");
1170 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
1171 (const char **)&domain_name
, &names
, &types
);
1172 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1173 d_printf("winbind_lookup_rids failed: %s\n",
1174 wbcErrorString(wbc_status
));
1178 d_printf("Domain: %s\n", domain_name
);
1180 for (i
=0; i
<num_rids
; i
++) {
1181 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1182 wbcSidTypeString(types
[i
]));
1188 wbcFreeMemory(dinfo
);
1191 wbcFreeMemory(domain_name
);
1194 wbcFreeMemory(names
);
1197 wbcFreeMemory(types
);
1199 TALLOC_FREE(mem_ctx
);
1203 /* Convert string to sid */
1205 static bool wbinfo_lookupname(const char *full_name
)
1207 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1208 struct wbcDomainSid sid
;
1210 enum wbcSidType type
;
1211 fstring domain_name
;
1212 fstring account_name
;
1214 /* Send off request */
1216 parse_wbinfo_domain_user(full_name
, domain_name
,
1219 wbc_status
= wbcLookupName(domain_name
, account_name
,
1221 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1225 wbc_status
= wbcSidToString(&sid
, &sid_str
);
1226 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1230 /* Display response */
1232 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1234 wbcFreeMemory(sid_str
);
1239 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1241 const char *username
)
1244 const char *ret
= NULL
;
1246 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1251 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1256 prompt
= talloc_asprintf_append(prompt
, "password: ");
1261 ret
= getpass(prompt
);
1262 TALLOC_FREE(prompt
);
1264 return talloc_strdup(mem_ctx
, ret
);
1267 /* Authenticate a user with a plaintext password */
1269 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1271 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1274 char *password
= NULL
;
1276 char *local_cctype
= NULL
;
1278 struct wbcLogonUserParams params
;
1279 struct wbcLogonUserInfo
*info
;
1280 struct wbcAuthErrorInfo
*error
;
1281 struct wbcUserPasswordPolicyInfo
*policy
;
1282 TALLOC_CTX
*frame
= talloc_tos();
1284 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1288 if ((p
= strchr(s
, '%')) != NULL
) {
1291 password
= talloc_strdup(frame
, p
);
1293 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1296 local_cctype
= talloc_strdup(frame
, cctype
);
1302 params
.username
= name
;
1303 params
.password
= password
;
1304 params
.num_blobs
= 0;
1305 params
.blobs
= NULL
;
1307 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1313 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1317 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1323 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1327 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1331 (uint8_t *)local_cctype
,
1333 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1337 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1339 d_printf("plaintext kerberos password authentication for [%s] %s "
1340 "(requesting cctype: %s)\n",
1341 username
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1346 "error code was %s (0x%x)\nerror messsage was: %s\n",
1349 error
->display_string
);
1352 if (WBC_ERROR_IS_OK(wbc_status
)) {
1353 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1354 if (info
&& info
->info
&& info
->info
->user_flags
&
1355 NETLOGON_CACHED_ACCOUNT
) {
1356 d_printf("user_flgs: "
1357 "NETLOGON_CACHED_ACCOUNT\n");
1363 for (i
=0; i
< info
->num_blobs
; i
++) {
1364 if (strequal(info
->blobs
[i
].name
,
1366 d_printf("credentials were put "
1369 info
->blobs
[i
].blob
.data
);
1374 d_printf("no credentials cached\n");
1379 wbcFreeMemory(params
.blobs
);
1381 return WBC_ERROR_IS_OK(wbc_status
);
1384 /* Authenticate a user with a plaintext password */
1386 static bool wbinfo_auth(char *username
)
1388 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1391 char *password
= NULL
;
1393 TALLOC_CTX
*frame
= talloc_tos();
1395 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1399 if ((p
= strchr(s
, '%')) != NULL
) {
1402 password
= talloc_strdup(frame
, p
);
1404 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1409 wbc_status
= wbcAuthenticateUser(name
, password
);
1411 d_printf("plaintext password authentication %s\n",
1412 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1415 if (response
.data
.auth
.nt_status
)
1417 "error code was %s (0x%x)\nerror messsage was: %s\n",
1418 response
.data
.auth
.nt_status_string
,
1419 response
.data
.auth
.nt_status
,
1420 response
.data
.auth
.error_string
);
1423 return WBC_ERROR_IS_OK(wbc_status
);
1426 /* Authenticate a user with a challenge/response */
1428 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1430 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1431 struct wbcAuthUserParams params
;
1432 struct wbcAuthUserInfo
*info
= NULL
;
1433 struct wbcAuthErrorInfo
*err
= NULL
;
1434 DATA_BLOB lm
= data_blob_null
;
1435 DATA_BLOB nt
= data_blob_null
;
1437 fstring name_domain
;
1440 TALLOC_CTX
*frame
= talloc_tos();
1442 p
= strchr(username
, '%');
1446 pass
= talloc_strdup(frame
, p
+ 1);
1448 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1451 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1453 params
.account_name
= name_user
;
1454 params
.domain_name
= name_domain
;
1455 params
.workstation_name
= NULL
;
1458 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1459 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1461 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1463 generate_random_buffer(params
.password
.response
.challenge
, 8);
1466 DATA_BLOB server_chal
;
1467 DATA_BLOB names_blob
;
1469 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1471 /* Pretend this is a login to 'us', for blob purposes */
1472 names_blob
= NTLMv2_generate_names_blob(NULL
,
1473 get_winbind_netbios_name(),
1474 get_winbind_domain());
1476 if (!SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1479 &lm
, &nt
, NULL
, NULL
)) {
1480 data_blob_free(&names_blob
);
1481 data_blob_free(&server_chal
);
1485 data_blob_free(&names_blob
);
1486 data_blob_free(&server_chal
);
1491 lm
= data_blob(NULL
, 24);
1492 ok
= SMBencrypt(pass
,
1493 params
.password
.response
.challenge
,
1496 data_blob_free(&lm
);
1499 nt
= data_blob(NULL
, 24);
1500 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1504 params
.password
.response
.nt_length
= nt
.length
;
1505 params
.password
.response
.nt_data
= nt
.data
;
1506 params
.password
.response
.lm_length
= lm
.length
;
1507 params
.password
.response
.lm_data
= lm
.data
;
1509 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1511 /* Display response */
1513 d_printf("challenge/response password authentication %s\n",
1514 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1516 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1518 "error code was %s (0x%x)\nerror messsage was: %s\n",
1521 err
->display_string
);
1523 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1524 wbcFreeMemory(info
);
1527 data_blob_free(&nt
);
1528 data_blob_free(&lm
);
1530 return WBC_ERROR_IS_OK(wbc_status
);
1533 #ifdef WITH_FAKE_KASERVER
1534 /* Authenticate a user with a plaintext password and set a token */
1536 static bool wbinfo_klog(char *username
)
1538 struct winbindd_request request
;
1539 struct winbindd_response response
;
1543 /* Send off request */
1545 ZERO_STRUCT(request
);
1546 ZERO_STRUCT(response
);
1548 p
= strchr(username
, '%');
1552 fstrcpy(request
.data
.auth
.user
, username
);
1553 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
1556 fstrcpy(request
.data
.auth
.user
, username
);
1557 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
1560 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
1562 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
,
1565 /* Display response */
1567 d_printf("plaintext password authentication %s\n",
1568 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
1570 if (response
.data
.auth
.nt_status
)
1572 "error code was %s (0x%x)\nerror messsage was: %s\n",
1573 response
.data
.auth
.nt_status_string
,
1574 response
.data
.auth
.nt_status
,
1575 response
.data
.auth
.error_string
);
1577 if (result
!= NSS_STATUS_SUCCESS
)
1580 if (response
.extra_data
.data
== NULL
) {
1581 d_fprintf(stderr
, "Did not get token data\n");
1585 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
1586 d_fprintf(stderr
, "Could not set token\n");
1590 d_printf("Successfully created AFS token\n");
1594 static bool wbinfo_klog(char *username
)
1596 d_fprintf(stderr
, "No AFS support compiled in.\n");
1601 /* Print domain users */
1603 static bool print_domain_users(const char *domain
)
1605 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1607 uint32_t num_users
= 0;
1608 const char **users
= NULL
;
1610 /* Send request to winbind daemon */
1612 /* '.' is the special sign for our own domain */
1613 if (domain
&& strcmp(domain
, ".") == 0) {
1614 domain
= get_winbind_domain();
1617 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
1618 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1622 for (i
=0; i
< num_users
; i
++) {
1623 d_printf("%s\n", users
[i
]);
1626 wbcFreeMemory(users
);
1631 /* Print domain groups */
1633 static bool print_domain_groups(const char *domain
)
1635 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1637 uint32_t num_groups
= 0;
1638 const char **groups
= NULL
;
1640 /* Send request to winbind daemon */
1642 /* '.' is the special sign for our own domain */
1643 if (domain
&& strcmp(domain
, ".") == 0) {
1644 domain
= get_winbind_domain();
1647 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
1648 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1652 for (i
=0; i
< num_groups
; i
++) {
1653 d_printf("%s\n", groups
[i
]);
1656 wbcFreeMemory(groups
);
1661 /* Set the authorised user for winbindd access in secrets.tdb */
1663 static bool wbinfo_set_auth_user(char *username
)
1665 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1666 "See 'net help setauthuser' for details.\n");
1670 static void wbinfo_get_auth_user(void)
1672 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1673 "See 'net help getauthuser' for details.\n");
1676 static bool wbinfo_ping(void)
1680 wbc_status
= wbcPing();
1682 /* Display response */
1684 d_printf("Ping to winbindd %s\n",
1685 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1687 return WBC_ERROR_IS_OK(wbc_status
);
1690 static bool wbinfo_change_user_password(const char *username
)
1693 char *old_password
= NULL
;
1694 char *new_password
= NULL
;
1695 TALLOC_CTX
*frame
= talloc_tos();
1697 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
1698 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
1700 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
1702 /* Display response */
1704 d_printf("Password change for user %s %s\n", username
,
1705 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1707 return WBC_ERROR_IS_OK(wbc_status
);
1713 OPT_SET_AUTH_USER
= 1000,
1724 OPT_SET_UID_MAPPING
,
1725 OPT_SET_GID_MAPPING
,
1726 OPT_REMOVE_UID_MAPPING
,
1727 OPT_REMOVE_GID_MAPPING
,
1729 OPT_LIST_ALL_DOMAINS
,
1730 OPT_LIST_OWN_DOMAIN
,
1737 OPT_CHANGE_USER_PASSWORD
,
1739 OPT_SID_TO_FULLNAME
,
1744 int main(int argc
, char **argv
, char **envp
)
1747 TALLOC_CTX
*frame
= talloc_stackframe();
1749 static char *string_arg
;
1750 char *string_subarg
= NULL
;
1751 static char *opt_domain_name
;
1753 int int_subarg
= -1;
1755 bool verbose
= false;
1756 bool use_ntlmv2
= false;
1757 bool use_lanman
= false;
1759 struct poptOption long_options
[] = {
1762 /* longName, shortName, argInfo, argPtr, value, descrip,
1765 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1766 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1767 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1768 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1769 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1770 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1771 { "sid-to-fullname", 0, POPT_ARG_STRING
, &string_arg
,
1772 OPT_SID_TO_FULLNAME
, "Converts sid to fullname", "SID" },
1773 { "lookup-rids", 'R', POPT_ARG_STRING
, &string_arg
, 'R', "Converts RIDs to names", "RIDs" },
1774 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1775 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1776 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1777 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1778 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1779 "Get a new UID out of idmap" },
1780 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1781 "Get a new GID out of idmap" },
1782 { "set-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_UID_MAPPING
, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1783 { "set-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_GID_MAPPING
, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1784 { "remove-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_UID_MAPPING
, "Remove uid to sid mapping in idmap", "UID,SID" },
1785 { "remove-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_GID_MAPPING
, "Remove gid to sid mapping in idmap", "GID,SID" },
1786 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1787 { "change-secret", 'c', POPT_ARG_NONE
, 0, 'c', "Change shared secret" },
1788 { "ping-dc", 0, POPT_ARG_NONE
, 0, OPT_PING_DC
,
1789 "Check the NETLOGON connection" },
1790 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1791 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1792 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
1793 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1794 { "online-status", 0, POPT_ARG_NONE
, 0, OPT_ONLINESTATUS
, "Show whether domains are marked as online or offline"},
1795 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1796 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1797 { "uid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_UID_INFO
, "Get user info from uid", "UID" },
1798 { "group-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_GROUP_INFO
, "Get group info", "GROUP" },
1799 { "user-sidinfo", 0, POPT_ARG_STRING
, &string_arg
, OPT_USER_SIDINFO
, "Get user info from sid", "SID" },
1800 { "gid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_GID_INFO
, "Get group info from gid", "GID" },
1801 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1802 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1803 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1804 { "sid-aliases", 0, POPT_ARG_STRING
, &string_arg
, OPT_SIDALIASES
, "Get sid aliases", "SID" },
1805 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1806 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1807 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1808 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1809 "Get a DC name for a foreign domain", "domainname" },
1810 { "dsgetdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_DSGETDCNAME
, "Find a DC for a domain", "domainname" },
1811 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1812 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1813 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1814 #ifdef WITH_FAKE_KASERVER
1815 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1818 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1819 /* destroys wbinfo --help output */
1820 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1822 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1823 { "verbose", 0, POPT_ARG_NONE
, 0, OPT_VERBOSE
, "Print additional information per command", NULL
},
1824 { "change-user-password", 0, POPT_ARG_STRING
, &string_arg
, OPT_CHANGE_USER_PASSWORD
, "Change the password for a user", NULL
},
1825 { "ntlmv2", 0, POPT_ARG_NONE
, 0, OPT_NTLMV2
, "Use NTLMv2 cryptography for user authentication", NULL
},
1826 { "lanman", 0, POPT_ARG_NONE
, 0, OPT_LANMAN
, "Use lanman cryptography for user authentication", NULL
},
1831 /* Samba client initialisation */
1837 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
,
1840 /* Parse command line options */
1843 poptPrintHelp(pc
, stderr
, 0);
1847 while((opt
= poptGetNextOpt(pc
)) != -1) {
1848 /* get the generic configuration parameters like --domain */
1862 poptFreeContext(pc
);
1864 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1865 POPT_CONTEXT_KEEP_FIRST
);
1867 while((opt
= poptGetNextOpt(pc
)) != -1) {
1870 if (!print_domain_users(opt_domain_name
)) {
1872 "Error looking up domain users\n");
1877 if (!print_domain_groups(opt_domain_name
)) {
1879 "Error looking up domain groups\n");
1884 if (!wbinfo_lookupsid(string_arg
)) {
1886 "Could not lookup sid %s\n",
1891 case OPT_SID_TO_FULLNAME
:
1892 if (!wbinfo_lookupsid_fullname(string_arg
)) {
1893 d_fprintf(stderr
, "Could not lookup sid %s\n",
1899 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
1900 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
1906 if (!wbinfo_lookupname(string_arg
)) {
1907 d_fprintf(stderr
, "Could not lookup name %s\n",
1913 if (!wbinfo_wins_byname(string_arg
)) {
1915 "Could not lookup WINS by name %s\n",
1921 if (!wbinfo_wins_byip(string_arg
)) {
1923 "Could not lookup WINS by IP %s\n",
1929 if (!wbinfo_uid_to_sid(int_arg
)) {
1931 "Could not convert uid %d to sid\n",
1937 if (!wbinfo_gid_to_sid(int_arg
)) {
1939 "Could not convert gid %d to sid\n",
1945 if (!wbinfo_sid_to_uid(string_arg
)) {
1947 "Could not convert sid %s to uid\n",
1953 if (!wbinfo_sid_to_gid(string_arg
)) {
1955 "Could not convert sid %s to gid\n",
1960 case OPT_ALLOCATE_UID
:
1961 if (!wbinfo_allocate_uid()) {
1962 d_fprintf(stderr
, "Could not allocate a uid\n");
1966 case OPT_ALLOCATE_GID
:
1967 if (!wbinfo_allocate_gid()) {
1968 d_fprintf(stderr
, "Could not allocate a gid\n");
1972 case OPT_SET_UID_MAPPING
:
1973 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1975 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
1977 d_fprintf(stderr
, "Could not create or modify "
1978 "uid to sid mapping\n");
1982 case OPT_SET_GID_MAPPING
:
1983 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1985 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
1987 d_fprintf(stderr
, "Could not create or modify "
1988 "gid to sid mapping\n");
1992 case OPT_REMOVE_UID_MAPPING
:
1993 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1995 !wbinfo_remove_uid_mapping(int_subarg
,
1998 d_fprintf(stderr
, "Could not remove uid to sid "
2003 case OPT_REMOVE_GID_MAPPING
:
2004 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2006 !wbinfo_remove_gid_mapping(int_subarg
,
2009 d_fprintf(stderr
, "Could not remove gid to sid "
2015 if (!wbinfo_check_secret(opt_domain_name
)) {
2016 d_fprintf(stderr
, "Could not check secret\n");
2021 if (!wbinfo_change_secret(opt_domain_name
)) {
2022 d_fprintf(stderr
, "Could not change secret\n");
2027 if (!wbinfo_ping_dc()) {
2028 d_fprintf(stderr
, "Could not ping our DC\n");
2033 if (!wbinfo_list_domains(false, verbose
)) {
2035 "Could not list trusted domains\n");
2040 if (!wbinfo_show_sequence(opt_domain_name
)) {
2042 "Could not show sequence numbers\n");
2046 case OPT_ONLINESTATUS
:
2047 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
2049 "Could not show online-status\n");
2054 if (!wbinfo_domain_info(string_arg
)) {
2056 "Could not get domain info\n");
2061 if (!wbinfo_get_userinfo(string_arg
)) {
2063 "Could not get info for user %s\n",
2068 case OPT_USER_SIDINFO
:
2069 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
2071 "Could not get info for user "
2072 "sid %s\n", string_arg
);
2077 if ( !wbinfo_get_uidinfo(int_arg
)) {
2078 d_fprintf(stderr
, "Could not get info for uid "
2083 case OPT_GROUP_INFO
:
2084 if ( !wbinfo_get_groupinfo(string_arg
)) {
2085 d_fprintf(stderr
, "Could not get info for "
2086 "group %s\n", string_arg
);
2091 if ( !wbinfo_get_gidinfo(int_arg
)) {
2092 d_fprintf(stderr
, "Could not get info for gid "
2098 if (!wbinfo_get_usergroups(string_arg
)) {
2100 "Could not get groups for user %s\n",
2106 if (!wbinfo_get_usersids(string_arg
)) {
2107 d_fprintf(stderr
, "Could not get group SIDs "
2108 "for user SID %s\n",
2113 case OPT_USERDOMGROUPS
:
2114 if (!wbinfo_get_userdomgroups(string_arg
)) {
2115 d_fprintf(stderr
, "Could not get user's domain "
2116 "groups for user SID %s\n",
2121 case OPT_SIDALIASES
:
2122 if (!wbinfo_get_sidaliases(opt_domain_name
,
2124 d_fprintf(stderr
, "Could not get sid aliases "
2125 "for user SID %s\n", string_arg
);
2130 bool got_error
= false;
2132 if (!wbinfo_auth(string_arg
)) {
2134 "Could not authenticate user "
2135 "%s with plaintext "
2136 "password\n", string_arg
);
2140 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
2143 "Could not authenticate user "
2144 "%s with challenge/response\n",
2154 uint32_t flags
= WBFLAG_PAM_KRB5
|
2155 WBFLAG_PAM_CACHED_LOGIN
|
2156 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
2157 WBFLAG_PAM_INFO3_TEXT
|
2158 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2160 if (!wbinfo_auth_krb5(string_arg
, "FILE",
2163 "Could not authenticate user "
2164 "[%s] with Kerberos "
2165 "(ccache: %s)\n", string_arg
,
2172 if (!wbinfo_klog(string_arg
)) {
2173 d_fprintf(stderr
, "Could not klog user\n");
2178 if (!wbinfo_ping()) {
2179 d_fprintf(stderr
, "could not ping winbindd!\n");
2183 case OPT_SET_AUTH_USER
:
2184 if (!wbinfo_set_auth_user(string_arg
)) {
2188 case OPT_GET_AUTH_USER
:
2189 wbinfo_get_auth_user();
2193 if (!wbinfo_getdcname(string_arg
)) {
2197 case OPT_DSGETDCNAME
:
2198 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
2202 case OPT_SEPARATOR
: {
2203 const char sep
= winbind_separator();
2207 d_printf("%c\n", sep
);
2210 case OPT_LIST_ALL_DOMAINS
:
2211 if (!wbinfo_list_domains(true, verbose
)) {
2215 case OPT_LIST_OWN_DOMAIN
:
2216 if (!wbinfo_list_own_domain()) {
2220 case OPT_CHANGE_USER_PASSWORD
:
2221 if (!wbinfo_change_user_password(string_arg
)) {
2223 "Could not change user password "
2224 "for user %s\n", string_arg
);
2229 /* generic configuration options */
2230 case OPT_DOMAIN_NAME
:
2239 d_fprintf(stderr
, "Invalid option\n");
2240 poptPrintHelp(pc
, stderr
, 0);
2252 poptFreeContext(pc
);