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 /* Change trust account password chose Domain Controller */
854 static bool wbinfo_change_secret_at(const char *domain
,
855 const char *domain_controller
)
857 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
858 struct wbcAuthErrorInfo
*error
= NULL
;
859 const char *domain_name
;
862 domain_name
= domain
;
864 domain_name
= get_winbind_domain();
867 wbc_status
= wbcChangeTrustCredentialsAt(
868 domain_name
, domain_controller
, &error
);
870 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
872 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
874 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
875 d_fprintf(stderr
, "wbcChangeTrustCredentials(%s): "
876 "error code was %s (0x%x)\n",
877 domain_name
, error
->nt_string
, error
->nt_status
);
878 wbcFreeMemory(error
);
880 if (!WBC_ERROR_IS_OK(wbc_status
)) {
881 d_fprintf(stderr
, "failed to call wbcChangeTrustCredentials: "
882 "%s\n", wbcErrorString(wbc_status
));
889 /* Check DC connection */
891 static bool wbinfo_ping_dc(const char *domain
)
893 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
894 struct wbcAuthErrorInfo
*error
= NULL
;
897 const char *domain_name
;
900 domain_name
= domain
;
902 domain_name
= get_winbind_domain();
905 wbc_status
= wbcPingDc2(domain_name
, &error
, &dcname
);
907 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
908 domain_name
? domain_name
: "",
909 dcname
? dcname
: "",
910 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
912 wbcFreeMemory(dcname
);
913 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
914 d_fprintf(stderr
, "wbcPingDc2(%s): error code was %s (0x%x)\n",
915 domain_name
, error
->nt_string
, error
->nt_status
);
916 wbcFreeMemory(error
);
919 if (!WBC_ERROR_IS_OK(wbc_status
)) {
920 d_fprintf(stderr
, "failed to call wbcPingDc: %s\n",
921 wbcErrorString(wbc_status
));
928 /* Convert uid to sid */
930 static bool wbinfo_uid_to_sid(uid_t uid
)
932 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
933 struct wbcDomainSid sid
;
934 char sid_str
[WBC_SID_STRING_BUFLEN
];
938 wbc_status
= wbcUidToSid(uid
, &sid
);
939 if (!WBC_ERROR_IS_OK(wbc_status
)) {
940 d_fprintf(stderr
, "failed to call wbcUidToSid: %s\n",
941 wbcErrorString(wbc_status
));
945 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
947 /* Display response */
949 d_printf("%s\n", sid_str
);
954 /* Convert gid to sid */
956 static bool wbinfo_gid_to_sid(gid_t gid
)
958 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
959 struct wbcDomainSid sid
;
960 char sid_str
[WBC_SID_STRING_BUFLEN
];
964 wbc_status
= wbcGidToSid(gid
, &sid
);
965 if (!WBC_ERROR_IS_OK(wbc_status
)) {
966 d_fprintf(stderr
, "failed to call wbcGidToSid: %s\n",
967 wbcErrorString(wbc_status
));
971 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
973 /* Display response */
975 d_printf("%s\n", sid_str
);
980 /* Convert sid to uid */
982 static bool wbinfo_sid_to_uid(const char *sid_str
)
984 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
985 struct wbcDomainSid sid
;
990 wbc_status
= wbcStringToSid(sid_str
, &sid
);
991 if (!WBC_ERROR_IS_OK(wbc_status
)) {
992 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
993 wbcErrorString(wbc_status
));
997 wbc_status
= wbcSidToUid(&sid
, &uid
);
998 if (!WBC_ERROR_IS_OK(wbc_status
)) {
999 d_fprintf(stderr
, "failed to call wbcSidToUid: %s\n",
1000 wbcErrorString(wbc_status
));
1004 /* Display response */
1006 d_printf("%d\n", (int)uid
);
1011 static bool wbinfo_sid_to_gid(const char *sid_str
)
1013 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1014 struct wbcDomainSid sid
;
1019 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1020 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1021 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1022 wbcErrorString(wbc_status
));
1026 wbc_status
= wbcSidToGid(&sid
, &gid
);
1027 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1028 d_fprintf(stderr
, "failed to call wbcSidToGid: %s\n",
1029 wbcErrorString(wbc_status
));
1033 /* Display response */
1035 d_printf("%d\n", (int)gid
);
1040 static bool wbinfo_sids_to_unix_ids(const char *arg
)
1042 char sidstr
[WBC_SID_STRING_BUFLEN
];
1043 struct wbcDomainSid
*sids
;
1044 struct wbcUnixId
*unix_ids
;
1054 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1055 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1058 d_fprintf(stderr
, "talloc failed\n");
1061 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1062 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1063 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1064 sidstr
, wbcErrorString(wbc_status
));
1071 unix_ids
= talloc_array(talloc_tos(), struct wbcUnixId
, num_sids
);
1072 if (unix_ids
== NULL
) {
1077 wbc_status
= wbcSidsToUnixIds(sids
, num_sids
, unix_ids
);
1078 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1079 d_fprintf(stderr
, "wbcSidsToUnixIds failed: %s\n",
1080 wbcErrorString(wbc_status
));
1085 for (i
=0; i
<num_sids
; i
++) {
1087 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1089 switch(unix_ids
[i
].type
) {
1090 case WBC_ID_TYPE_UID
:
1091 d_printf("%s -> uid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1093 case WBC_ID_TYPE_GID
:
1094 d_printf("%s -> gid %d\n", sidstr
, unix_ids
[i
].id
.gid
);
1096 case WBC_ID_TYPE_BOTH
:
1097 d_printf("%s -> uid/gid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1100 d_printf("%s -> unmapped\n", sidstr
);
1106 TALLOC_FREE(unix_ids
);
1111 static bool wbinfo_xids_to_sids(const char *arg
)
1114 struct wbcUnixId
*xids
= NULL
;
1115 struct wbcDomainSid
*sids
;
1123 while (next_token(&p
, idstr
, LIST_SEP
, sizeof(idstr
))) {
1124 xids
= talloc_realloc(talloc_tos(), xids
, struct wbcUnixId
,
1127 d_fprintf(stderr
, "talloc failed\n");
1133 xids
[num_xids
] = (struct wbcUnixId
) {
1134 .type
= WBC_ID_TYPE_UID
,
1135 .id
.uid
= atoi(&idstr
[1])
1139 xids
[num_xids
] = (struct wbcUnixId
) {
1140 .type
= WBC_ID_TYPE_GID
,
1141 .id
.gid
= atoi(&idstr
[1])
1145 d_fprintf(stderr
, "%s is an invalid id\n", idstr
);
1152 sids
= talloc_array(talloc_tos(), struct wbcDomainSid
, num_xids
);
1154 d_fprintf(stderr
, "talloc failed\n");
1159 wbc_status
= wbcUnixIdsToSids(xids
, num_xids
, sids
);
1160 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1161 d_fprintf(stderr
, "wbcUnixIdsToSids failed: %s\n",
1162 wbcErrorString(wbc_status
));
1168 for (i
=0; i
<num_xids
; i
++) {
1169 char str
[WBC_SID_STRING_BUFLEN
];
1170 struct wbcDomainSid null_sid
= { 0 };
1172 if (memcmp(&null_sid
, &sids
[i
], sizeof(struct wbcDomainSid
)) == 0) {
1173 d_printf("NOT MAPPED\n");
1176 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
1177 d_printf("%s\n", str
);
1183 static bool wbinfo_allocate_uid(void)
1185 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1190 wbc_status
= wbcAllocateUid(&uid
);
1191 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1192 d_fprintf(stderr
, "failed to call wbcAllocateUid: %s\n",
1193 wbcErrorString(wbc_status
));
1197 /* Display response */
1199 d_printf("New uid: %u\n", (unsigned int)uid
);
1204 static bool wbinfo_allocate_gid(void)
1206 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1211 wbc_status
= wbcAllocateGid(&gid
);
1212 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1213 d_fprintf(stderr
, "failed to call wbcAllocateGid: %s\n",
1214 wbcErrorString(wbc_status
));
1218 /* Display response */
1220 d_printf("New gid: %u\n", (unsigned int)gid
);
1225 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
1227 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1228 struct wbcDomainSid sid
;
1232 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1233 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1234 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1235 wbcErrorString(wbc_status
));
1239 wbc_status
= wbcSetUidMapping(uid
, &sid
);
1240 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1241 d_fprintf(stderr
, "failed to call wbcSetUidMapping: %s\n",
1242 wbcErrorString(wbc_status
));
1246 /* Display response */
1248 d_printf("uid %u now mapped to sid %s\n",
1249 (unsigned int)uid
, sid_str
);
1254 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
1256 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1257 struct wbcDomainSid sid
;
1261 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1262 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1263 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1264 wbcErrorString(wbc_status
));
1268 wbc_status
= wbcSetGidMapping(gid
, &sid
);
1269 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1270 d_fprintf(stderr
, "failed to call wbcSetGidMapping: %s\n",
1271 wbcErrorString(wbc_status
));
1275 /* Display response */
1277 d_printf("gid %u now mapped to sid %s\n",
1278 (unsigned int)gid
, sid_str
);
1283 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1285 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1286 struct wbcDomainSid sid
;
1290 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1291 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1292 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1293 wbcErrorString(wbc_status
));
1297 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1298 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1299 d_fprintf(stderr
, "failed to call wbcRemoveUidMapping: %s\n",
1300 wbcErrorString(wbc_status
));
1304 /* Display response */
1306 d_printf("Removed uid %u to sid %s mapping\n",
1307 (unsigned int)uid
, sid_str
);
1312 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1314 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1315 struct wbcDomainSid sid
;
1319 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1320 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1321 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1322 wbcErrorString(wbc_status
));
1326 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1327 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1328 d_fprintf(stderr
, "failed to call wbcRemoveGidMapping: %s\n",
1329 wbcErrorString(wbc_status
));
1333 /* Display response */
1335 d_printf("Removed gid %u to sid %s mapping\n",
1336 (unsigned int)gid
, sid_str
);
1341 /* Convert sid to string */
1343 static bool wbinfo_lookupsid(const char *sid_str
)
1345 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1346 struct wbcDomainSid sid
;
1349 enum wbcSidType type
;
1351 /* Send off request */
1353 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1354 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1355 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1356 wbcErrorString(wbc_status
));
1360 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1361 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1362 d_fprintf(stderr
, "failed to call wbcLookupSid: %s\n",
1363 wbcErrorString(wbc_status
));
1367 /* Display response */
1369 if (type
== WBC_SID_NAME_DOMAIN
) {
1370 d_printf("%s %d\n", domain
, type
);
1372 d_printf("%s%c%s %d\n",
1373 domain
, winbind_separator(), name
, type
);
1376 wbcFreeMemory(domain
);
1377 wbcFreeMemory(name
);
1382 /* Convert sid to fullname */
1384 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1386 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1387 struct wbcDomainSid sid
;
1390 enum wbcSidType type
;
1392 /* Send off request */
1394 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1395 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1396 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1397 wbcErrorString(wbc_status
));
1401 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1402 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1403 d_fprintf(stderr
, "failed to call wbcGetDisplayName: %s\n",
1404 wbcErrorString(wbc_status
));
1408 /* Display response */
1410 d_printf("%s%c%s %d\n",
1411 domain
, winbind_separator(), name
, type
);
1413 wbcFreeMemory(domain
);
1414 wbcFreeMemory(name
);
1419 /* Lookup a list of RIDs */
1421 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1423 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1424 struct wbcDomainSid dsid
;
1425 char *domain_name
= NULL
;
1426 const char **names
= NULL
;
1427 enum wbcSidType
*types
= NULL
;
1429 uint32_t *rids
= NULL
;
1432 TALLOC_CTX
*mem_ctx
= NULL
;
1435 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1436 domain
= get_winbind_domain();
1439 wbc_status
= wbcStringToSid(domain
, &dsid
);
1440 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1441 struct wbcDomainInfo
*dinfo
= NULL
;
1443 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1444 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1445 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1446 wbcErrorString(wbc_status
));
1451 wbcFreeMemory(dinfo
);
1454 mem_ctx
= talloc_new(NULL
);
1455 if (mem_ctx
== NULL
) {
1456 d_printf("talloc_new failed\n");
1464 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1468 rid
= smb_strtoul(ridstr
, NULL
, 10, &error
, SMB_STR_STANDARD
);
1470 d_printf("failed to convert rid\n");
1473 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1475 d_printf("talloc_realloc failed\n");
1477 rids
[num_rids
] = rid
;
1482 d_printf("no rids\n");
1486 wbc_status
= wbcLookupRids(
1487 &dsid
, num_rids
, rids
, &p
, &names
, &types
);
1488 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1489 d_printf("winbind_lookup_rids failed: %s\n",
1490 wbcErrorString(wbc_status
));
1494 domain_name
= discard_const_p(char, p
);
1495 d_printf("Domain: %s\n", domain_name
);
1497 for (i
=0; i
<num_rids
; i
++) {
1498 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1499 wbcSidTypeString(types
[i
]));
1504 wbcFreeMemory(domain_name
);
1505 wbcFreeMemory(names
);
1506 wbcFreeMemory(types
);
1507 TALLOC_FREE(mem_ctx
);
1511 static bool wbinfo_lookup_sids(const char *arg
)
1513 char sidstr
[WBC_SID_STRING_BUFLEN
];
1514 struct wbcDomainSid
*sids
;
1515 struct wbcDomainInfo
*domains
;
1516 struct wbcTranslatedName
*names
;
1527 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1528 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1531 d_fprintf(stderr
, "talloc failed\n");
1534 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1535 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1536 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1537 sidstr
, wbcErrorString(wbc_status
));
1544 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1546 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1547 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1548 wbcErrorString(wbc_status
));
1553 for (i
=0; i
<num_sids
; i
++) {
1554 const char *domain
= NULL
;
1556 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1558 if (names
[i
].domain_index
>= num_domains
) {
1560 } else if (names
[i
].domain_index
< 0) {
1563 domain
= domains
[names
[i
].domain_index
].short_name
;
1566 if (names
[i
].type
== WBC_SID_NAME_DOMAIN
) {
1567 d_printf("%s -> %s %d\n", sidstr
,
1571 d_printf("%s -> %s%c%s %d\n", sidstr
,
1573 winbind_separator(),
1574 names
[i
].name
, names
[i
].type
);
1577 wbcFreeMemory(names
);
1578 wbcFreeMemory(domains
);
1582 /* Convert string to sid */
1584 static bool wbinfo_lookupname(const char *full_name
)
1586 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1587 struct wbcDomainSid sid
;
1588 char sid_str
[WBC_SID_STRING_BUFLEN
];
1589 enum wbcSidType type
;
1590 fstring domain_name
;
1591 fstring account_name
;
1593 /* Send off request */
1595 parse_wbinfo_domain_user(full_name
, domain_name
,
1598 wbc_status
= wbcLookupName(domain_name
, account_name
,
1600 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1601 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1602 wbcErrorString(wbc_status
));
1606 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1608 /* Display response */
1610 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1615 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1617 const char *username
)
1620 char buf
[1024] = {0};
1623 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1628 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1633 prompt
= talloc_asprintf_append(prompt
, "password: ");
1638 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1639 TALLOC_FREE(prompt
);
1644 return talloc_strdup(mem_ctx
, buf
);
1647 /* Authenticate a user with a plaintext password */
1649 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1651 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1654 char *password
= NULL
;
1656 char *local_cctype
= NULL
;
1658 struct wbcLogonUserParams params
;
1659 struct wbcLogonUserInfo
*info
= NULL
;
1660 struct wbcAuthErrorInfo
*error
= NULL
;
1661 struct wbcUserPasswordPolicyInfo
*policy
= NULL
;
1662 TALLOC_CTX
*frame
= talloc_tos();
1664 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1668 if ((p
= strchr(s
, '%')) != NULL
) {
1671 password
= talloc_strdup(frame
, p
);
1673 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1676 local_cctype
= talloc_strdup(frame
, cctype
);
1682 params
.username
= name
;
1683 params
.password
= password
;
1684 params
.num_blobs
= 0;
1685 params
.blobs
= NULL
;
1687 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1693 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1694 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1695 wbcErrorString(wbc_status
));
1699 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1705 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1706 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1707 wbcErrorString(wbc_status
));
1711 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1715 (uint8_t *)local_cctype
,
1717 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1718 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1719 wbcErrorString(wbc_status
));
1723 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1725 d_printf("plaintext kerberos password authentication for [%s] %s "
1726 "(requesting cctype: %s)\n",
1727 name
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1732 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1733 "error message was: %s\n",
1734 params
.username
, error
->nt_string
,
1736 error
->display_string
);
1739 if (WBC_ERROR_IS_OK(wbc_status
)) {
1740 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1741 if (info
&& info
->info
&& info
->info
->user_flags
&
1742 NETLOGON_CACHED_ACCOUNT
) {
1743 d_printf("user_flgs: "
1744 "NETLOGON_CACHED_ACCOUNT\n");
1750 for (i
=0; i
< info
->num_blobs
; i
++) {
1751 if (strequal(info
->blobs
[i
].name
,
1753 d_printf("credentials were put "
1756 info
->blobs
[i
].blob
.data
);
1761 d_printf("no credentials cached\n");
1765 wbcFreeMemory(error
);
1766 wbcFreeMemory(policy
);
1767 wbcFreeMemory(info
);
1768 wbcFreeMemory(params
.blobs
);
1770 return WBC_ERROR_IS_OK(wbc_status
);
1773 /* Authenticate a user with a plaintext password */
1775 static bool wbinfo_auth(char *username
)
1777 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1780 char *password
= NULL
;
1782 TALLOC_CTX
*frame
= talloc_tos();
1784 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1788 if ((p
= strchr(s
, '%')) != NULL
) {
1791 password
= talloc_strdup(frame
, p
);
1793 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1798 wbc_status
= wbcAuthenticateUser(name
, password
);
1800 d_printf("plaintext password authentication %s\n",
1801 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1804 if (response
.data
.auth
.nt_status
)
1806 "error code was %s (0x%x)\nerror message was: %s\n",
1807 response
.data
.auth
.nt_status_string
,
1808 response
.data
.auth
.nt_status
,
1809 response
.data
.auth
.error_string
);
1812 return WBC_ERROR_IS_OK(wbc_status
);
1815 /* Authenticate a user with a challenge/response */
1817 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1819 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1820 struct wbcAuthUserParams params
;
1821 struct wbcAuthUserInfo
*info
= NULL
;
1822 struct wbcAuthErrorInfo
*err
= NULL
;
1823 DATA_BLOB lm
= data_blob_null
;
1824 DATA_BLOB nt
= data_blob_null
;
1826 fstring name_domain
;
1829 TALLOC_CTX
*frame
= talloc_tos();
1831 p
= strchr(username
, '%');
1835 pass
= talloc_strdup(frame
, p
+ 1);
1837 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1840 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1842 params
.account_name
= name_user
;
1843 params
.domain_name
= name_domain
;
1844 params
.workstation_name
= NULL
;
1847 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1848 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1850 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1852 generate_random_buffer(params
.password
.response
.challenge
, 8);
1855 DATA_BLOB server_chal
;
1856 DATA_BLOB names_blob
;
1857 const char *netbios_name
= NULL
;
1858 const char *domain
= NULL
;
1860 netbios_name
= get_winbind_netbios_name(),
1861 domain
= get_winbind_domain();
1862 if (domain
== NULL
) {
1863 d_fprintf(stderr
, "Failed to get domain from winbindd\n");
1867 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1869 /* Pretend this is a login to 'us', for blob purposes */
1870 names_blob
= NTLMv2_generate_names_blob(NULL
,
1875 !SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1878 &lm
, &nt
, NULL
, NULL
)) {
1879 data_blob_free(&names_blob
);
1880 data_blob_free(&server_chal
);
1884 data_blob_free(&names_blob
);
1885 data_blob_free(&server_chal
);
1890 lm
= data_blob(NULL
, 24);
1891 ok
= SMBencrypt(pass
,
1892 params
.password
.response
.challenge
,
1895 data_blob_free(&lm
);
1898 nt
= data_blob(NULL
, 24);
1899 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1903 params
.password
.response
.nt_length
= nt
.length
;
1904 params
.password
.response
.nt_data
= nt
.data
;
1905 params
.password
.response
.lm_length
= lm
.length
;
1906 params
.password
.response
.lm_data
= lm
.data
;
1908 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1910 /* Display response */
1912 d_printf("challenge/response password authentication %s\n",
1913 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1915 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1917 "wbcAuthenticateUserEx(%s%c%s): error code was "
1918 "%s (0x%x, authoritative=%"PRIu8
")\n"
1919 "error message was: %s\n",
1921 winbind_separator(),
1926 err
->display_string
);
1928 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1929 wbcFreeMemory(info
);
1932 data_blob_free(&nt
);
1933 data_blob_free(&lm
);
1935 return WBC_ERROR_IS_OK(wbc_status
);
1938 /* Authenticate a user with a plaintext password */
1940 static bool wbinfo_pam_logon(char *username
, bool verbose
)
1942 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1943 struct wbcLogonUserParams params
;
1944 struct wbcLogonUserInfo
*info
= NULL
;
1945 struct wbcAuthErrorInfo
*error
= NULL
;
1948 TALLOC_CTX
*frame
= talloc_tos();
1952 ZERO_STRUCT(params
);
1954 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1958 if ((p
= strchr(s
, '%')) != NULL
) {
1961 params
.password
= talloc_strdup(frame
, p
);
1963 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1965 params
.username
= s
;
1967 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1969 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1971 (uint8_t *)&flags
, sizeof(flags
));
1972 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1973 d_printf("wbcAddNamedBlob failed: %s\n",
1974 wbcErrorString(wbc_status
));
1980 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1982 (uint8_t *)&uid
, sizeof(uid
));
1983 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1984 d_printf("wbcAddNamedBlob failed: %s\n",
1985 wbcErrorString(wbc_status
));
1989 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, NULL
);
1991 if (verbose
&& (info
!= NULL
)) {
1992 struct wbcAuthUserInfo
*i
= info
->info
;
1995 if (i
->account_name
!= NULL
) {
1996 d_printf("account_name: %s\n", i
->account_name
);
1998 if (i
->user_principal
!= NULL
) {
1999 d_printf("user_principal: %s\n", i
->user_principal
);
2001 if (i
->full_name
!= NULL
) {
2002 d_printf("full_name: %s\n", i
->full_name
);
2004 if (i
->domain_name
!= NULL
) {
2005 d_printf("domain_name: %s\n", i
->domain_name
);
2007 if (i
->dns_domain_name
!= NULL
) {
2008 d_printf("dns_domain_name: %s\n", i
->dns_domain_name
);
2010 if (i
->logon_server
!= NULL
) {
2011 d_printf("logon_server: %s\n", i
->logon_server
);
2013 if (i
->logon_script
!= NULL
) {
2014 d_printf("logon_script: %s\n", i
->logon_script
);
2016 if (i
->profile_path
!= NULL
) {
2017 d_printf("profile_path: %s\n", i
->profile_path
);
2019 if (i
->home_directory
!= NULL
) {
2020 d_printf("home_directory: %s\n", i
->home_directory
);
2022 if (i
->home_drive
!= NULL
) {
2023 d_printf("home_drive: %s\n", i
->home_drive
);
2028 for (j
=0; j
<i
->num_sids
; j
++) {
2029 char buf
[WBC_SID_STRING_BUFLEN
];
2030 wbcSidToStringBuf(&i
->sids
[j
].sid
, buf
, sizeof(buf
));
2031 d_printf(" %s", buf
);
2035 wbcFreeMemory(info
);
2039 wbcFreeMemory(params
.blobs
);
2041 d_printf("plaintext password authentication %s\n",
2042 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2044 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
2046 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2047 "error message was: %s\n",
2050 (int)error
->nt_status
,
2051 error
->display_string
);
2052 wbcFreeMemory(error
);
2054 return WBC_ERROR_IS_OK(wbc_status
);
2057 /* Save creds with winbind */
2059 static bool wbinfo_ccache_save(char *username
)
2061 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2064 char *password
= NULL
;
2066 TALLOC_CTX
*frame
= talloc_stackframe();
2068 s
= talloc_strdup(frame
, username
);
2077 password
= talloc_strdup(frame
, p
);
2079 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
2084 wbc_status
= wbcCredentialSave(name
, password
);
2086 d_printf("saving creds %s\n",
2087 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2091 return WBC_ERROR_IS_OK(wbc_status
);
2094 #ifdef WITH_FAKE_KASERVER
2095 /* Authenticate a user with a plaintext password and set a token */
2097 static bool wbinfo_klog(char *username
)
2099 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2100 struct winbindd_request request
;
2101 struct winbindd_response response
;
2104 /* Send off request */
2106 ZERO_STRUCT(request
);
2107 ZERO_STRUCT(response
);
2109 p
= strchr(username
, '%');
2113 fstrcpy(request
.data
.auth
.user
, username
);
2114 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
2117 fstrcpy(request
.data
.auth
.user
, username
);
2118 (void) samba_getpass("Password: ",
2119 request
.data
.auth
.pass
,
2120 sizeof(request
.data
.auth
.pass
),
2124 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
2126 wbc_status
= wbcRequestResponse(NULL
, WINBINDD_PAM_AUTH
,
2127 &request
, &response
);
2129 /* Display response */
2131 d_printf("plaintext password authentication %s\n",
2132 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2134 if (response
.data
.auth
.nt_status
)
2136 "error code was %s (0x%x)\nerror message was: %s\n",
2137 response
.data
.auth
.nt_status_string
,
2138 response
.data
.auth
.nt_status
,
2139 response
.data
.auth
.error_string
);
2141 if (!WBC_ERROR_IS_OK(wbc_status
))
2144 if (response
.extra_data
.data
== NULL
) {
2145 d_fprintf(stderr
, "Did not get token data\n");
2149 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
2150 winbindd_free_response(&response
);
2151 d_fprintf(stderr
, "Could not set token\n");
2155 winbindd_free_response(&response
);
2156 d_printf("Successfully created AFS token\n");
2160 static bool wbinfo_klog(char *username
)
2162 d_fprintf(stderr
, "No AFS support compiled in.\n");
2167 /* Print domain users */
2169 static bool print_domain_users(const char *domain
)
2171 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2173 uint32_t num_users
= 0;
2174 const char **users
= NULL
;
2176 /* Send request to winbind daemon */
2178 if (domain
== NULL
) {
2179 domain
= get_winbind_domain();
2181 /* '.' is the special sign for our own domain */
2182 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2183 domain
= get_winbind_domain();
2184 /* '*' is the special sign for all domains */
2185 } else if (strcmp(domain
, "*") == 0) {
2190 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
2191 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2195 for (i
=0; i
< num_users
; i
++) {
2196 d_printf("%s\n", users
[i
]);
2199 wbcFreeMemory(users
);
2204 /* Print domain groups */
2206 static bool print_domain_groups(const char *domain
)
2208 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2210 uint32_t num_groups
= 0;
2211 const char **groups
= NULL
;
2213 /* Send request to winbind daemon */
2215 if (domain
== NULL
) {
2216 domain
= get_winbind_domain();
2218 /* '.' is the special sign for our own domain */
2219 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2220 domain
= get_winbind_domain();
2221 /* '*' is the special sign for all domains */
2222 } else if (strcmp(domain
, "*") == 0) {
2227 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
2228 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2229 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
2230 wbcErrorString(wbc_status
));
2234 for (i
=0; i
< num_groups
; i
++) {
2235 d_printf("%s\n", groups
[i
]);
2238 wbcFreeMemory(groups
);
2243 /* Set the authorised user for winbindd access in secrets.tdb */
2245 static bool wbinfo_set_auth_user(char *username
)
2247 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2248 "See 'net help setauthuser' for details.\n");
2252 static void wbinfo_get_auth_user(void)
2254 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2255 "See 'net help getauthuser' for details.\n");
2258 static bool wbinfo_ping(void)
2262 wbc_status
= wbcPing();
2264 /* Display response */
2266 d_printf("Ping to winbindd %s\n",
2267 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2269 return WBC_ERROR_IS_OK(wbc_status
);
2272 static bool wbinfo_change_user_password(const char *username
)
2275 char *old_password
= NULL
;
2276 char *new_password
= NULL
;
2277 TALLOC_CTX
*frame
= talloc_tos();
2279 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2280 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2282 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2284 /* Display response */
2286 d_printf("Password change for user %s %s\n", username
,
2287 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2289 return WBC_ERROR_IS_OK(wbc_status
);
2295 OPT_SET_AUTH_USER
= 1000,
2308 OPT_SET_UID_MAPPING
,
2309 OPT_SET_GID_MAPPING
,
2310 OPT_REMOVE_UID_MAPPING
,
2311 OPT_REMOVE_GID_MAPPING
,
2315 OPT_LIST_ALL_DOMAINS
,
2316 OPT_LIST_OWN_DOMAIN
,
2323 OPT_CHANGE_USER_PASSWORD
,
2325 OPT_SID_TO_FULLNAME
,
2334 OPT_CHANGE_SECRET_AT
2337 int main(int argc
, const char **argv
, char **envp
)
2340 TALLOC_CTX
*frame
= talloc_stackframe();
2342 static char *string_arg
;
2343 char *string_subarg
= NULL
;
2344 static char *opt_domain_name
;
2346 int int_subarg
= -1;
2348 bool verbose
= false;
2349 bool use_ntlmv2
= true;
2350 bool use_lanman
= false;
2351 char *logoff_user
= getenv("USER");
2352 int logoff_uid
= geteuid();
2353 const char *opt_krb5ccname
= "FILE";
2355 struct poptOption long_options
[] = {
2358 /* longName, shortName, argInfo, argPtr, value, descrip,
2362 .longName
= "domain-users",
2364 .argInfo
= POPT_ARG_NONE
,
2366 .descrip
= "Lists all domain users",
2367 .argDescrip
= "domain"
2370 .longName
= "domain-groups",
2372 .argInfo
= POPT_ARG_NONE
,
2374 .descrip
= "Lists all domain groups",
2375 .argDescrip
= "domain"
2378 .longName
= "WINS-by-name",
2380 .argInfo
= POPT_ARG_STRING
,
2383 .descrip
= "Converts NetBIOS name to IP",
2384 .argDescrip
= "NETBIOS-NAME"
2387 .longName
= "WINS-by-ip",
2389 .argInfo
= POPT_ARG_STRING
,
2392 .descrip
= "Converts IP address to NetBIOS name",
2396 .longName
= "name-to-sid",
2398 .argInfo
= POPT_ARG_STRING
,
2401 .descrip
= "Converts name to sid",
2402 .argDescrip
= "NAME"
2405 .longName
= "sid-to-name",
2407 .argInfo
= POPT_ARG_STRING
,
2410 .descrip
= "Converts sid to name",
2414 .longName
= "sid-to-fullname",
2415 .argInfo
= POPT_ARG_STRING
,
2417 .val
= OPT_SID_TO_FULLNAME
,
2418 .descrip
= "Converts sid to fullname",
2422 .longName
= "lookup-rids",
2424 .argInfo
= POPT_ARG_STRING
,
2427 .descrip
= "Converts RIDs to names",
2428 .argDescrip
= "RIDs"
2431 .longName
= "lookup-sids",
2432 .argInfo
= POPT_ARG_STRING
,
2434 .val
= OPT_LOOKUP_SIDS
,
2435 .descrip
= "Converts SIDs to types and names",
2436 .argDescrip
= "Sid-List"
2439 .longName
= "uid-to-sid",
2441 .argInfo
= POPT_ARG_INT
,
2444 .descrip
= "Converts uid to sid",
2448 .longName
= "gid-to-sid",
2450 .argInfo
= POPT_ARG_INT
,
2453 .descrip
= "Converts gid to sid",
2457 .longName
= "sid-to-uid",
2459 .argInfo
= POPT_ARG_STRING
,
2462 .descrip
= "Converts sid to uid",
2466 .longName
= "sid-to-gid",
2468 .argInfo
= POPT_ARG_STRING
,
2471 .descrip
= "Converts sid to gid",
2475 .longName
= "allocate-uid",
2476 .argInfo
= POPT_ARG_NONE
,
2477 .val
= OPT_ALLOCATE_UID
,
2478 .descrip
= "Get a new UID out of idmap"
2481 .longName
= "allocate-gid",
2482 .argInfo
= POPT_ARG_NONE
,
2483 .val
= OPT_ALLOCATE_GID
,
2484 .descrip
= "Get a new GID out of idmap"
2487 .longName
= "set-uid-mapping",
2488 .argInfo
= POPT_ARG_STRING
,
2490 .val
= OPT_SET_UID_MAPPING
,
2491 .descrip
= "Create or modify uid to sid mapping in "
2493 .argDescrip
= "UID,SID"
2496 .longName
= "set-gid-mapping",
2497 .argInfo
= POPT_ARG_STRING
,
2499 .val
= OPT_SET_GID_MAPPING
,
2500 .descrip
= "Create or modify gid to sid mapping in "
2502 .argDescrip
= "GID,SID"
2505 .longName
= "remove-uid-mapping",
2506 .argInfo
= POPT_ARG_STRING
,
2508 .val
= OPT_REMOVE_UID_MAPPING
,
2509 .descrip
= "Remove uid to sid mapping in idmap",
2510 .argDescrip
= "UID,SID"
2513 .longName
= "remove-gid-mapping",
2514 .argInfo
= POPT_ARG_STRING
,
2516 .val
= OPT_REMOVE_GID_MAPPING
,
2517 .descrip
= "Remove gid to sid mapping in idmap",
2518 .argDescrip
= "GID,SID",
2521 .longName
= "sids-to-unix-ids",
2522 .argInfo
= POPT_ARG_STRING
,
2524 .val
= OPT_SIDS_TO_XIDS
,
2525 .descrip
= "Translate SIDs to Unix IDs",
2526 .argDescrip
= "Sid-List",
2529 .longName
= "unix-ids-to-sids",
2530 .argInfo
= POPT_ARG_STRING
,
2532 .val
= OPT_XIDS_TO_SIDS
,
2533 .descrip
= "Translate Unix IDs to SIDs",
2534 .argDescrip
= "ID-List (u<num> g<num>)",
2537 .longName
= "check-secret",
2539 .argInfo
= POPT_ARG_NONE
,
2541 .descrip
= "Check shared secret",
2544 .longName
= "change-secret",
2546 .argInfo
= POPT_ARG_NONE
,
2548 .descrip
= "Change shared secret",
2551 .longName
= "change-secret-at",
2553 .argInfo
= POPT_ARG_STRING
,
2555 .val
= OPT_CHANGE_SECRET_AT
,
2556 .descrip
= "Change shared secret at Domain Controller" },
2558 .longName
= "ping-dc",
2560 .argInfo
= POPT_ARG_NONE
,
2562 .descrip
= "Check the NETLOGON connection",
2565 .longName
= "trusted-domains",
2567 .argInfo
= POPT_ARG_NONE
,
2569 .descrip
= "List trusted domains",
2572 .longName
= "all-domains",
2573 .argInfo
= POPT_ARG_NONE
,
2574 .val
= OPT_LIST_ALL_DOMAINS
,
2575 .descrip
= "List all domains (trusted and own "
2579 .longName
= "own-domain",
2580 .argInfo
= POPT_ARG_NONE
,
2581 .val
= OPT_LIST_OWN_DOMAIN
,
2582 .descrip
= "List own domain",
2585 .longName
= "sequence",
2586 .argInfo
= POPT_ARG_NONE
,
2587 .val
= OPT_SEQUENCE
,
2588 .descrip
= "Deprecated command, see --online-status",
2591 .longName
= "online-status",
2592 .argInfo
= POPT_ARG_NONE
,
2593 .val
= OPT_ONLINESTATUS
,
2594 .descrip
= "Show whether domains maintain an active "
2598 .longName
= "domain-info",
2600 .argInfo
= POPT_ARG_STRING
,
2603 .descrip
= "Show most of the info we have about the "
2607 .longName
= "user-info",
2609 .argInfo
= POPT_ARG_STRING
,
2612 .descrip
= "Get user info",
2613 .argDescrip
= "USER",
2616 .longName
= "uid-info",
2617 .argInfo
= POPT_ARG_INT
,
2619 .val
= OPT_UID_INFO
,
2620 .descrip
= "Get user info from uid",
2621 .argDescrip
= "UID",
2624 .longName
= "group-info",
2625 .argInfo
= POPT_ARG_STRING
,
2627 .val
= OPT_GROUP_INFO
,
2628 .descrip
= "Get group info",
2629 .argDescrip
= "GROUP",
2632 .longName
= "user-sidinfo",
2633 .argInfo
= POPT_ARG_STRING
,
2635 .val
= OPT_USER_SIDINFO
,
2636 .descrip
= "Get user info from sid",
2637 .argDescrip
= "SID",
2640 .longName
= "gid-info",
2641 .argInfo
= POPT_ARG_INT
,
2643 .val
= OPT_GID_INFO
,
2644 .descrip
= "Get group info from gid",
2645 .argDescrip
= "GID",
2648 .longName
= "user-groups",
2650 .argInfo
= POPT_ARG_STRING
,
2653 .descrip
= "Get user groups",
2654 .argDescrip
= "USER",
2657 .longName
= "user-domgroups",
2658 .argInfo
= POPT_ARG_STRING
,
2660 .val
= OPT_USERDOMGROUPS
,
2661 .descrip
= "Get user domain groups",
2662 .argDescrip
= "SID",
2665 .longName
= "sid-aliases",
2666 .argInfo
= POPT_ARG_STRING
,
2668 .val
= OPT_SIDALIASES
,
2669 .descrip
= "Get sid aliases",
2670 .argDescrip
= "SID",
2673 .longName
= "user-sids",
2674 .argInfo
= POPT_ARG_STRING
,
2676 .val
= OPT_USERSIDS
,
2677 .descrip
= "Get user group sids for user SID",
2678 .argDescrip
= "SID",
2681 .longName
= "authenticate",
2683 .argInfo
= POPT_ARG_STRING
,
2686 .descrip
= "authenticate user",
2687 .argDescrip
= "user%password",
2690 .longName
= "pam-logon",
2691 .argInfo
= POPT_ARG_STRING
,
2693 .val
= OPT_PAM_LOGON
,
2694 .descrip
= "do a pam logon equivalent",
2695 .argDescrip
= "user%password",
2698 .longName
= "logoff",
2699 .argInfo
= POPT_ARG_NONE
,
2701 .descrip
= "log off user",
2702 .argDescrip
= "uid",
2705 .longName
= "logoff-user",
2706 .argInfo
= POPT_ARG_STRING
,
2707 .arg
= &logoff_user
,
2708 .val
= OPT_LOGOFF_USER
,
2709 .descrip
= "username to log off"
2712 .longName
= "logoff-uid",
2713 .argInfo
= POPT_ARG_INT
,
2715 .val
= OPT_LOGOFF_UID
,
2716 .descrip
= "uid to log off",
2719 .longName
= "set-auth-user",
2720 .argInfo
= POPT_ARG_STRING
,
2722 .val
= OPT_SET_AUTH_USER
,
2723 .descrip
= "Store user and password used by "
2724 "winbindd (root only)",
2725 .argDescrip
= "user%password",
2728 .longName
= "ccache-save",
2730 .argInfo
= POPT_ARG_STRING
,
2732 .val
= OPT_CCACHE_SAVE
,
2733 .descrip
= "Store user and password for ccache "
2735 .argDescrip
= "user%password",
2738 .longName
= "getdcname",
2739 .argInfo
= POPT_ARG_STRING
,
2741 .val
= OPT_GETDCNAME
,
2742 .descrip
= "Get a DC name for a foreign domain",
2743 .argDescrip
= "domainname",
2746 .longName
= "dsgetdcname",
2747 .argInfo
= POPT_ARG_STRING
,
2749 .val
= OPT_DSGETDCNAME
,
2750 .descrip
= "Find a DC for a domain",
2751 .argDescrip
= "domainname",
2754 .longName
= "dc-info",
2755 .argInfo
= POPT_ARG_STRING
,
2758 .descrip
= "Find the currently known DCs",
2759 .argDescrip
= "domainname",
2762 .longName
= "get-auth-user",
2763 .argInfo
= POPT_ARG_NONE
,
2764 .val
= OPT_GET_AUTH_USER
,
2765 .descrip
= "Retrieve user and password used by "
2766 "winbindd (root only)",
2771 .argInfo
= POPT_ARG_NONE
,
2774 .descrip
= "Ping winbindd to see if it is alive",
2777 .longName
= "domain",
2779 .argInfo
= POPT_ARG_STRING
,
2780 .arg
= &opt_domain_name
,
2781 .val
= OPT_DOMAIN_NAME
,
2782 .descrip
= "Define to the domain to restrict "
2784 .argDescrip
= "domain",
2786 #ifdef WITH_FAKE_KASERVER
2790 .argInfo
= POPT_ARG_STRING
,
2793 .descrip
= "set an AFS token from winbind",
2794 .argDescrip
= "user%password",
2799 .longName
= "krb5auth",
2801 .argInfo
= POPT_ARG_STRING
,
2804 .descrip
= "authenticate user using Kerberos",
2805 .argDescrip
= "user%password",
2807 /* destroys wbinfo --help output */
2808 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2811 .longName
= "krb5ccname",
2812 .argInfo
= POPT_ARG_STRING
,
2813 .arg
= &opt_krb5ccname
,
2814 .val
= OPT_KRB5CCNAME
,
2815 .descrip
= "authenticate user using Kerberos and "
2816 "specific credential cache type",
2817 .argDescrip
= "krb5ccname",
2821 .longName
= "separator",
2822 .argInfo
= POPT_ARG_NONE
,
2823 .val
= OPT_SEPARATOR
,
2824 .descrip
= "Get the active winbind separator",
2827 .longName
= "verbose",
2828 .argInfo
= POPT_ARG_NONE
,
2830 .descrip
= "Print additional information per command",
2833 .longName
= "change-user-password",
2834 .argInfo
= POPT_ARG_STRING
,
2836 .val
= OPT_CHANGE_USER_PASSWORD
,
2837 .descrip
= "Change the password for a user",
2840 .longName
= "ntlmv1",
2841 .argInfo
= POPT_ARG_NONE
,
2843 .descrip
= "Use NTLMv1 cryptography for user authentication",
2846 .longName
= "ntlmv2",
2847 .argInfo
= POPT_ARG_NONE
,
2849 .descrip
= "Use NTLMv2 cryptography for user authentication",
2852 .longName
= "lanman",
2853 .argInfo
= POPT_ARG_NONE
,
2855 .descrip
= "Use lanman cryptography for user authentication",
2861 /* Samba client initialisation */
2867 pc
= samba_popt_get_context(getprogname(),
2873 DBG_ERR("Failed to setup popt context!\n");
2877 /* Parse command line options */
2880 poptPrintHelp(pc
, stderr
, 0);
2884 while((opt
= poptGetNextOpt(pc
)) != -1) {
2885 /* get the generic configuration parameters like --domain */
2899 poptFreeContext(pc
);
2901 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2902 POPT_CONTEXT_KEEP_FIRST
);
2904 while((opt
= poptGetNextOpt(pc
)) != -1) {
2907 if (!print_domain_users(opt_domain_name
)) {
2909 "Error looking up domain users\n");
2914 if (!print_domain_groups(opt_domain_name
)) {
2916 "Error looking up domain groups\n");
2921 if (!wbinfo_lookupsid(string_arg
)) {
2923 "Could not lookup sid %s\n",
2928 case OPT_SID_TO_FULLNAME
:
2929 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2930 d_fprintf(stderr
, "Could not lookup sid %s\n",
2936 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2937 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2942 case OPT_LOOKUP_SIDS
:
2943 if (!wbinfo_lookup_sids(string_arg
)) {
2944 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2950 if (!wbinfo_lookupname(string_arg
)) {
2951 d_fprintf(stderr
, "Could not lookup name %s\n",
2957 if (!wbinfo_wins_byname(string_arg
)) {
2959 "Could not lookup WINS by name %s\n",
2965 if (!wbinfo_wins_byip(string_arg
)) {
2967 "Could not lookup WINS by IP %s\n",
2973 if (!wbinfo_uid_to_sid(int_arg
)) {
2975 "Could not convert uid %d to sid\n",
2981 if (!wbinfo_gid_to_sid(int_arg
)) {
2983 "Could not convert gid %d to sid\n",
2989 if (!wbinfo_sid_to_uid(string_arg
)) {
2991 "Could not convert sid %s to uid\n",
2997 if (!wbinfo_sid_to_gid(string_arg
)) {
2999 "Could not convert sid %s to gid\n",
3004 case OPT_ALLOCATE_UID
:
3005 if (!wbinfo_allocate_uid()) {
3006 d_fprintf(stderr
, "Could not allocate a uid\n");
3010 case OPT_ALLOCATE_GID
:
3011 if (!wbinfo_allocate_gid()) {
3012 d_fprintf(stderr
, "Could not allocate a gid\n");
3016 case OPT_SET_UID_MAPPING
:
3017 if (!parse_mapping_arg(string_arg
, &int_subarg
,
3019 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
3021 d_fprintf(stderr
, "Could not create or modify "
3022 "uid to sid mapping\n");
3026 case OPT_SET_GID_MAPPING
:
3027 if (!parse_mapping_arg(string_arg
, &int_subarg
,
3029 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
3031 d_fprintf(stderr
, "Could not create or modify "
3032 "gid to sid mapping\n");
3036 case OPT_REMOVE_UID_MAPPING
:
3037 if (!parse_mapping_arg(string_arg
, &int_subarg
,
3039 !wbinfo_remove_uid_mapping(int_subarg
,
3042 d_fprintf(stderr
, "Could not remove uid to sid "
3047 case OPT_REMOVE_GID_MAPPING
:
3048 if (!parse_mapping_arg(string_arg
, &int_subarg
,
3050 !wbinfo_remove_gid_mapping(int_subarg
,
3053 d_fprintf(stderr
, "Could not remove gid to sid "
3058 case OPT_SIDS_TO_XIDS
:
3059 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
3060 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
3065 case OPT_XIDS_TO_SIDS
:
3066 if (!wbinfo_xids_to_sids(string_arg
)) {
3067 d_fprintf(stderr
, "wbinfo_xids_to_sids "
3073 if (!wbinfo_check_secret(opt_domain_name
)) {
3074 d_fprintf(stderr
, "Could not check secret\n");
3079 if (!wbinfo_change_secret(opt_domain_name
)) {
3080 d_fprintf(stderr
, "Could not change secret\n");
3084 case OPT_CHANGE_SECRET_AT
:
3085 if (!wbinfo_change_secret_at(opt_domain_name
, string_arg
)) {
3086 d_fprintf(stderr
, "Could not change secret\n");
3091 if (!wbinfo_ping_dc(opt_domain_name
)) {
3096 if (!wbinfo_list_domains(false, verbose
)) {
3098 "Could not list trusted domains\n");
3103 if (!wbinfo_show_sequence(opt_domain_name
)) {
3105 "Could not show sequence numbers\n");
3109 case OPT_ONLINESTATUS
:
3110 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
3112 "Could not show online-status\n");
3117 if (!wbinfo_domain_info(string_arg
)) {
3119 "Could not get domain info\n");
3124 if (!wbinfo_get_userinfo(string_arg
)) {
3126 "Could not get info for user %s\n",
3131 case OPT_USER_SIDINFO
:
3132 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
3134 "Could not get info for user "
3135 "sid %s\n", string_arg
);
3140 if ( !wbinfo_get_uidinfo(int_arg
)) {
3141 d_fprintf(stderr
, "Could not get info for uid "
3146 case OPT_GROUP_INFO
:
3147 if ( !wbinfo_get_groupinfo(string_arg
)) {
3148 d_fprintf(stderr
, "Could not get info for "
3149 "group %s\n", string_arg
);
3154 if ( !wbinfo_get_gidinfo(int_arg
)) {
3155 d_fprintf(stderr
, "Could not get info for gid "
3161 if (!wbinfo_get_usergroups(string_arg
)) {
3163 "Could not get groups for user %s\n",
3169 if (!wbinfo_get_usersids(string_arg
)) {
3170 d_fprintf(stderr
, "Could not get group SIDs "
3171 "for user SID %s\n",
3176 case OPT_USERDOMGROUPS
:
3177 if (!wbinfo_get_userdomgroups(string_arg
)) {
3178 d_fprintf(stderr
, "Could not get user's domain "
3179 "groups for user SID %s\n",
3184 case OPT_SIDALIASES
:
3185 if (!wbinfo_get_sidaliases(opt_domain_name
,
3187 d_fprintf(stderr
, "Could not get sid aliases "
3188 "for user SID %s\n", string_arg
);
3193 bool got_error
= false;
3195 if (!wbinfo_auth(string_arg
)) {
3197 "Could not authenticate user "
3198 "%s with plaintext "
3199 "password\n", string_arg
);
3203 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
3206 "Could not authenticate user "
3207 "%s with challenge/response\n",
3217 if (!wbinfo_pam_logon(string_arg
, verbose
)) {
3218 d_fprintf(stderr
, "pam_logon failed for %s\n",
3227 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
3229 d_printf("Logoff %s (%d): %s\n", logoff_user
,
3230 logoff_uid
, wbcErrorString(wbc_status
));
3234 uint32_t flags
= WBFLAG_PAM_KRB5
|
3235 WBFLAG_PAM_CACHED_LOGIN
|
3236 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
3237 WBFLAG_PAM_INFO3_TEXT
|
3238 WBFLAG_PAM_CONTACT_TRUSTDOM
;
3240 if (!wbinfo_auth_krb5(string_arg
, opt_krb5ccname
,
3243 "Could not authenticate user "
3244 "[%s] with Kerberos "
3245 "(ccache: %s)\n", string_arg
,
3252 if (!wbinfo_klog(string_arg
)) {
3253 d_fprintf(stderr
, "Could not klog user\n");
3258 if (!wbinfo_ping()) {
3259 d_fprintf(stderr
, "could not ping winbindd!\n");
3263 case OPT_SET_AUTH_USER
:
3264 if (!wbinfo_set_auth_user(string_arg
)) {
3268 case OPT_GET_AUTH_USER
:
3269 wbinfo_get_auth_user();
3272 case OPT_CCACHE_SAVE
:
3273 if (!wbinfo_ccache_save(string_arg
)) {
3278 if (!wbinfo_getdcname(string_arg
)) {
3282 case OPT_DSGETDCNAME
:
3283 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
3288 if (!wbinfo_dc_info(string_arg
)) {
3292 case OPT_SEPARATOR
: {
3293 const char sep
= winbind_separator();
3297 d_printf("%c\n", sep
);
3300 case OPT_LIST_ALL_DOMAINS
:
3301 if (!wbinfo_list_domains(true, verbose
)) {
3305 case OPT_LIST_OWN_DOMAIN
:
3306 if (!wbinfo_list_own_domain()) {
3310 case OPT_CHANGE_USER_PASSWORD
:
3311 if (!wbinfo_change_user_password(string_arg
)) {
3313 "Could not change user password "
3314 "for user %s\n", string_arg
);
3319 /* generic configuration options */
3320 case OPT_DOMAIN_NAME
:
3325 case OPT_LOGOFF_USER
:
3326 case OPT_LOGOFF_UID
:
3327 case OPT_KRB5CCNAME
:
3330 d_fprintf(stderr
, "Invalid option\n");
3331 poptPrintHelp(pc
, stderr
, 0);
3343 poptFreeContext(pc
);