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 "../libcli/auth/libcli_auth.h"
28 #include "lib/cmdline/popt_common.h"
29 #include "lib/afs/afs_settoken.h"
33 #define DBGC_CLASS DBGC_WINBIND
36 static struct wbcInterfaceDetails
*init_interface_details(void)
38 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
39 static struct wbcInterfaceDetails
*details
;
45 wbc_status
= wbcInterfaceDetails(&details
);
46 if (!WBC_ERROR_IS_OK(wbc_status
)) {
47 d_fprintf(stderr
, "could not obtain winbind interface "
48 "details: %s\n", wbcErrorString(wbc_status
));
54 static char winbind_separator(void)
56 struct wbcInterfaceDetails
*details
;
63 details
= init_interface_details();
66 d_fprintf(stderr
, "could not obtain winbind separator!\n");
70 sep
= details
->winbind_separator
;
74 d_fprintf(stderr
, "winbind separator was NULL!\n");
81 static const char *get_winbind_domain(void)
83 static struct wbcInterfaceDetails
*details
;
85 details
= init_interface_details();
88 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
92 return details
->netbios_domain
;
95 static const char *get_winbind_netbios_name(void)
97 static struct wbcInterfaceDetails
*details
;
99 details
= init_interface_details();
102 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
106 return details
->netbios_name
;
109 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
110 form DOMAIN/user into a domain and a user */
112 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
116 char *p
= strchr(domuser
,winbind_separator());
119 /* Maybe it was a UPN? */
120 p
= strchr(domuser
, '@');
123 fstrcpy(user
, domuser
);
127 fstrcpy(user
, domuser
);
128 fstrcpy(domain
, get_winbind_domain());
133 fstrcpy(domain
, domuser
);
134 domain
[PTR_DIFF(p
, domuser
)] = 0;
139 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
140 * Return true if input was valid, false otherwise. */
141 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
149 tmp
= strtok(arg
, ",");
150 *sid
= strtok(NULL
, ",");
152 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
155 /* Because atoi() can return 0 on invalid input, which would be a valid
156 * UID/GID we must use strtoul() and do error checking */
157 *id
= strtoul_err(tmp
, &endptr
, 10, &error
);
159 if (endptr
[0] != '\0' || error
!= 0)
165 /* pull pwent info for a given user */
167 static bool wbinfo_get_userinfo(char *user
)
169 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
170 struct passwd
*pwd
= NULL
;
172 wbc_status
= wbcGetpwnam(user
, &pwd
);
173 if (!WBC_ERROR_IS_OK(wbc_status
)) {
174 d_fprintf(stderr
, "failed to call wbcGetpwnam: %s\n",
175 wbcErrorString(wbc_status
));
179 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
182 (unsigned int)pwd
->pw_uid
,
183 (unsigned int)pwd
->pw_gid
,
193 /* pull pwent info for a given uid */
194 static bool wbinfo_get_uidinfo(int uid
)
196 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
197 struct passwd
*pwd
= NULL
;
199 wbc_status
= wbcGetpwuid(uid
, &pwd
);
200 if (!WBC_ERROR_IS_OK(wbc_status
)) {
201 d_fprintf(stderr
, "failed to call wbcGetpwuid: %s\n",
202 wbcErrorString(wbc_status
));
206 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
209 (unsigned int)pwd
->pw_uid
,
210 (unsigned int)pwd
->pw_gid
,
220 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
222 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
223 struct passwd
*pwd
= NULL
;
224 struct wbcDomainSid sid
;
226 wbc_status
= wbcStringToSid(sid_str
, &sid
);
227 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
228 if (!WBC_ERROR_IS_OK(wbc_status
)) {
229 d_fprintf(stderr
, "failed to call wbcGetpwsid: %s\n",
230 wbcErrorString(wbc_status
));
234 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
237 (unsigned int)pwd
->pw_uid
,
238 (unsigned int)pwd
->pw_gid
,
249 /* pull grent for a given group */
250 static bool wbinfo_get_groupinfo(const char *group
)
252 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
256 wbc_status
= wbcGetgrnam(group
, &grp
);
257 if (!WBC_ERROR_IS_OK(wbc_status
)) {
258 d_fprintf(stderr
, "failed to call wbcGetgrnam: %s\n",
259 wbcErrorString(wbc_status
));
263 d_printf("%s:%s:%u:",
266 (unsigned int)grp
->gr_gid
);
269 while (*mem
!= NULL
) {
270 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
280 /* pull grent for a given gid */
281 static bool wbinfo_get_gidinfo(int gid
)
283 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
287 wbc_status
= wbcGetgrgid(gid
, &grp
);
288 if (!WBC_ERROR_IS_OK(wbc_status
)) {
289 d_fprintf(stderr
, "failed to call wbcGetgrgid: %s\n",
290 wbcErrorString(wbc_status
));
294 d_printf("%s:%s:%u:",
297 (unsigned int)grp
->gr_gid
);
300 while (*mem
!= NULL
) {
301 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
311 /* List groups a user is a member of */
313 static bool wbinfo_get_usergroups(const char *user
)
315 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
318 gid_t
*groups
= NULL
;
322 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
323 if (!WBC_ERROR_IS_OK(wbc_status
)) {
324 d_fprintf(stderr
, "failed to call wbcGetGroups: %s\n",
325 wbcErrorString(wbc_status
));
329 for (i
= 0; i
< num_groups
; i
++) {
330 d_printf("%d\n", (int)groups
[i
]);
333 wbcFreeMemory(groups
);
339 /* List group SIDs a user SID is a member of */
340 static bool wbinfo_get_usersids(const char *user_sid_str
)
342 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
345 struct wbcDomainSid user_sid
, *sids
= NULL
;
349 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
350 if (!WBC_ERROR_IS_OK(wbc_status
)) {
351 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
352 wbcErrorString(wbc_status
));
356 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
357 if (!WBC_ERROR_IS_OK(wbc_status
)) {
358 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
359 wbcErrorString(wbc_status
));
363 for (i
= 0; i
< num_sids
; i
++) {
364 char str
[WBC_SID_STRING_BUFLEN
];
365 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
366 d_printf("%s\n", str
);
374 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
376 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
379 struct wbcDomainSid user_sid
, *sids
= NULL
;
383 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
384 if (!WBC_ERROR_IS_OK(wbc_status
)) {
385 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
386 wbcErrorString(wbc_status
));
390 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
391 if (!WBC_ERROR_IS_OK(wbc_status
)) {
392 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
393 wbcErrorString(wbc_status
));
397 for (i
= 0; i
< num_sids
; i
++) {
398 char str
[WBC_SID_STRING_BUFLEN
];
399 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
400 d_printf("%s\n", str
);
408 static bool wbinfo_get_sidaliases(const char *domain
,
409 const char *user_sid_str
)
411 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
412 struct wbcDomainInfo
*dinfo
= NULL
;
414 struct wbcDomainSid user_sid
;
415 uint32_t *alias_rids
= NULL
;
416 uint32_t num_alias_rids
;
417 char domain_sid_str
[WBC_SID_STRING_BUFLEN
];
420 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
421 (domain
[0] == '\0')) {
422 domain
= get_winbind_domain();
427 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
428 if (!WBC_ERROR_IS_OK(wbc_status
)) {
429 d_fprintf(stderr
, "wbcDomainInfo(%s) failed: %s\n", domain
,
430 wbcErrorString(wbc_status
));
433 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
434 if (!WBC_ERROR_IS_OK(wbc_status
)) {
438 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
439 &alias_rids
, &num_alias_rids
);
440 if (!WBC_ERROR_IS_OK(wbc_status
)) {
444 wbcSidToStringBuf(&dinfo
->sid
, domain_sid_str
, sizeof(domain_sid_str
));
446 for (i
= 0; i
< num_alias_rids
; i
++) {
447 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
450 wbcFreeMemory(alias_rids
);
453 wbcFreeMemory(dinfo
);
454 return (WBC_ERR_SUCCESS
== wbc_status
);
458 /* Convert NetBIOS name to IP */
460 static bool wbinfo_wins_byname(const char *name
)
462 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
465 wbc_status
= wbcResolveWinsByName(name
, &ip
);
466 if (!WBC_ERROR_IS_OK(wbc_status
)) {
467 d_fprintf(stderr
, "failed to call wbcResolveWinsByName: %s\n",
468 wbcErrorString(wbc_status
));
472 /* Display response */
474 d_printf("%s\n", ip
);
481 /* Convert IP to NetBIOS name */
483 static bool wbinfo_wins_byip(const char *ip
)
485 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
488 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
489 if (!WBC_ERROR_IS_OK(wbc_status
)) {
490 d_fprintf(stderr
, "failed to call wbcResolveWinsByIP: %s\n",
491 wbcErrorString(wbc_status
));
495 /* Display response */
497 d_printf("%s\n", name
);
504 /* List all/trusted domains */
506 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
508 struct wbcDomainInfo
*domain_list
= NULL
;
510 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
511 bool print_all
= !list_all_domains
&& verbose
;
514 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
515 if (!WBC_ERROR_IS_OK(wbc_status
)) {
516 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
517 wbcErrorString(wbc_status
));
522 d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
523 "Domain Name", "DNS Domain", "Trust Type",
524 "Transitive", "In", "Out");
527 for (i
=0; i
<num_domains
; i
++) {
529 d_printf("%-16s", domain_list
[i
].short_name
);
531 d_printf("%s", domain_list
[i
].short_name
);
536 d_printf("%-65s", domain_list
[i
].dns_name
);
538 switch(domain_list
[i
].trust_type
) {
539 case WBC_DOMINFO_TRUSTTYPE_NONE
:
540 if (domain_list
[i
].trust_routing
!= NULL
) {
541 d_printf("%s\n", domain_list
[i
].trust_routing
);
546 case WBC_DOMINFO_TRUSTTYPE_LOCAL
:
549 case WBC_DOMINFO_TRUSTTYPE_RWDC
:
552 case WBC_DOMINFO_TRUSTTYPE_RODC
:
555 case WBC_DOMINFO_TRUSTTYPE_PDC
:
558 case WBC_DOMINFO_TRUSTTYPE_WKSTA
:
559 d_printf("Workstation ");
561 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
564 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
565 d_printf("External ");
567 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
568 d_printf("In-Forest ");
572 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
578 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
584 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
593 wbcFreeMemory(domain_list
);
598 /* List own domain */
600 static bool wbinfo_list_own_domain(void)
602 d_printf("%s\n", get_winbind_domain());
607 /* show sequence numbers */
608 static bool wbinfo_show_sequence(const char *domain
)
610 d_printf("This command has been deprecated. Please use the "
611 "--online-status option instead.\n");
615 /* show sequence numbers */
616 static bool wbinfo_show_onlinestatus(const char *domain
)
618 struct wbcDomainInfo
*domain_list
= NULL
;
620 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 struct winbindd_request request
;
702 struct winbindd_response response
;
704 ZERO_STRUCT(request
);
705 ZERO_STRUCT(response
);
707 fstrcpy(request
.domain_name
, domain_name
);
711 if (winbindd_request_response(NULL
, WINBINDD_GETDCNAME
, &request
,
712 &response
) != NSS_STATUS_SUCCESS
) {
713 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
717 /* Display response */
719 d_printf("%s\n", response
.data
.dc_name
);
725 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
727 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
728 struct wbcDomainControllerInfoEx
*dc_info
;
731 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
732 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
734 if (!WBC_ERROR_IS_OK(wbc_status
)) {
735 printf("Could not find dc for %s\n", domain_name
);
739 wbcGuidToString(dc_info
->domain_guid
, &str
);
741 d_printf("%s\n", dc_info
->dc_unc
);
742 d_printf("%s\n", dc_info
->dc_address
);
743 d_printf("%d\n", dc_info
->dc_address_type
);
744 d_printf("%s\n", str
);
745 d_printf("%s\n", dc_info
->domain_name
);
746 d_printf("%s\n", dc_info
->forest_name
);
747 d_printf("0x%08x\n", dc_info
->dc_flags
);
748 d_printf("%s\n", dc_info
->dc_site_name
);
749 d_printf("%s\n", dc_info
->client_site_name
);
752 wbcFreeMemory(dc_info
);
757 /* Check trust account password */
759 static bool wbinfo_check_secret(const char *domain
)
761 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
762 struct wbcAuthErrorInfo
*error
= NULL
;
763 const char *domain_name
;
766 domain_name
= domain
;
768 domain_name
= get_winbind_domain();
771 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
773 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
775 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
777 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
778 d_fprintf(stderr
, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
779 domain_name
, error
->nt_string
, error
->nt_status
);
780 wbcFreeMemory(error
);
782 if (!WBC_ERROR_IS_OK(wbc_status
)) {
783 d_fprintf(stderr
, "failed to call wbcCheckTrustCredentials: "
784 "%s\n", wbcErrorString(wbc_status
));
791 /* Find the currently connected DCs */
793 static bool wbinfo_dc_info(const char *domain_name
)
795 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
797 const char **dc_names
, **dc_ips
;
799 wbc_status
= wbcDcInfo(domain_name
, &num_dcs
,
801 if (!WBC_ERROR_IS_OK(wbc_status
)) {
802 printf("Could not find dc info %s\n",
803 domain_name
? domain_name
: "our domain");
807 for (i
=0; i
<num_dcs
; i
++) {
808 printf("%s (%s)\n", dc_names
[i
], dc_ips
[i
]);
810 wbcFreeMemory(dc_names
);
811 wbcFreeMemory(dc_ips
);
816 /* Change trust account password */
818 static bool wbinfo_change_secret(const char *domain
)
820 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
821 struct wbcAuthErrorInfo
*error
= NULL
;
822 const char *domain_name
;
825 domain_name
= domain
;
827 domain_name
= get_winbind_domain();
830 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
832 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
834 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
836 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
837 d_fprintf(stderr
, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
838 domain_name
, error
->nt_string
, error
->nt_status
);
839 wbcFreeMemory(error
);
841 if (!WBC_ERROR_IS_OK(wbc_status
)) {
842 d_fprintf(stderr
, "failed to call wbcChangeTrustCredentials: "
843 "%s\n", wbcErrorString(wbc_status
));
850 /* Check DC connection */
852 static bool wbinfo_ping_dc(const char *domain
)
854 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
855 struct wbcAuthErrorInfo
*error
= NULL
;
858 const char *domain_name
;
861 domain_name
= domain
;
863 domain_name
= get_winbind_domain();
866 wbc_status
= wbcPingDc2(domain_name
, &error
, &dcname
);
868 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
869 domain_name
? domain_name
: "",
870 dcname
? dcname
: "",
871 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
873 wbcFreeMemory(dcname
);
874 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
875 d_fprintf(stderr
, "wbcPingDc2(%s): error code was %s (0x%x)\n",
876 domain_name
, error
->nt_string
, error
->nt_status
);
877 wbcFreeMemory(error
);
880 if (!WBC_ERROR_IS_OK(wbc_status
)) {
881 d_fprintf(stderr
, "failed to call wbcPingDc: %s\n",
882 wbcErrorString(wbc_status
));
889 /* Convert uid to sid */
891 static bool wbinfo_uid_to_sid(uid_t uid
)
893 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
894 struct wbcDomainSid sid
;
895 char sid_str
[WBC_SID_STRING_BUFLEN
];
899 wbc_status
= wbcUidToSid(uid
, &sid
);
900 if (!WBC_ERROR_IS_OK(wbc_status
)) {
901 d_fprintf(stderr
, "failed to call wbcUidToSid: %s\n",
902 wbcErrorString(wbc_status
));
906 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
908 /* Display response */
910 d_printf("%s\n", sid_str
);
915 /* Convert gid to sid */
917 static bool wbinfo_gid_to_sid(gid_t gid
)
919 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
920 struct wbcDomainSid sid
;
921 char sid_str
[WBC_SID_STRING_BUFLEN
];
925 wbc_status
= wbcGidToSid(gid
, &sid
);
926 if (!WBC_ERROR_IS_OK(wbc_status
)) {
927 d_fprintf(stderr
, "failed to call wbcGidToSid: %s\n",
928 wbcErrorString(wbc_status
));
932 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
934 /* Display response */
936 d_printf("%s\n", sid_str
);
941 /* Convert sid to uid */
943 static bool wbinfo_sid_to_uid(const char *sid_str
)
945 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
946 struct wbcDomainSid sid
;
951 wbc_status
= wbcStringToSid(sid_str
, &sid
);
952 if (!WBC_ERROR_IS_OK(wbc_status
)) {
953 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
954 wbcErrorString(wbc_status
));
958 wbc_status
= wbcSidToUid(&sid
, &uid
);
959 if (!WBC_ERROR_IS_OK(wbc_status
)) {
960 d_fprintf(stderr
, "failed to call wbcSidToUid: %s\n",
961 wbcErrorString(wbc_status
));
965 /* Display response */
967 d_printf("%d\n", (int)uid
);
972 static bool wbinfo_sid_to_gid(const char *sid_str
)
974 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
975 struct wbcDomainSid sid
;
980 wbc_status
= wbcStringToSid(sid_str
, &sid
);
981 if (!WBC_ERROR_IS_OK(wbc_status
)) {
982 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
983 wbcErrorString(wbc_status
));
987 wbc_status
= wbcSidToGid(&sid
, &gid
);
988 if (!WBC_ERROR_IS_OK(wbc_status
)) {
989 d_fprintf(stderr
, "failed to call wbcSidToGid: %s\n",
990 wbcErrorString(wbc_status
));
994 /* Display response */
996 d_printf("%d\n", (int)gid
);
1001 static bool wbinfo_sids_to_unix_ids(const char *arg
)
1003 char sidstr
[WBC_SID_STRING_BUFLEN
];
1004 struct wbcDomainSid
*sids
;
1005 struct wbcUnixId
*unix_ids
;
1015 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1016 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1019 d_fprintf(stderr
, "talloc failed\n");
1022 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1023 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1024 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1025 sidstr
, wbcErrorString(wbc_status
));
1032 unix_ids
= talloc_array(talloc_tos(), struct wbcUnixId
, num_sids
);
1033 if (unix_ids
== NULL
) {
1038 wbc_status
= wbcSidsToUnixIds(sids
, num_sids
, unix_ids
);
1039 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1040 d_fprintf(stderr
, "wbcSidsToUnixIds failed: %s\n",
1041 wbcErrorString(wbc_status
));
1046 for (i
=0; i
<num_sids
; i
++) {
1048 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1050 switch(unix_ids
[i
].type
) {
1051 case WBC_ID_TYPE_UID
:
1052 d_printf("%s -> uid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1054 case WBC_ID_TYPE_GID
:
1055 d_printf("%s -> gid %d\n", sidstr
, unix_ids
[i
].id
.gid
);
1057 case WBC_ID_TYPE_BOTH
:
1058 d_printf("%s -> uid/gid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1061 d_printf("%s -> unmapped\n", sidstr
);
1067 TALLOC_FREE(unix_ids
);
1072 static bool wbinfo_xids_to_sids(const char *arg
)
1075 struct wbcUnixId
*xids
= NULL
;
1076 struct wbcDomainSid
*sids
;
1084 while (next_token(&p
, idstr
, LIST_SEP
, sizeof(idstr
))) {
1085 xids
= talloc_realloc(talloc_tos(), xids
, struct wbcUnixId
,
1088 d_fprintf(stderr
, "talloc failed\n");
1094 xids
[num_xids
] = (struct wbcUnixId
) {
1095 .type
= WBC_ID_TYPE_UID
,
1096 .id
.uid
= atoi(&idstr
[1])
1100 xids
[num_xids
] = (struct wbcUnixId
) {
1101 .type
= WBC_ID_TYPE_GID
,
1102 .id
.gid
= atoi(&idstr
[1])
1106 d_fprintf(stderr
, "%s is an invalid id\n", idstr
);
1113 sids
= talloc_array(talloc_tos(), struct wbcDomainSid
, num_xids
);
1115 d_fprintf(stderr
, "talloc failed\n");
1120 wbc_status
= wbcUnixIdsToSids(xids
, num_xids
, sids
);
1121 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1122 d_fprintf(stderr
, "wbcUnixIdsToSids failed: %s\n",
1123 wbcErrorString(wbc_status
));
1129 for (i
=0; i
<num_xids
; i
++) {
1130 char str
[WBC_SID_STRING_BUFLEN
];
1131 struct wbcDomainSid null_sid
= { 0 };
1133 if (memcmp(&null_sid
, &sids
[i
], sizeof(struct wbcDomainSid
)) == 0) {
1134 d_printf("NOT MAPPED\n");
1137 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
1138 d_printf("%s\n", str
);
1144 static bool wbinfo_allocate_uid(void)
1146 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1151 wbc_status
= wbcAllocateUid(&uid
);
1152 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1153 d_fprintf(stderr
, "failed to call wbcAllocateUid: %s\n",
1154 wbcErrorString(wbc_status
));
1158 /* Display response */
1160 d_printf("New uid: %u\n", (unsigned int)uid
);
1165 static bool wbinfo_allocate_gid(void)
1167 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1172 wbc_status
= wbcAllocateGid(&gid
);
1173 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1174 d_fprintf(stderr
, "failed to call wbcAllocateGid: %s\n",
1175 wbcErrorString(wbc_status
));
1179 /* Display response */
1181 d_printf("New gid: %u\n", (unsigned int)gid
);
1186 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
1188 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1189 struct wbcDomainSid sid
;
1193 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1194 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1195 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1196 wbcErrorString(wbc_status
));
1200 wbc_status
= wbcSetUidMapping(uid
, &sid
);
1201 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1202 d_fprintf(stderr
, "failed to call wbcSetUidMapping: %s\n",
1203 wbcErrorString(wbc_status
));
1207 /* Display response */
1209 d_printf("uid %u now mapped to sid %s\n",
1210 (unsigned int)uid
, sid_str
);
1215 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
1217 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1218 struct wbcDomainSid sid
;
1222 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1223 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1224 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1225 wbcErrorString(wbc_status
));
1229 wbc_status
= wbcSetGidMapping(gid
, &sid
);
1230 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1231 d_fprintf(stderr
, "failed to call wbcSetGidMapping: %s\n",
1232 wbcErrorString(wbc_status
));
1236 /* Display response */
1238 d_printf("gid %u now mapped to sid %s\n",
1239 (unsigned int)gid
, sid_str
);
1244 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1246 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1247 struct wbcDomainSid sid
;
1251 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1252 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1253 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1254 wbcErrorString(wbc_status
));
1258 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1259 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1260 d_fprintf(stderr
, "failed to call wbcRemoveUidMapping: %s\n",
1261 wbcErrorString(wbc_status
));
1265 /* Display response */
1267 d_printf("Removed uid %u to sid %s mapping\n",
1268 (unsigned int)uid
, sid_str
);
1273 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1275 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1276 struct wbcDomainSid sid
;
1280 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1281 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1282 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1283 wbcErrorString(wbc_status
));
1287 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1288 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1289 d_fprintf(stderr
, "failed to call wbcRemoveGidMapping: %s\n",
1290 wbcErrorString(wbc_status
));
1294 /* Display response */
1296 d_printf("Removed gid %u to sid %s mapping\n",
1297 (unsigned int)gid
, sid_str
);
1302 /* Convert sid to string */
1304 static bool wbinfo_lookupsid(const char *sid_str
)
1306 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1307 struct wbcDomainSid sid
;
1310 enum wbcSidType type
;
1312 /* Send off request */
1314 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1315 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1316 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1317 wbcErrorString(wbc_status
));
1321 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1322 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1323 d_fprintf(stderr
, "failed to call wbcLookupSid: %s\n",
1324 wbcErrorString(wbc_status
));
1328 /* Display response */
1330 if (type
== WBC_SID_NAME_DOMAIN
) {
1331 d_printf("%s %d\n", domain
, type
);
1333 d_printf("%s%c%s %d\n",
1334 domain
, winbind_separator(), name
, type
);
1337 wbcFreeMemory(domain
);
1338 wbcFreeMemory(name
);
1343 /* Convert sid to fullname */
1345 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1347 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1348 struct wbcDomainSid sid
;
1351 enum wbcSidType type
;
1353 /* Send off request */
1355 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1356 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1357 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1358 wbcErrorString(wbc_status
));
1362 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1363 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1364 d_fprintf(stderr
, "failed to call wbcGetDisplayName: %s\n",
1365 wbcErrorString(wbc_status
));
1369 /* Display response */
1371 d_printf("%s%c%s %d\n",
1372 domain
, winbind_separator(), name
, type
);
1374 wbcFreeMemory(domain
);
1375 wbcFreeMemory(name
);
1380 /* Lookup a list of RIDs */
1382 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1384 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1385 struct wbcDomainInfo
*dinfo
= NULL
;
1386 char *domain_name
= NULL
;
1387 const char **names
= NULL
;
1388 enum wbcSidType
*types
= NULL
;
1391 uint32_t *rids
= NULL
;
1394 TALLOC_CTX
*mem_ctx
= NULL
;
1397 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1398 domain
= get_winbind_domain();
1403 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1404 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1405 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1406 wbcErrorString(wbc_status
));
1410 mem_ctx
= talloc_new(NULL
);
1411 if (mem_ctx
== NULL
) {
1412 d_printf("talloc_new failed\n");
1420 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1424 rid
= strtoul_err(ridstr
, NULL
, 10, &error
);
1426 d_printf("failed to convert rid\n");
1429 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1431 d_printf("talloc_realloc failed\n");
1433 rids
[num_rids
] = rid
;
1438 d_printf("no rids\n");
1442 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
1443 &p
, &names
, &types
);
1444 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1445 d_printf("winbind_lookup_rids failed: %s\n",
1446 wbcErrorString(wbc_status
));
1450 domain_name
= discard_const_p(char, p
);
1451 d_printf("Domain: %s\n", domain_name
);
1453 for (i
=0; i
<num_rids
; i
++) {
1454 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1455 wbcSidTypeString(types
[i
]));
1460 wbcFreeMemory(dinfo
);
1461 wbcFreeMemory(domain_name
);
1462 wbcFreeMemory(names
);
1463 wbcFreeMemory(types
);
1464 TALLOC_FREE(mem_ctx
);
1468 static bool wbinfo_lookup_sids(const char *arg
)
1470 char sidstr
[WBC_SID_STRING_BUFLEN
];
1471 struct wbcDomainSid
*sids
;
1472 struct wbcDomainInfo
*domains
;
1473 struct wbcTranslatedName
*names
;
1484 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1485 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1488 d_fprintf(stderr
, "talloc failed\n");
1491 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1492 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1493 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1494 sidstr
, wbcErrorString(wbc_status
));
1501 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1503 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1504 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1505 wbcErrorString(wbc_status
));
1510 for (i
=0; i
<num_sids
; i
++) {
1511 const char *domain
= NULL
;
1513 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1515 if (names
[i
].domain_index
>= num_domains
) {
1517 } else if (names
[i
].domain_index
< 0) {
1520 domain
= domains
[names
[i
].domain_index
].short_name
;
1523 if (names
[i
].type
== WBC_SID_NAME_DOMAIN
) {
1524 d_printf("%s -> %s %d\n", sidstr
,
1528 d_printf("%s -> %s%c%s %d\n", sidstr
,
1530 winbind_separator(),
1531 names
[i
].name
, names
[i
].type
);
1534 wbcFreeMemory(names
);
1535 wbcFreeMemory(domains
);
1539 /* Convert string to sid */
1541 static bool wbinfo_lookupname(const char *full_name
)
1543 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1544 struct wbcDomainSid sid
;
1545 char sid_str
[WBC_SID_STRING_BUFLEN
];
1546 enum wbcSidType type
;
1547 fstring domain_name
;
1548 fstring account_name
;
1550 /* Send off request */
1552 parse_wbinfo_domain_user(full_name
, domain_name
,
1555 wbc_status
= wbcLookupName(domain_name
, account_name
,
1557 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1558 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1559 wbcErrorString(wbc_status
));
1563 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1565 /* Display response */
1567 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1572 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1574 const char *username
)
1577 char buf
[1024] = {0};
1580 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1585 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1590 prompt
= talloc_asprintf_append(prompt
, "password: ");
1595 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1596 TALLOC_FREE(prompt
);
1601 return talloc_strdup(mem_ctx
, buf
);
1604 /* Authenticate a user with a plaintext password */
1606 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1608 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1611 char *password
= NULL
;
1613 char *local_cctype
= NULL
;
1615 struct wbcLogonUserParams params
;
1616 struct wbcLogonUserInfo
*info
;
1617 struct wbcAuthErrorInfo
*error
;
1618 struct wbcUserPasswordPolicyInfo
*policy
;
1619 TALLOC_CTX
*frame
= talloc_tos();
1621 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1625 if ((p
= strchr(s
, '%')) != NULL
) {
1628 password
= talloc_strdup(frame
, p
);
1630 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1633 local_cctype
= talloc_strdup(frame
, cctype
);
1639 params
.username
= name
;
1640 params
.password
= password
;
1641 params
.num_blobs
= 0;
1642 params
.blobs
= NULL
;
1644 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1650 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1651 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1652 wbcErrorString(wbc_status
));
1656 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1662 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1663 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1664 wbcErrorString(wbc_status
));
1668 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1672 (uint8_t *)local_cctype
,
1674 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1675 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1676 wbcErrorString(wbc_status
));
1680 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1682 d_printf("plaintext kerberos password authentication for [%s] %s "
1683 "(requesting cctype: %s)\n",
1684 username
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1689 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1690 "error message was: %s\n",
1691 params
.username
, error
->nt_string
,
1693 error
->display_string
);
1696 if (WBC_ERROR_IS_OK(wbc_status
)) {
1697 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1698 if (info
&& info
->info
&& info
->info
->user_flags
&
1699 NETLOGON_CACHED_ACCOUNT
) {
1700 d_printf("user_flgs: "
1701 "NETLOGON_CACHED_ACCOUNT\n");
1707 for (i
=0; i
< info
->num_blobs
; i
++) {
1708 if (strequal(info
->blobs
[i
].name
,
1710 d_printf("credentials were put "
1713 info
->blobs
[i
].blob
.data
);
1718 d_printf("no credentials cached\n");
1723 wbcFreeMemory(params
.blobs
);
1725 return WBC_ERROR_IS_OK(wbc_status
);
1728 /* Authenticate a user with a plaintext password */
1730 static bool wbinfo_auth(char *username
)
1732 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1735 char *password
= NULL
;
1737 TALLOC_CTX
*frame
= talloc_tos();
1739 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1743 if ((p
= strchr(s
, '%')) != NULL
) {
1746 password
= talloc_strdup(frame
, p
);
1748 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1753 wbc_status
= wbcAuthenticateUser(name
, password
);
1755 d_printf("plaintext password authentication %s\n",
1756 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1759 if (response
.data
.auth
.nt_status
)
1761 "error code was %s (0x%x)\nerror message was: %s\n",
1762 response
.data
.auth
.nt_status_string
,
1763 response
.data
.auth
.nt_status
,
1764 response
.data
.auth
.error_string
);
1767 return WBC_ERROR_IS_OK(wbc_status
);
1770 /* Authenticate a user with a challenge/response */
1772 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1774 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1775 struct wbcAuthUserParams params
;
1776 struct wbcAuthUserInfo
*info
= NULL
;
1777 struct wbcAuthErrorInfo
*err
= NULL
;
1778 DATA_BLOB lm
= data_blob_null
;
1779 DATA_BLOB nt
= data_blob_null
;
1781 fstring name_domain
;
1784 TALLOC_CTX
*frame
= talloc_tos();
1786 p
= strchr(username
, '%');
1790 pass
= talloc_strdup(frame
, p
+ 1);
1792 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1795 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1797 params
.account_name
= name_user
;
1798 params
.domain_name
= name_domain
;
1799 params
.workstation_name
= NULL
;
1802 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1803 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1805 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1807 generate_random_buffer(params
.password
.response
.challenge
, 8);
1810 DATA_BLOB server_chal
;
1811 DATA_BLOB names_blob
;
1812 const char *netbios_name
= NULL
;
1813 const char *domain
= NULL
;
1815 netbios_name
= get_winbind_netbios_name(),
1816 domain
= get_winbind_domain();
1817 if (domain
== NULL
) {
1818 d_fprintf(stderr
, "Failed to get domain from winbindd\n");
1822 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1824 /* Pretend this is a login to 'us', for blob purposes */
1825 names_blob
= NTLMv2_generate_names_blob(NULL
,
1830 !SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1833 &lm
, &nt
, NULL
, NULL
)) {
1834 data_blob_free(&names_blob
);
1835 data_blob_free(&server_chal
);
1839 data_blob_free(&names_blob
);
1840 data_blob_free(&server_chal
);
1845 lm
= data_blob(NULL
, 24);
1846 ok
= SMBencrypt(pass
,
1847 params
.password
.response
.challenge
,
1850 data_blob_free(&lm
);
1853 nt
= data_blob(NULL
, 24);
1854 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1858 params
.password
.response
.nt_length
= nt
.length
;
1859 params
.password
.response
.nt_data
= nt
.data
;
1860 params
.password
.response
.lm_length
= lm
.length
;
1861 params
.password
.response
.lm_data
= lm
.data
;
1863 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1865 /* Display response */
1867 d_printf("challenge/response password authentication %s\n",
1868 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1870 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1872 "wbcAuthenticateUserEx(%s%c%s): error code was "
1873 "%s (0x%x, authoritative=%"PRIu8
")\n"
1874 "error message was: %s\n",
1876 winbind_separator(),
1881 err
->display_string
);
1883 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1884 wbcFreeMemory(info
);
1887 data_blob_free(&nt
);
1888 data_blob_free(&lm
);
1890 return WBC_ERROR_IS_OK(wbc_status
);
1893 /* Authenticate a user with a plaintext password */
1895 static bool wbinfo_pam_logon(char *username
, bool verbose
)
1897 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1898 struct wbcLogonUserParams params
;
1899 struct wbcLogonUserInfo
*info
= NULL
;
1900 struct wbcAuthErrorInfo
*error
= NULL
;
1903 TALLOC_CTX
*frame
= talloc_tos();
1907 ZERO_STRUCT(params
);
1909 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1913 if ((p
= strchr(s
, '%')) != NULL
) {
1916 params
.password
= talloc_strdup(frame
, p
);
1918 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1920 params
.username
= s
;
1922 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1924 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1926 (uint8_t *)&flags
, sizeof(flags
));
1927 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1928 d_printf("wbcAddNamedBlob failed: %s\n",
1929 wbcErrorString(wbc_status
));
1935 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1937 (uint8_t *)&uid
, sizeof(uid
));
1938 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1939 d_printf("wbcAddNamedBlob failed: %s\n",
1940 wbcErrorString(wbc_status
));
1944 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, NULL
);
1946 if (verbose
&& (info
!= NULL
)) {
1947 struct wbcAuthUserInfo
*i
= info
->info
;
1950 if (i
->account_name
!= NULL
) {
1951 d_printf("account_name: %s\n", i
->account_name
);
1953 if (i
->user_principal
!= NULL
) {
1954 d_printf("user_principal: %s\n", i
->user_principal
);
1956 if (i
->full_name
!= NULL
) {
1957 d_printf("full_name: %s\n", i
->full_name
);
1959 if (i
->domain_name
!= NULL
) {
1960 d_printf("domain_name: %s\n", i
->domain_name
);
1962 if (i
->dns_domain_name
!= NULL
) {
1963 d_printf("dns_domain_name: %s\n", i
->dns_domain_name
);
1965 if (i
->logon_server
!= NULL
) {
1966 d_printf("logon_server: %s\n", i
->logon_server
);
1968 if (i
->logon_script
!= NULL
) {
1969 d_printf("logon_script: %s\n", i
->logon_script
);
1971 if (i
->profile_path
!= NULL
) {
1972 d_printf("profile_path: %s\n", i
->profile_path
);
1974 if (i
->home_directory
!= NULL
) {
1975 d_printf("home_directory: %s\n", i
->home_directory
);
1977 if (i
->home_drive
!= NULL
) {
1978 d_printf("home_drive: %s\n", i
->home_drive
);
1983 for (j
=0; j
<i
->num_sids
; j
++) {
1984 char buf
[WBC_SID_STRING_BUFLEN
];
1985 wbcSidToStringBuf(&i
->sids
[j
].sid
, buf
, sizeof(buf
));
1986 d_printf(" %s", buf
);
1990 wbcFreeMemory(info
);
1994 wbcFreeMemory(params
.blobs
);
1996 d_printf("plaintext password authentication %s\n",
1997 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1999 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
2001 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2002 "error message was: %s\n",
2005 (int)error
->nt_status
,
2006 error
->display_string
);
2007 wbcFreeMemory(error
);
2009 return WBC_ERROR_IS_OK(wbc_status
);
2012 /* Save creds with winbind */
2014 static bool wbinfo_ccache_save(char *username
)
2016 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2019 char *password
= NULL
;
2021 TALLOC_CTX
*frame
= talloc_stackframe();
2023 s
= talloc_strdup(frame
, username
);
2032 password
= talloc_strdup(frame
, p
);
2034 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
2039 wbc_status
= wbcCredentialSave(name
, password
);
2041 d_printf("saving creds %s\n",
2042 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2046 return WBC_ERROR_IS_OK(wbc_status
);
2049 #ifdef WITH_FAKE_KASERVER
2050 /* Authenticate a user with a plaintext password and set a token */
2052 static bool wbinfo_klog(char *username
)
2054 struct winbindd_request request
;
2055 struct winbindd_response response
;
2059 /* Send off request */
2061 ZERO_STRUCT(request
);
2062 ZERO_STRUCT(response
);
2064 p
= strchr(username
, '%');
2068 fstrcpy(request
.data
.auth
.user
, username
);
2069 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
2072 fstrcpy(request
.data
.auth
.user
, username
);
2073 (void) samba_getpass("Password: ",
2074 request
.data
.auth
.pass
,
2075 sizeof(request
.data
.auth
.pass
),
2079 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
2081 result
= winbindd_request_response(NULL
, WINBINDD_PAM_AUTH
, &request
,
2084 /* Display response */
2086 d_printf("plaintext password authentication %s\n",
2087 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
2089 if (response
.data
.auth
.nt_status
)
2091 "error code was %s (0x%x)\nerror message was: %s\n",
2092 response
.data
.auth
.nt_status_string
,
2093 response
.data
.auth
.nt_status
,
2094 response
.data
.auth
.error_string
);
2096 if (result
!= NSS_STATUS_SUCCESS
)
2099 if (response
.extra_data
.data
== NULL
) {
2100 d_fprintf(stderr
, "Did not get token data\n");
2104 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
2105 d_fprintf(stderr
, "Could not set token\n");
2109 d_printf("Successfully created AFS token\n");
2113 static bool wbinfo_klog(char *username
)
2115 d_fprintf(stderr
, "No AFS support compiled in.\n");
2120 /* Print domain users */
2122 static bool print_domain_users(const char *domain
)
2124 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2126 uint32_t num_users
= 0;
2127 const char **users
= NULL
;
2129 /* Send request to winbind daemon */
2131 if (domain
== NULL
) {
2132 domain
= get_winbind_domain();
2134 /* '.' is the special sign for our own domain */
2135 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2136 domain
= get_winbind_domain();
2137 /* '*' is the special sign for all domains */
2138 } else if (strcmp(domain
, "*") == 0) {
2143 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
2144 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2148 for (i
=0; i
< num_users
; i
++) {
2149 d_printf("%s\n", users
[i
]);
2152 wbcFreeMemory(users
);
2157 /* Print domain groups */
2159 static bool print_domain_groups(const char *domain
)
2161 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2163 uint32_t num_groups
= 0;
2164 const char **groups
= NULL
;
2166 /* Send request to winbind daemon */
2168 if (domain
== NULL
) {
2169 domain
= get_winbind_domain();
2171 /* '.' is the special sign for our own domain */
2172 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2173 domain
= get_winbind_domain();
2174 /* '*' is the special sign for all domains */
2175 } else if (strcmp(domain
, "*") == 0) {
2180 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
2181 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2182 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
2183 wbcErrorString(wbc_status
));
2187 for (i
=0; i
< num_groups
; i
++) {
2188 d_printf("%s\n", groups
[i
]);
2191 wbcFreeMemory(groups
);
2196 /* Set the authorised user for winbindd access in secrets.tdb */
2198 static bool wbinfo_set_auth_user(char *username
)
2200 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2201 "See 'net help setauthuser' for details.\n");
2205 static void wbinfo_get_auth_user(void)
2207 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2208 "See 'net help getauthuser' for details.\n");
2211 static bool wbinfo_ping(void)
2215 wbc_status
= wbcPing();
2217 /* Display response */
2219 d_printf("Ping to winbindd %s\n",
2220 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2222 return WBC_ERROR_IS_OK(wbc_status
);
2225 static bool wbinfo_change_user_password(const char *username
)
2228 char *old_password
= NULL
;
2229 char *new_password
= NULL
;
2230 TALLOC_CTX
*frame
= talloc_tos();
2232 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2233 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2235 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2237 /* Display response */
2239 d_printf("Password change for user %s %s\n", username
,
2240 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2242 return WBC_ERROR_IS_OK(wbc_status
);
2248 OPT_SET_AUTH_USER
= 1000,
2261 OPT_SET_UID_MAPPING
,
2262 OPT_SET_GID_MAPPING
,
2263 OPT_REMOVE_UID_MAPPING
,
2264 OPT_REMOVE_GID_MAPPING
,
2268 OPT_LIST_ALL_DOMAINS
,
2269 OPT_LIST_OWN_DOMAIN
,
2276 OPT_CHANGE_USER_PASSWORD
,
2278 OPT_SID_TO_FULLNAME
,
2289 int main(int argc
, const char **argv
, char **envp
)
2292 TALLOC_CTX
*frame
= talloc_stackframe();
2294 static char *string_arg
;
2295 char *string_subarg
= NULL
;
2296 static char *opt_domain_name
;
2298 int int_subarg
= -1;
2300 bool verbose
= false;
2301 bool use_ntlmv2
= true;
2302 bool use_lanman
= false;
2303 char *logoff_user
= getenv("USER");
2304 int logoff_uid
= geteuid();
2305 const char *opt_krb5ccname
= "FILE";
2307 struct poptOption long_options
[] = {
2310 /* longName, shortName, argInfo, argPtr, value, descrip,
2314 .longName
= "domain-users",
2316 .argInfo
= POPT_ARG_NONE
,
2318 .descrip
= "Lists all domain users",
2319 .argDescrip
= "domain"
2322 .longName
= "domain-groups",
2324 .argInfo
= POPT_ARG_NONE
,
2326 .descrip
= "Lists all domain groups",
2327 .argDescrip
= "domain"
2330 .longName
= "WINS-by-name",
2332 .argInfo
= POPT_ARG_STRING
,
2335 .descrip
= "Converts NetBIOS name to IP",
2336 .argDescrip
= "NETBIOS-NAME"
2339 .longName
= "WINS-by-ip",
2341 .argInfo
= POPT_ARG_STRING
,
2344 .descrip
= "Converts IP address to NetBIOS name",
2348 .longName
= "name-to-sid",
2350 .argInfo
= POPT_ARG_STRING
,
2353 .descrip
= "Converts name to sid",
2354 .argDescrip
= "NAME"
2357 .longName
= "sid-to-name",
2359 .argInfo
= POPT_ARG_STRING
,
2362 .descrip
= "Converts sid to name",
2366 .longName
= "sid-to-fullname",
2367 .argInfo
= POPT_ARG_STRING
,
2369 .val
= OPT_SID_TO_FULLNAME
,
2370 .descrip
= "Converts sid to fullname",
2374 .longName
= "lookup-rids",
2376 .argInfo
= POPT_ARG_STRING
,
2379 .descrip
= "Converts RIDs to names",
2380 .argDescrip
= "RIDs"
2383 .longName
= "lookup-sids",
2384 .argInfo
= POPT_ARG_STRING
,
2386 .val
= OPT_LOOKUP_SIDS
,
2387 .descrip
= "Converts SIDs to types and names",
2388 .argDescrip
= "Sid-List"
2391 .longName
= "uid-to-sid",
2393 .argInfo
= POPT_ARG_INT
,
2396 .descrip
= "Converts uid to sid",
2400 .longName
= "gid-to-sid",
2402 .argInfo
= POPT_ARG_INT
,
2405 .descrip
= "Converts gid to sid",
2409 .longName
= "sid-to-uid",
2411 .argInfo
= POPT_ARG_STRING
,
2414 .descrip
= "Converts sid to uid",
2418 .longName
= "sid-to-gid",
2420 .argInfo
= POPT_ARG_STRING
,
2423 .descrip
= "Converts sid to gid",
2427 .longName
= "allocate-uid",
2428 .argInfo
= POPT_ARG_NONE
,
2429 .val
= OPT_ALLOCATE_UID
,
2430 .descrip
= "Get a new UID out of idmap"
2433 .longName
= "allocate-gid",
2434 .argInfo
= POPT_ARG_NONE
,
2435 .val
= OPT_ALLOCATE_GID
,
2436 .descrip
= "Get a new GID out of idmap"
2439 .longName
= "set-uid-mapping",
2440 .argInfo
= POPT_ARG_STRING
,
2442 .val
= OPT_SET_UID_MAPPING
,
2443 .descrip
= "Create or modify uid to sid mapping in "
2445 .argDescrip
= "UID,SID"
2448 .longName
= "set-gid-mapping",
2449 .argInfo
= POPT_ARG_STRING
,
2451 .val
= OPT_SET_GID_MAPPING
,
2452 .descrip
= "Create or modify gid to sid mapping in "
2454 .argDescrip
= "GID,SID"
2457 .longName
= "remove-uid-mapping",
2458 .argInfo
= POPT_ARG_STRING
,
2460 .val
= OPT_REMOVE_UID_MAPPING
,
2461 .descrip
= "Remove uid to sid mapping in idmap",
2462 .argDescrip
= "UID,SID"
2465 .longName
= "remove-gid-mapping",
2466 .argInfo
= POPT_ARG_STRING
,
2468 .val
= OPT_REMOVE_GID_MAPPING
,
2469 .descrip
= "Remove gid to sid mapping in idmap",
2470 .argDescrip
= "GID,SID",
2473 .longName
= "sids-to-unix-ids",
2474 .argInfo
= POPT_ARG_STRING
,
2476 .val
= OPT_SIDS_TO_XIDS
,
2477 .descrip
= "Translate SIDs to Unix IDs",
2478 .argDescrip
= "Sid-List",
2481 .longName
= "unix-ids-to-sids",
2482 .argInfo
= POPT_ARG_STRING
,
2484 .val
= OPT_XIDS_TO_SIDS
,
2485 .descrip
= "Translate Unix IDs to SIDs",
2486 .argDescrip
= "ID-List (u<num> g<num>)",
2489 .longName
= "check-secret",
2491 .argInfo
= POPT_ARG_NONE
,
2493 .descrip
= "Check shared secret",
2496 .longName
= "change-secret",
2498 .argInfo
= POPT_ARG_NONE
,
2500 .descrip
= "Change shared secret",
2503 .longName
= "ping-dc",
2505 .argInfo
= POPT_ARG_NONE
,
2507 .descrip
= "Check the NETLOGON connection",
2510 .longName
= "trusted-domains",
2512 .argInfo
= POPT_ARG_NONE
,
2514 .descrip
= "List trusted domains",
2517 .longName
= "all-domains",
2518 .argInfo
= POPT_ARG_NONE
,
2519 .val
= OPT_LIST_ALL_DOMAINS
,
2520 .descrip
= "List all domains (trusted and own "
2524 .longName
= "own-domain",
2525 .argInfo
= POPT_ARG_NONE
,
2526 .val
= OPT_LIST_OWN_DOMAIN
,
2527 .descrip
= "List own domain",
2530 .longName
= "sequence",
2531 .argInfo
= POPT_ARG_NONE
,
2532 .val
= OPT_SEQUENCE
,
2533 .descrip
= "Deprecated command, see --online-status",
2536 .longName
= "online-status",
2537 .argInfo
= POPT_ARG_NONE
,
2538 .val
= OPT_ONLINESTATUS
,
2539 .descrip
= "Show whether domains maintain an active "
2543 .longName
= "domain-info",
2545 .argInfo
= POPT_ARG_STRING
,
2548 .descrip
= "Show most of the info we have about the "
2552 .longName
= "user-info",
2554 .argInfo
= POPT_ARG_STRING
,
2557 .descrip
= "Get user info",
2558 .argDescrip
= "USER",
2561 .longName
= "uid-info",
2562 .argInfo
= POPT_ARG_INT
,
2564 .val
= OPT_UID_INFO
,
2565 .descrip
= "Get user info from uid",
2566 .argDescrip
= "UID",
2569 .longName
= "group-info",
2570 .argInfo
= POPT_ARG_STRING
,
2572 .val
= OPT_GROUP_INFO
,
2573 .descrip
= "Get group info",
2574 .argDescrip
= "GROUP",
2577 .longName
= "user-sidinfo",
2578 .argInfo
= POPT_ARG_STRING
,
2580 .val
= OPT_USER_SIDINFO
,
2581 .descrip
= "Get user info from sid",
2582 .argDescrip
= "SID",
2585 .longName
= "gid-info",
2586 .argInfo
= POPT_ARG_INT
,
2588 .val
= OPT_GID_INFO
,
2589 .descrip
= "Get group info from gid",
2590 .argDescrip
= "GID",
2593 .longName
= "user-groups",
2595 .argInfo
= POPT_ARG_STRING
,
2598 .descrip
= "Get user groups",
2599 .argDescrip
= "USER",
2602 .longName
= "user-domgroups",
2603 .argInfo
= POPT_ARG_STRING
,
2605 .val
= OPT_USERDOMGROUPS
,
2606 .descrip
= "Get user domain groups",
2607 .argDescrip
= "SID",
2610 .longName
= "sid-aliases",
2611 .argInfo
= POPT_ARG_STRING
,
2613 .val
= OPT_SIDALIASES
,
2614 .descrip
= "Get sid aliases",
2615 .argDescrip
= "SID",
2618 .longName
= "user-sids",
2619 .argInfo
= POPT_ARG_STRING
,
2621 .val
= OPT_USERSIDS
,
2622 .descrip
= "Get user group sids for user SID",
2623 .argDescrip
= "SID",
2626 .longName
= "authenticate",
2628 .argInfo
= POPT_ARG_STRING
,
2631 .descrip
= "authenticate user",
2632 .argDescrip
= "user%password",
2635 .longName
= "pam-logon",
2636 .argInfo
= POPT_ARG_STRING
,
2638 .val
= OPT_PAM_LOGON
,
2639 .descrip
= "do a pam logon equivalent",
2640 .argDescrip
= "user%password",
2643 .longName
= "logoff",
2644 .argInfo
= POPT_ARG_NONE
,
2646 .descrip
= "log off user",
2647 .argDescrip
= "uid",
2650 .longName
= "logoff-user",
2651 .argInfo
= POPT_ARG_STRING
,
2652 .arg
= &logoff_user
,
2653 .val
= OPT_LOGOFF_USER
,
2654 .descrip
= "username to log off"
2657 .longName
= "logoff-uid",
2658 .argInfo
= POPT_ARG_INT
,
2660 .val
= OPT_LOGOFF_UID
,
2661 .descrip
= "uid to log off",
2664 .longName
= "set-auth-user",
2665 .argInfo
= POPT_ARG_STRING
,
2667 .val
= OPT_SET_AUTH_USER
,
2668 .descrip
= "Store user and password used by "
2669 "winbindd (root only)",
2670 .argDescrip
= "user%password",
2673 .longName
= "ccache-save",
2675 .argInfo
= POPT_ARG_STRING
,
2677 .val
= OPT_CCACHE_SAVE
,
2678 .descrip
= "Store user and password for ccache "
2680 .argDescrip
= "user%password",
2683 .longName
= "getdcname",
2684 .argInfo
= POPT_ARG_STRING
,
2686 .val
= OPT_GETDCNAME
,
2687 .descrip
= "Get a DC name for a foreign domain",
2688 .argDescrip
= "domainname",
2691 .longName
= "dsgetdcname",
2692 .argInfo
= POPT_ARG_STRING
,
2694 .val
= OPT_DSGETDCNAME
,
2695 .descrip
= "Find a DC for a domain",
2696 .argDescrip
= "domainname",
2699 .longName
= "dc-info",
2700 .argInfo
= POPT_ARG_STRING
,
2703 .descrip
= "Find the currently known DCs",
2704 .argDescrip
= "domainname",
2707 .longName
= "get-auth-user",
2708 .argInfo
= POPT_ARG_NONE
,
2709 .val
= OPT_GET_AUTH_USER
,
2710 .descrip
= "Retrieve user and password used by "
2711 "winbindd (root only)",
2716 .argInfo
= POPT_ARG_NONE
,
2719 .descrip
= "Ping winbindd to see if it is alive",
2722 .longName
= "domain",
2724 .argInfo
= POPT_ARG_STRING
,
2725 .arg
= &opt_domain_name
,
2726 .val
= OPT_DOMAIN_NAME
,
2727 .descrip
= "Define to the domain to restrict "
2729 .argDescrip
= "domain",
2731 #ifdef WITH_FAKE_KASERVER
2735 .argInfo
= POPT_ARG_STRING
,
2738 .descrip
= "set an AFS token from winbind",
2739 .argDescrip
= "user%password",
2744 .longName
= "krb5auth",
2746 .argInfo
= POPT_ARG_STRING
,
2749 .descrip
= "authenticate user using Kerberos",
2750 .argDescrip
= "user%password",
2752 /* destroys wbinfo --help output */
2753 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2756 .longName
= "krb5ccname",
2757 .argInfo
= POPT_ARG_STRING
,
2758 .arg
= &opt_krb5ccname
,
2759 .val
= OPT_KRB5CCNAME
,
2760 .descrip
= "authenticate user using Kerberos and "
2761 "specific credential cache type",
2762 .argDescrip
= "krb5ccname",
2766 .longName
= "separator",
2767 .argInfo
= POPT_ARG_NONE
,
2768 .val
= OPT_SEPARATOR
,
2769 .descrip
= "Get the active winbind separator",
2772 .longName
= "verbose",
2773 .argInfo
= POPT_ARG_NONE
,
2775 .descrip
= "Print additional information per command",
2778 .longName
= "change-user-password",
2779 .argInfo
= POPT_ARG_STRING
,
2781 .val
= OPT_CHANGE_USER_PASSWORD
,
2782 .descrip
= "Change the password for a user",
2785 .longName
= "ntlmv1",
2786 .argInfo
= POPT_ARG_NONE
,
2788 .descrip
= "Use NTLMv1 cryptography for user authentication",
2791 .longName
= "ntlmv2",
2792 .argInfo
= POPT_ARG_NONE
,
2794 .descrip
= "Use NTLMv2 cryptography for user authentication",
2797 .longName
= "lanman",
2798 .argInfo
= POPT_ARG_NONE
,
2800 .descrip
= "Use lanman cryptography for user authentication",
2806 /* Samba client initialisation */
2812 pc
= poptGetContext("wbinfo", argc
, argv
,
2815 /* Parse command line options */
2818 poptPrintHelp(pc
, stderr
, 0);
2822 while((opt
= poptGetNextOpt(pc
)) != -1) {
2823 /* get the generic configuration parameters like --domain */
2837 poptFreeContext(pc
);
2839 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2840 POPT_CONTEXT_KEEP_FIRST
);
2842 while((opt
= poptGetNextOpt(pc
)) != -1) {
2845 if (!print_domain_users(opt_domain_name
)) {
2847 "Error looking up domain users\n");
2852 if (!print_domain_groups(opt_domain_name
)) {
2854 "Error looking up domain groups\n");
2859 if (!wbinfo_lookupsid(string_arg
)) {
2861 "Could not lookup sid %s\n",
2866 case OPT_SID_TO_FULLNAME
:
2867 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2868 d_fprintf(stderr
, "Could not lookup sid %s\n",
2874 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2875 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2880 case OPT_LOOKUP_SIDS
:
2881 if (!wbinfo_lookup_sids(string_arg
)) {
2882 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2888 if (!wbinfo_lookupname(string_arg
)) {
2889 d_fprintf(stderr
, "Could not lookup name %s\n",
2895 if (!wbinfo_wins_byname(string_arg
)) {
2897 "Could not lookup WINS by name %s\n",
2903 if (!wbinfo_wins_byip(string_arg
)) {
2905 "Could not lookup WINS by IP %s\n",
2911 if (!wbinfo_uid_to_sid(int_arg
)) {
2913 "Could not convert uid %d to sid\n",
2919 if (!wbinfo_gid_to_sid(int_arg
)) {
2921 "Could not convert gid %d to sid\n",
2927 if (!wbinfo_sid_to_uid(string_arg
)) {
2929 "Could not convert sid %s to uid\n",
2935 if (!wbinfo_sid_to_gid(string_arg
)) {
2937 "Could not convert sid %s to gid\n",
2942 case OPT_ALLOCATE_UID
:
2943 if (!wbinfo_allocate_uid()) {
2944 d_fprintf(stderr
, "Could not allocate a uid\n");
2948 case OPT_ALLOCATE_GID
:
2949 if (!wbinfo_allocate_gid()) {
2950 d_fprintf(stderr
, "Could not allocate a gid\n");
2954 case OPT_SET_UID_MAPPING
:
2955 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2957 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2959 d_fprintf(stderr
, "Could not create or modify "
2960 "uid to sid mapping\n");
2964 case OPT_SET_GID_MAPPING
:
2965 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2967 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2969 d_fprintf(stderr
, "Could not create or modify "
2970 "gid to sid mapping\n");
2974 case OPT_REMOVE_UID_MAPPING
:
2975 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2977 !wbinfo_remove_uid_mapping(int_subarg
,
2980 d_fprintf(stderr
, "Could not remove uid to sid "
2985 case OPT_REMOVE_GID_MAPPING
:
2986 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2988 !wbinfo_remove_gid_mapping(int_subarg
,
2991 d_fprintf(stderr
, "Could not remove gid to sid "
2996 case OPT_SIDS_TO_XIDS
:
2997 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
2998 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
3003 case OPT_XIDS_TO_SIDS
:
3004 if (!wbinfo_xids_to_sids(string_arg
)) {
3005 d_fprintf(stderr
, "wbinfo_xids_to_sids "
3011 if (!wbinfo_check_secret(opt_domain_name
)) {
3012 d_fprintf(stderr
, "Could not check secret\n");
3017 if (!wbinfo_change_secret(opt_domain_name
)) {
3018 d_fprintf(stderr
, "Could not change secret\n");
3023 if (!wbinfo_ping_dc(opt_domain_name
)) {
3028 if (!wbinfo_list_domains(false, verbose
)) {
3030 "Could not list trusted domains\n");
3035 if (!wbinfo_show_sequence(opt_domain_name
)) {
3037 "Could not show sequence numbers\n");
3041 case OPT_ONLINESTATUS
:
3042 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
3044 "Could not show online-status\n");
3049 if (!wbinfo_domain_info(string_arg
)) {
3051 "Could not get domain info\n");
3056 if (!wbinfo_get_userinfo(string_arg
)) {
3058 "Could not get info for user %s\n",
3063 case OPT_USER_SIDINFO
:
3064 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
3066 "Could not get info for user "
3067 "sid %s\n", string_arg
);
3072 if ( !wbinfo_get_uidinfo(int_arg
)) {
3073 d_fprintf(stderr
, "Could not get info for uid "
3078 case OPT_GROUP_INFO
:
3079 if ( !wbinfo_get_groupinfo(string_arg
)) {
3080 d_fprintf(stderr
, "Could not get info for "
3081 "group %s\n", string_arg
);
3086 if ( !wbinfo_get_gidinfo(int_arg
)) {
3087 d_fprintf(stderr
, "Could not get info for gid "
3093 if (!wbinfo_get_usergroups(string_arg
)) {
3095 "Could not get groups for user %s\n",
3101 if (!wbinfo_get_usersids(string_arg
)) {
3102 d_fprintf(stderr
, "Could not get group SIDs "
3103 "for user SID %s\n",
3108 case OPT_USERDOMGROUPS
:
3109 if (!wbinfo_get_userdomgroups(string_arg
)) {
3110 d_fprintf(stderr
, "Could not get user's domain "
3111 "groups for user SID %s\n",
3116 case OPT_SIDALIASES
:
3117 if (!wbinfo_get_sidaliases(opt_domain_name
,
3119 d_fprintf(stderr
, "Could not get sid aliases "
3120 "for user SID %s\n", string_arg
);
3125 bool got_error
= false;
3127 if (!wbinfo_auth(string_arg
)) {
3129 "Could not authenticate user "
3130 "%s with plaintext "
3131 "password\n", string_arg
);
3135 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
3138 "Could not authenticate user "
3139 "%s with challenge/response\n",
3149 if (!wbinfo_pam_logon(string_arg
, verbose
)) {
3150 d_fprintf(stderr
, "pam_logon failed for %s\n",
3159 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
3161 d_printf("Logoff %s (%d): %s\n", logoff_user
,
3162 logoff_uid
, wbcErrorString(wbc_status
));
3166 uint32_t flags
= WBFLAG_PAM_KRB5
|
3167 WBFLAG_PAM_CACHED_LOGIN
|
3168 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
3169 WBFLAG_PAM_INFO3_TEXT
|
3170 WBFLAG_PAM_CONTACT_TRUSTDOM
;
3172 if (!wbinfo_auth_krb5(string_arg
, opt_krb5ccname
,
3175 "Could not authenticate user "
3176 "[%s] with Kerberos "
3177 "(ccache: %s)\n", string_arg
,
3184 if (!wbinfo_klog(string_arg
)) {
3185 d_fprintf(stderr
, "Could not klog user\n");
3190 if (!wbinfo_ping()) {
3191 d_fprintf(stderr
, "could not ping winbindd!\n");
3195 case OPT_SET_AUTH_USER
:
3196 if (!wbinfo_set_auth_user(string_arg
)) {
3200 case OPT_GET_AUTH_USER
:
3201 wbinfo_get_auth_user();
3204 case OPT_CCACHE_SAVE
:
3205 if (!wbinfo_ccache_save(string_arg
)) {
3210 if (!wbinfo_getdcname(string_arg
)) {
3214 case OPT_DSGETDCNAME
:
3215 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
3220 if (!wbinfo_dc_info(string_arg
)) {
3224 case OPT_SEPARATOR
: {
3225 const char sep
= winbind_separator();
3229 d_printf("%c\n", sep
);
3232 case OPT_LIST_ALL_DOMAINS
:
3233 if (!wbinfo_list_domains(true, verbose
)) {
3237 case OPT_LIST_OWN_DOMAIN
:
3238 if (!wbinfo_list_own_domain()) {
3242 case OPT_CHANGE_USER_PASSWORD
:
3243 if (!wbinfo_change_user_password(string_arg
)) {
3245 "Could not change user password "
3246 "for user %s\n", string_arg
);
3251 /* generic configuration options */
3252 case OPT_DOMAIN_NAME
:
3257 case OPT_LOGOFF_USER
:
3258 case OPT_LOGOFF_UID
:
3259 case OPT_KRB5CCNAME
:
3262 d_fprintf(stderr
, "Invalid option\n");
3263 poptPrintHelp(pc
, stderr
, 0);
3275 poptFreeContext(pc
);