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"
30 #include "lib/util/smb_strtox.h"
31 #include "lib/util/string_wrappers.h"
35 #define DBGC_CLASS DBGC_WINBIND
38 static struct wbcInterfaceDetails
*init_interface_details(void)
40 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
41 static struct wbcInterfaceDetails
*details
;
47 wbc_status
= wbcInterfaceDetails(&details
);
48 if (!WBC_ERROR_IS_OK(wbc_status
)) {
49 d_fprintf(stderr
, "could not obtain winbind interface "
50 "details: %s\n", wbcErrorString(wbc_status
));
56 static char winbind_separator(void)
58 struct wbcInterfaceDetails
*details
;
65 details
= init_interface_details();
68 d_fprintf(stderr
, "could not obtain winbind separator!\n");
72 sep
= details
->winbind_separator
;
76 d_fprintf(stderr
, "winbind separator was NULL!\n");
83 static const char *get_winbind_domain(void)
85 static struct wbcInterfaceDetails
*details
;
87 details
= init_interface_details();
90 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
94 return details
->netbios_domain
;
97 static const char *get_winbind_netbios_name(void)
99 static struct wbcInterfaceDetails
*details
;
101 details
= init_interface_details();
104 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
108 return details
->netbios_name
;
111 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
112 form DOMAIN/user into a domain and a user */
114 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
118 char *p
= strchr(domuser
,winbind_separator());
121 /* Maybe it was a UPN? */
122 p
= strchr(domuser
, '@');
125 fstrcpy(user
, domuser
);
129 fstrcpy(user
, domuser
);
130 fstrcpy(domain
, get_winbind_domain());
135 fstrcpy(domain
, domuser
);
136 domain
[PTR_DIFF(p
, domuser
)] = 0;
141 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
142 * Return true if input was valid, false otherwise. */
143 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
151 tmp
= strtok(arg
, ",");
152 *sid
= strtok(NULL
, ",");
154 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
157 /* Because atoi() can return 0 on invalid input, which would be a valid
158 * UID/GID we must use strtoul() and do error checking */
159 *id
= smb_strtoul(tmp
, NULL
, 10, &error
, SMB_STR_FULL_STR_CONV
);
166 /* pull pwent info for a given user */
168 static bool wbinfo_get_userinfo(char *user
)
170 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
171 struct passwd
*pwd
= NULL
;
173 wbc_status
= wbcGetpwnam(user
, &pwd
);
174 if (!WBC_ERROR_IS_OK(wbc_status
)) {
175 d_fprintf(stderr
, "failed to call wbcGetpwnam: %s\n",
176 wbcErrorString(wbc_status
));
180 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
183 (unsigned int)pwd
->pw_uid
,
184 (unsigned int)pwd
->pw_gid
,
194 /* pull pwent info for a given uid */
195 static bool wbinfo_get_uidinfo(int uid
)
197 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
198 struct passwd
*pwd
= NULL
;
200 wbc_status
= wbcGetpwuid(uid
, &pwd
);
201 if (!WBC_ERROR_IS_OK(wbc_status
)) {
202 d_fprintf(stderr
, "failed to call wbcGetpwuid: %s\n",
203 wbcErrorString(wbc_status
));
207 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
210 (unsigned int)pwd
->pw_uid
,
211 (unsigned int)pwd
->pw_gid
,
221 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
223 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
224 struct passwd
*pwd
= NULL
;
225 struct wbcDomainSid sid
;
227 wbc_status
= wbcStringToSid(sid_str
, &sid
);
228 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
229 if (!WBC_ERROR_IS_OK(wbc_status
)) {
230 d_fprintf(stderr
, "failed to call wbcGetpwsid: %s\n",
231 wbcErrorString(wbc_status
));
235 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
238 (unsigned int)pwd
->pw_uid
,
239 (unsigned int)pwd
->pw_gid
,
250 /* pull grent for a given group */
251 static bool wbinfo_get_groupinfo(const char *group
)
253 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
257 wbc_status
= wbcGetgrnam(group
, &grp
);
258 if (!WBC_ERROR_IS_OK(wbc_status
)) {
259 d_fprintf(stderr
, "failed to call wbcGetgrnam: %s\n",
260 wbcErrorString(wbc_status
));
264 d_printf("%s:%s:%u:",
267 (unsigned int)grp
->gr_gid
);
270 while (*mem
!= NULL
) {
271 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
281 /* pull grent for a given gid */
282 static bool wbinfo_get_gidinfo(int gid
)
284 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
288 wbc_status
= wbcGetgrgid(gid
, &grp
);
289 if (!WBC_ERROR_IS_OK(wbc_status
)) {
290 d_fprintf(stderr
, "failed to call wbcGetgrgid: %s\n",
291 wbcErrorString(wbc_status
));
295 d_printf("%s:%s:%u:",
298 (unsigned int)grp
->gr_gid
);
301 while (*mem
!= NULL
) {
302 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
312 /* List groups a user is a member of */
314 static bool wbinfo_get_usergroups(const char *user
)
316 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
319 gid_t
*groups
= NULL
;
323 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
324 if (!WBC_ERROR_IS_OK(wbc_status
)) {
325 d_fprintf(stderr
, "failed to call wbcGetGroups: %s\n",
326 wbcErrorString(wbc_status
));
330 for (i
= 0; i
< num_groups
; i
++) {
331 d_printf("%d\n", (int)groups
[i
]);
334 wbcFreeMemory(groups
);
340 /* List group SIDs a user SID is a member of */
341 static bool wbinfo_get_usersids(const char *user_sid_str
)
343 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
346 struct wbcDomainSid user_sid
, *sids
= NULL
;
350 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
351 if (!WBC_ERROR_IS_OK(wbc_status
)) {
352 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
353 wbcErrorString(wbc_status
));
357 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
358 if (!WBC_ERROR_IS_OK(wbc_status
)) {
359 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
360 wbcErrorString(wbc_status
));
364 for (i
= 0; i
< num_sids
; i
++) {
365 char str
[WBC_SID_STRING_BUFLEN
];
366 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
367 d_printf("%s\n", str
);
375 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
377 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
380 struct wbcDomainSid user_sid
, *sids
= NULL
;
384 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
385 if (!WBC_ERROR_IS_OK(wbc_status
)) {
386 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
387 wbcErrorString(wbc_status
));
391 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
392 if (!WBC_ERROR_IS_OK(wbc_status
)) {
393 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
394 wbcErrorString(wbc_status
));
398 for (i
= 0; i
< num_sids
; i
++) {
399 char str
[WBC_SID_STRING_BUFLEN
];
400 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
401 d_printf("%s\n", str
);
409 static bool wbinfo_get_sidaliases(const char *domain
,
410 const char *user_sid_str
)
412 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
413 struct wbcDomainInfo
*dinfo
= NULL
;
415 struct wbcDomainSid user_sid
;
416 uint32_t *alias_rids
= NULL
;
417 uint32_t num_alias_rids
;
418 char domain_sid_str
[WBC_SID_STRING_BUFLEN
];
421 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
422 (domain
[0] == '\0')) {
423 domain
= get_winbind_domain();
428 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
429 if (!WBC_ERROR_IS_OK(wbc_status
)) {
430 d_fprintf(stderr
, "wbcDomainInfo(%s) failed: %s\n", domain
,
431 wbcErrorString(wbc_status
));
434 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
435 if (!WBC_ERROR_IS_OK(wbc_status
)) {
439 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
440 &alias_rids
, &num_alias_rids
);
441 if (!WBC_ERROR_IS_OK(wbc_status
)) {
445 wbcSidToStringBuf(&dinfo
->sid
, domain_sid_str
, sizeof(domain_sid_str
));
447 for (i
= 0; i
< num_alias_rids
; i
++) {
448 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
451 wbcFreeMemory(alias_rids
);
454 wbcFreeMemory(dinfo
);
455 return (WBC_ERR_SUCCESS
== wbc_status
);
459 /* Convert NetBIOS name to IP */
461 static bool wbinfo_wins_byname(const char *name
)
463 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
466 wbc_status
= wbcResolveWinsByName(name
, &ip
);
467 if (!WBC_ERROR_IS_OK(wbc_status
)) {
468 d_fprintf(stderr
, "failed to call wbcResolveWinsByName: %s\n",
469 wbcErrorString(wbc_status
));
473 /* Display response */
475 d_printf("%s\n", ip
);
482 /* Convert IP to NetBIOS name */
484 static bool wbinfo_wins_byip(const char *ip
)
486 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
489 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
490 if (!WBC_ERROR_IS_OK(wbc_status
)) {
491 d_fprintf(stderr
, "failed to call wbcResolveWinsByIP: %s\n",
492 wbcErrorString(wbc_status
));
496 /* Display response */
498 d_printf("%s\n", name
);
505 /* List all/trusted domains */
507 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
509 struct wbcDomainInfo
*domain_list
= NULL
;
510 size_t i
, num_domains
;
511 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
512 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
;
619 size_t i
, num_domains
;
620 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
622 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
623 if (!WBC_ERROR_IS_OK(wbc_status
)) {
624 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
625 wbcErrorString(wbc_status
));
629 for (i
=0; i
<num_domains
; i
++) {
633 if (!strequal(domain_list
[i
].short_name
, domain
)) {
638 is_offline
= (domain_list
[i
].domain_flags
&
639 WBC_DOMINFO_DOMAIN_OFFLINE
);
641 d_printf("%s : %s\n",
642 domain_list
[i
].short_name
,
643 is_offline
? "no active connection" : "active connection" );
646 wbcFreeMemory(domain_list
);
652 /* Show domain info */
654 static bool wbinfo_domain_info(const char *domain
)
656 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
657 struct wbcDomainInfo
*dinfo
= NULL
;
658 char sid_str
[WBC_SID_STRING_BUFLEN
];
660 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
661 domain
= get_winbind_domain();
666 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
667 if (!WBC_ERROR_IS_OK(wbc_status
)) {
668 d_fprintf(stderr
, "failed to call wbcDomainInfo: %s\n",
669 wbcErrorString(wbc_status
));
673 wbcSidToStringBuf(&dinfo
->sid
, sid_str
, sizeof(sid_str
));
675 /* Display response */
677 d_printf("Name : %s\n", dinfo
->short_name
);
678 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
680 d_printf("SID : %s\n", sid_str
);
682 d_printf("Active Directory : %s\n",
683 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
684 d_printf("Native : %s\n",
685 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ?
688 d_printf("Primary : %s\n",
689 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ?
692 wbcFreeMemory(dinfo
);
697 /* Get a foreign DC's name */
698 static bool wbinfo_getdcname(const char *domain_name
)
700 struct winbindd_request request
;
701 struct winbindd_response response
;
703 ZERO_STRUCT(request
);
704 ZERO_STRUCT(response
);
706 fstrcpy(request
.domain_name
, domain_name
);
710 if (winbindd_request_response(NULL
, WINBINDD_GETDCNAME
, &request
,
711 &response
) != NSS_STATUS_SUCCESS
) {
712 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
716 /* Display response */
718 d_printf("%s\n", response
.data
.dc_name
);
724 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
726 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
727 struct wbcDomainControllerInfoEx
*dc_info
;
730 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
731 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
733 if (!WBC_ERROR_IS_OK(wbc_status
)) {
734 printf("Could not find dc for %s\n", domain_name
);
738 wbcGuidToString(dc_info
->domain_guid
, &str
);
740 d_printf("%s\n", dc_info
->dc_unc
);
741 d_printf("%s\n", dc_info
->dc_address
);
742 d_printf("%d\n", dc_info
->dc_address_type
);
743 d_printf("%s\n", str
);
744 d_printf("%s\n", dc_info
->domain_name
);
745 d_printf("%s\n", dc_info
->forest_name
);
746 d_printf("0x%08x\n", dc_info
->dc_flags
);
747 d_printf("%s\n", dc_info
->dc_site_name
);
748 d_printf("%s\n", dc_info
->client_site_name
);
751 wbcFreeMemory(dc_info
);
756 /* Check trust account password */
758 static bool wbinfo_check_secret(const char *domain
)
760 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
761 struct wbcAuthErrorInfo
*error
= NULL
;
762 const char *domain_name
;
765 domain_name
= domain
;
767 domain_name
= get_winbind_domain();
770 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
772 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
774 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
776 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
777 d_fprintf(stderr
, "wbcCheckTrustCredentials(%s): error code was %s (0x%x)\n",
778 domain_name
, error
->nt_string
, error
->nt_status
);
779 wbcFreeMemory(error
);
781 if (!WBC_ERROR_IS_OK(wbc_status
)) {
782 d_fprintf(stderr
, "failed to call wbcCheckTrustCredentials: "
783 "%s\n", wbcErrorString(wbc_status
));
790 /* Find the currently connected DCs */
792 static bool wbinfo_dc_info(const char *domain_name
)
794 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
796 const char **dc_names
, **dc_ips
;
798 wbc_status
= wbcDcInfo(domain_name
, &num_dcs
,
800 if (!WBC_ERROR_IS_OK(wbc_status
)) {
801 printf("Could not find dc info %s\n",
802 domain_name
? domain_name
: "our domain");
806 for (i
=0; i
<num_dcs
; i
++) {
807 printf("%s (%s)\n", dc_names
[i
], dc_ips
[i
]);
809 wbcFreeMemory(dc_names
);
810 wbcFreeMemory(dc_ips
);
815 /* Change trust account password */
817 static bool wbinfo_change_secret(const char *domain
)
819 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
820 struct wbcAuthErrorInfo
*error
= NULL
;
821 const char *domain_name
;
824 domain_name
= domain
;
826 domain_name
= get_winbind_domain();
829 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
831 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
833 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
835 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
836 d_fprintf(stderr
, "wbcChangeTrustCredentials(%s): error code was %s (0x%x)\n",
837 domain_name
, error
->nt_string
, error
->nt_status
);
838 wbcFreeMemory(error
);
840 if (!WBC_ERROR_IS_OK(wbc_status
)) {
841 d_fprintf(stderr
, "failed to call wbcChangeTrustCredentials: "
842 "%s\n", wbcErrorString(wbc_status
));
849 /* Check DC connection */
851 static bool wbinfo_ping_dc(const char *domain
)
853 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
854 struct wbcAuthErrorInfo
*error
= NULL
;
857 const char *domain_name
;
860 domain_name
= domain
;
862 domain_name
= get_winbind_domain();
865 wbc_status
= wbcPingDc2(domain_name
, &error
, &dcname
);
867 d_printf("checking the NETLOGON for domain[%s] dc connection to \"%s\" %s\n",
868 domain_name
? domain_name
: "",
869 dcname
? dcname
: "",
870 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
872 wbcFreeMemory(dcname
);
873 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
874 d_fprintf(stderr
, "wbcPingDc2(%s): error code was %s (0x%x)\n",
875 domain_name
, error
->nt_string
, error
->nt_status
);
876 wbcFreeMemory(error
);
879 if (!WBC_ERROR_IS_OK(wbc_status
)) {
880 d_fprintf(stderr
, "failed to call wbcPingDc: %s\n",
881 wbcErrorString(wbc_status
));
888 /* Convert uid to sid */
890 static bool wbinfo_uid_to_sid(uid_t uid
)
892 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
893 struct wbcDomainSid sid
;
894 char sid_str
[WBC_SID_STRING_BUFLEN
];
898 wbc_status
= wbcUidToSid(uid
, &sid
);
899 if (!WBC_ERROR_IS_OK(wbc_status
)) {
900 d_fprintf(stderr
, "failed to call wbcUidToSid: %s\n",
901 wbcErrorString(wbc_status
));
905 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
907 /* Display response */
909 d_printf("%s\n", sid_str
);
914 /* Convert gid to sid */
916 static bool wbinfo_gid_to_sid(gid_t gid
)
918 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
919 struct wbcDomainSid sid
;
920 char sid_str
[WBC_SID_STRING_BUFLEN
];
924 wbc_status
= wbcGidToSid(gid
, &sid
);
925 if (!WBC_ERROR_IS_OK(wbc_status
)) {
926 d_fprintf(stderr
, "failed to call wbcGidToSid: %s\n",
927 wbcErrorString(wbc_status
));
931 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
933 /* Display response */
935 d_printf("%s\n", sid_str
);
940 /* Convert sid to uid */
942 static bool wbinfo_sid_to_uid(const char *sid_str
)
944 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
945 struct wbcDomainSid sid
;
950 wbc_status
= wbcStringToSid(sid_str
, &sid
);
951 if (!WBC_ERROR_IS_OK(wbc_status
)) {
952 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
953 wbcErrorString(wbc_status
));
957 wbc_status
= wbcSidToUid(&sid
, &uid
);
958 if (!WBC_ERROR_IS_OK(wbc_status
)) {
959 d_fprintf(stderr
, "failed to call wbcSidToUid: %s\n",
960 wbcErrorString(wbc_status
));
964 /* Display response */
966 d_printf("%d\n", (int)uid
);
971 static bool wbinfo_sid_to_gid(const char *sid_str
)
973 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
974 struct wbcDomainSid sid
;
979 wbc_status
= wbcStringToSid(sid_str
, &sid
);
980 if (!WBC_ERROR_IS_OK(wbc_status
)) {
981 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
982 wbcErrorString(wbc_status
));
986 wbc_status
= wbcSidToGid(&sid
, &gid
);
987 if (!WBC_ERROR_IS_OK(wbc_status
)) {
988 d_fprintf(stderr
, "failed to call wbcSidToGid: %s\n",
989 wbcErrorString(wbc_status
));
993 /* Display response */
995 d_printf("%d\n", (int)gid
);
1000 static bool wbinfo_sids_to_unix_ids(const char *arg
)
1002 char sidstr
[WBC_SID_STRING_BUFLEN
];
1003 struct wbcDomainSid
*sids
;
1004 struct wbcUnixId
*unix_ids
;
1014 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1015 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1018 d_fprintf(stderr
, "talloc failed\n");
1021 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1022 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1023 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1024 sidstr
, wbcErrorString(wbc_status
));
1031 unix_ids
= talloc_array(talloc_tos(), struct wbcUnixId
, num_sids
);
1032 if (unix_ids
== NULL
) {
1037 wbc_status
= wbcSidsToUnixIds(sids
, num_sids
, unix_ids
);
1038 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1039 d_fprintf(stderr
, "wbcSidsToUnixIds failed: %s\n",
1040 wbcErrorString(wbc_status
));
1045 for (i
=0; i
<num_sids
; i
++) {
1047 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1049 switch(unix_ids
[i
].type
) {
1050 case WBC_ID_TYPE_UID
:
1051 d_printf("%s -> uid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1053 case WBC_ID_TYPE_GID
:
1054 d_printf("%s -> gid %d\n", sidstr
, unix_ids
[i
].id
.gid
);
1056 case WBC_ID_TYPE_BOTH
:
1057 d_printf("%s -> uid/gid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1060 d_printf("%s -> unmapped\n", sidstr
);
1066 TALLOC_FREE(unix_ids
);
1071 static bool wbinfo_xids_to_sids(const char *arg
)
1074 struct wbcUnixId
*xids
= NULL
;
1075 struct wbcDomainSid
*sids
;
1083 while (next_token(&p
, idstr
, LIST_SEP
, sizeof(idstr
))) {
1084 xids
= talloc_realloc(talloc_tos(), xids
, struct wbcUnixId
,
1087 d_fprintf(stderr
, "talloc failed\n");
1093 xids
[num_xids
] = (struct wbcUnixId
) {
1094 .type
= WBC_ID_TYPE_UID
,
1095 .id
.uid
= atoi(&idstr
[1])
1099 xids
[num_xids
] = (struct wbcUnixId
) {
1100 .type
= WBC_ID_TYPE_GID
,
1101 .id
.gid
= atoi(&idstr
[1])
1105 d_fprintf(stderr
, "%s is an invalid id\n", idstr
);
1112 sids
= talloc_array(talloc_tos(), struct wbcDomainSid
, num_xids
);
1114 d_fprintf(stderr
, "talloc failed\n");
1119 wbc_status
= wbcUnixIdsToSids(xids
, num_xids
, sids
);
1120 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1121 d_fprintf(stderr
, "wbcUnixIdsToSids failed: %s\n",
1122 wbcErrorString(wbc_status
));
1128 for (i
=0; i
<num_xids
; i
++) {
1129 char str
[WBC_SID_STRING_BUFLEN
];
1130 struct wbcDomainSid null_sid
= { 0 };
1132 if (memcmp(&null_sid
, &sids
[i
], sizeof(struct wbcDomainSid
)) == 0) {
1133 d_printf("NOT MAPPED\n");
1136 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
1137 d_printf("%s\n", str
);
1143 static bool wbinfo_allocate_uid(void)
1145 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1150 wbc_status
= wbcAllocateUid(&uid
);
1151 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1152 d_fprintf(stderr
, "failed to call wbcAllocateUid: %s\n",
1153 wbcErrorString(wbc_status
));
1157 /* Display response */
1159 d_printf("New uid: %u\n", (unsigned int)uid
);
1164 static bool wbinfo_allocate_gid(void)
1166 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1171 wbc_status
= wbcAllocateGid(&gid
);
1172 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1173 d_fprintf(stderr
, "failed to call wbcAllocateGid: %s\n",
1174 wbcErrorString(wbc_status
));
1178 /* Display response */
1180 d_printf("New gid: %u\n", (unsigned int)gid
);
1185 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
1187 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1188 struct wbcDomainSid sid
;
1192 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1193 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1194 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1195 wbcErrorString(wbc_status
));
1199 wbc_status
= wbcSetUidMapping(uid
, &sid
);
1200 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1201 d_fprintf(stderr
, "failed to call wbcSetUidMapping: %s\n",
1202 wbcErrorString(wbc_status
));
1206 /* Display response */
1208 d_printf("uid %u now mapped to sid %s\n",
1209 (unsigned int)uid
, sid_str
);
1214 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
1216 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1217 struct wbcDomainSid sid
;
1221 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1222 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1223 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1224 wbcErrorString(wbc_status
));
1228 wbc_status
= wbcSetGidMapping(gid
, &sid
);
1229 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1230 d_fprintf(stderr
, "failed to call wbcSetGidMapping: %s\n",
1231 wbcErrorString(wbc_status
));
1235 /* Display response */
1237 d_printf("gid %u now mapped to sid %s\n",
1238 (unsigned int)gid
, sid_str
);
1243 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1245 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1246 struct wbcDomainSid sid
;
1250 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1251 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1252 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1253 wbcErrorString(wbc_status
));
1257 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1258 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1259 d_fprintf(stderr
, "failed to call wbcRemoveUidMapping: %s\n",
1260 wbcErrorString(wbc_status
));
1264 /* Display response */
1266 d_printf("Removed uid %u to sid %s mapping\n",
1267 (unsigned int)uid
, sid_str
);
1272 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1274 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1275 struct wbcDomainSid sid
;
1279 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1280 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1281 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1282 wbcErrorString(wbc_status
));
1286 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1287 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1288 d_fprintf(stderr
, "failed to call wbcRemoveGidMapping: %s\n",
1289 wbcErrorString(wbc_status
));
1293 /* Display response */
1295 d_printf("Removed gid %u to sid %s mapping\n",
1296 (unsigned int)gid
, sid_str
);
1301 /* Convert sid to string */
1303 static bool wbinfo_lookupsid(const char *sid_str
)
1305 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1306 struct wbcDomainSid sid
;
1309 enum wbcSidType type
;
1311 /* Send off request */
1313 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1314 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1315 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1316 wbcErrorString(wbc_status
));
1320 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1321 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1322 d_fprintf(stderr
, "failed to call wbcLookupSid: %s\n",
1323 wbcErrorString(wbc_status
));
1327 /* Display response */
1329 if (type
== WBC_SID_NAME_DOMAIN
) {
1330 d_printf("%s %d\n", domain
, type
);
1332 d_printf("%s%c%s %d\n",
1333 domain
, winbind_separator(), name
, type
);
1336 wbcFreeMemory(domain
);
1337 wbcFreeMemory(name
);
1342 /* Convert sid to fullname */
1344 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1346 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1347 struct wbcDomainSid sid
;
1350 enum wbcSidType type
;
1352 /* Send off request */
1354 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1355 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1356 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1357 wbcErrorString(wbc_status
));
1361 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1362 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1363 d_fprintf(stderr
, "failed to call wbcGetDisplayName: %s\n",
1364 wbcErrorString(wbc_status
));
1368 /* Display response */
1370 d_printf("%s%c%s %d\n",
1371 domain
, winbind_separator(), name
, type
);
1373 wbcFreeMemory(domain
);
1374 wbcFreeMemory(name
);
1379 /* Lookup a list of RIDs */
1381 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1383 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1384 struct wbcDomainInfo
*dinfo
= NULL
;
1385 char *domain_name
= NULL
;
1386 const char **names
= NULL
;
1387 enum wbcSidType
*types
= NULL
;
1389 uint32_t *rids
= NULL
;
1392 TALLOC_CTX
*mem_ctx
= NULL
;
1395 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1396 domain
= get_winbind_domain();
1401 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1402 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1403 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1404 wbcErrorString(wbc_status
));
1408 mem_ctx
= talloc_new(NULL
);
1409 if (mem_ctx
== NULL
) {
1410 d_printf("talloc_new failed\n");
1418 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1422 rid
= smb_strtoul(ridstr
, NULL
, 10, &error
, SMB_STR_STANDARD
);
1424 d_printf("failed to convert rid\n");
1427 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1429 d_printf("talloc_realloc failed\n");
1431 rids
[num_rids
] = rid
;
1436 d_printf("no rids\n");
1440 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
1441 &p
, &names
, &types
);
1442 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1443 d_printf("winbind_lookup_rids failed: %s\n",
1444 wbcErrorString(wbc_status
));
1448 domain_name
= discard_const_p(char, p
);
1449 d_printf("Domain: %s\n", domain_name
);
1451 for (i
=0; i
<num_rids
; i
++) {
1452 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1453 wbcSidTypeString(types
[i
]));
1458 wbcFreeMemory(dinfo
);
1459 wbcFreeMemory(domain_name
);
1460 wbcFreeMemory(names
);
1461 wbcFreeMemory(types
);
1462 TALLOC_FREE(mem_ctx
);
1466 static bool wbinfo_lookup_sids(const char *arg
)
1468 char sidstr
[WBC_SID_STRING_BUFLEN
];
1469 struct wbcDomainSid
*sids
;
1470 struct wbcDomainInfo
*domains
;
1471 struct wbcTranslatedName
*names
;
1482 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1483 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1486 d_fprintf(stderr
, "talloc failed\n");
1489 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1490 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1491 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1492 sidstr
, wbcErrorString(wbc_status
));
1499 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1501 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1502 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1503 wbcErrorString(wbc_status
));
1508 for (i
=0; i
<num_sids
; i
++) {
1509 const char *domain
= NULL
;
1511 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1513 if (names
[i
].domain_index
>= num_domains
) {
1515 } else if (names
[i
].domain_index
< 0) {
1518 domain
= domains
[names
[i
].domain_index
].short_name
;
1521 if (names
[i
].type
== WBC_SID_NAME_DOMAIN
) {
1522 d_printf("%s -> %s %d\n", sidstr
,
1526 d_printf("%s -> %s%c%s %d\n", sidstr
,
1528 winbind_separator(),
1529 names
[i
].name
, names
[i
].type
);
1532 wbcFreeMemory(names
);
1533 wbcFreeMemory(domains
);
1537 /* Convert string to sid */
1539 static bool wbinfo_lookupname(const char *full_name
)
1541 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1542 struct wbcDomainSid sid
;
1543 char sid_str
[WBC_SID_STRING_BUFLEN
];
1544 enum wbcSidType type
;
1545 fstring domain_name
;
1546 fstring account_name
;
1548 /* Send off request */
1550 parse_wbinfo_domain_user(full_name
, domain_name
,
1553 wbc_status
= wbcLookupName(domain_name
, account_name
,
1555 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1556 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1557 wbcErrorString(wbc_status
));
1561 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1563 /* Display response */
1565 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1570 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1572 const char *username
)
1575 char buf
[1024] = {0};
1578 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1583 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1588 prompt
= talloc_asprintf_append(prompt
, "password: ");
1593 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1594 TALLOC_FREE(prompt
);
1599 return talloc_strdup(mem_ctx
, buf
);
1602 /* Authenticate a user with a plaintext password */
1604 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1606 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1609 char *password
= NULL
;
1611 char *local_cctype
= NULL
;
1613 struct wbcLogonUserParams params
;
1614 struct wbcLogonUserInfo
*info
;
1615 struct wbcAuthErrorInfo
*error
;
1616 struct wbcUserPasswordPolicyInfo
*policy
;
1617 TALLOC_CTX
*frame
= talloc_tos();
1619 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1623 if ((p
= strchr(s
, '%')) != NULL
) {
1626 password
= talloc_strdup(frame
, p
);
1628 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1631 local_cctype
= talloc_strdup(frame
, cctype
);
1637 params
.username
= name
;
1638 params
.password
= password
;
1639 params
.num_blobs
= 0;
1640 params
.blobs
= NULL
;
1642 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1648 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1649 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1650 wbcErrorString(wbc_status
));
1654 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1660 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1661 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1662 wbcErrorString(wbc_status
));
1666 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1670 (uint8_t *)local_cctype
,
1672 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1673 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1674 wbcErrorString(wbc_status
));
1678 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1680 d_printf("plaintext kerberos password authentication for [%s] %s "
1681 "(requesting cctype: %s)\n",
1682 name
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1687 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1688 "error message was: %s\n",
1689 params
.username
, error
->nt_string
,
1691 error
->display_string
);
1694 if (WBC_ERROR_IS_OK(wbc_status
)) {
1695 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1696 if (info
&& info
->info
&& info
->info
->user_flags
&
1697 NETLOGON_CACHED_ACCOUNT
) {
1698 d_printf("user_flgs: "
1699 "NETLOGON_CACHED_ACCOUNT\n");
1705 for (i
=0; i
< info
->num_blobs
; i
++) {
1706 if (strequal(info
->blobs
[i
].name
,
1708 d_printf("credentials were put "
1711 info
->blobs
[i
].blob
.data
);
1716 d_printf("no credentials cached\n");
1721 wbcFreeMemory(params
.blobs
);
1723 return WBC_ERROR_IS_OK(wbc_status
);
1726 /* Authenticate a user with a plaintext password */
1728 static bool wbinfo_auth(char *username
)
1730 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1733 char *password
= NULL
;
1735 TALLOC_CTX
*frame
= talloc_tos();
1737 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1741 if ((p
= strchr(s
, '%')) != NULL
) {
1744 password
= talloc_strdup(frame
, p
);
1746 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1751 wbc_status
= wbcAuthenticateUser(name
, password
);
1753 d_printf("plaintext password authentication %s\n",
1754 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1757 if (response
.data
.auth
.nt_status
)
1759 "error code was %s (0x%x)\nerror message was: %s\n",
1760 response
.data
.auth
.nt_status_string
,
1761 response
.data
.auth
.nt_status
,
1762 response
.data
.auth
.error_string
);
1765 return WBC_ERROR_IS_OK(wbc_status
);
1768 /* Authenticate a user with a challenge/response */
1770 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1772 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1773 struct wbcAuthUserParams params
;
1774 struct wbcAuthUserInfo
*info
= NULL
;
1775 struct wbcAuthErrorInfo
*err
= NULL
;
1776 DATA_BLOB lm
= data_blob_null
;
1777 DATA_BLOB nt
= data_blob_null
;
1779 fstring name_domain
;
1782 TALLOC_CTX
*frame
= talloc_tos();
1784 p
= strchr(username
, '%');
1788 pass
= talloc_strdup(frame
, p
+ 1);
1790 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1793 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1795 params
.account_name
= name_user
;
1796 params
.domain_name
= name_domain
;
1797 params
.workstation_name
= NULL
;
1800 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1801 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1803 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1805 generate_random_buffer(params
.password
.response
.challenge
, 8);
1808 DATA_BLOB server_chal
;
1809 DATA_BLOB names_blob
;
1810 const char *netbios_name
= NULL
;
1811 const char *domain
= NULL
;
1813 netbios_name
= get_winbind_netbios_name(),
1814 domain
= get_winbind_domain();
1815 if (domain
== NULL
) {
1816 d_fprintf(stderr
, "Failed to get domain from winbindd\n");
1820 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1822 /* Pretend this is a login to 'us', for blob purposes */
1823 names_blob
= NTLMv2_generate_names_blob(NULL
,
1828 !SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1831 &lm
, &nt
, NULL
, NULL
)) {
1832 data_blob_free(&names_blob
);
1833 data_blob_free(&server_chal
);
1837 data_blob_free(&names_blob
);
1838 data_blob_free(&server_chal
);
1843 lm
= data_blob(NULL
, 24);
1844 ok
= SMBencrypt(pass
,
1845 params
.password
.response
.challenge
,
1848 data_blob_free(&lm
);
1851 nt
= data_blob(NULL
, 24);
1852 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1856 params
.password
.response
.nt_length
= nt
.length
;
1857 params
.password
.response
.nt_data
= nt
.data
;
1858 params
.password
.response
.lm_length
= lm
.length
;
1859 params
.password
.response
.lm_data
= lm
.data
;
1861 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1863 /* Display response */
1865 d_printf("challenge/response password authentication %s\n",
1866 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1868 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1870 "wbcAuthenticateUserEx(%s%c%s): error code was "
1871 "%s (0x%x, authoritative=%"PRIu8
")\n"
1872 "error message was: %s\n",
1874 winbind_separator(),
1879 err
->display_string
);
1881 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1882 wbcFreeMemory(info
);
1885 data_blob_free(&nt
);
1886 data_blob_free(&lm
);
1888 return WBC_ERROR_IS_OK(wbc_status
);
1891 /* Authenticate a user with a plaintext password */
1893 static bool wbinfo_pam_logon(char *username
, bool verbose
)
1895 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1896 struct wbcLogonUserParams params
;
1897 struct wbcLogonUserInfo
*info
= NULL
;
1898 struct wbcAuthErrorInfo
*error
= NULL
;
1901 TALLOC_CTX
*frame
= talloc_tos();
1905 ZERO_STRUCT(params
);
1907 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1911 if ((p
= strchr(s
, '%')) != NULL
) {
1914 params
.password
= talloc_strdup(frame
, p
);
1916 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1918 params
.username
= s
;
1920 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1922 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1924 (uint8_t *)&flags
, sizeof(flags
));
1925 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1926 d_printf("wbcAddNamedBlob failed: %s\n",
1927 wbcErrorString(wbc_status
));
1933 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1935 (uint8_t *)&uid
, sizeof(uid
));
1936 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1937 d_printf("wbcAddNamedBlob failed: %s\n",
1938 wbcErrorString(wbc_status
));
1942 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, NULL
);
1944 if (verbose
&& (info
!= NULL
)) {
1945 struct wbcAuthUserInfo
*i
= info
->info
;
1948 if (i
->account_name
!= NULL
) {
1949 d_printf("account_name: %s\n", i
->account_name
);
1951 if (i
->user_principal
!= NULL
) {
1952 d_printf("user_principal: %s\n", i
->user_principal
);
1954 if (i
->full_name
!= NULL
) {
1955 d_printf("full_name: %s\n", i
->full_name
);
1957 if (i
->domain_name
!= NULL
) {
1958 d_printf("domain_name: %s\n", i
->domain_name
);
1960 if (i
->dns_domain_name
!= NULL
) {
1961 d_printf("dns_domain_name: %s\n", i
->dns_domain_name
);
1963 if (i
->logon_server
!= NULL
) {
1964 d_printf("logon_server: %s\n", i
->logon_server
);
1966 if (i
->logon_script
!= NULL
) {
1967 d_printf("logon_script: %s\n", i
->logon_script
);
1969 if (i
->profile_path
!= NULL
) {
1970 d_printf("profile_path: %s\n", i
->profile_path
);
1972 if (i
->home_directory
!= NULL
) {
1973 d_printf("home_directory: %s\n", i
->home_directory
);
1975 if (i
->home_drive
!= NULL
) {
1976 d_printf("home_drive: %s\n", i
->home_drive
);
1981 for (j
=0; j
<i
->num_sids
; j
++) {
1982 char buf
[WBC_SID_STRING_BUFLEN
];
1983 wbcSidToStringBuf(&i
->sids
[j
].sid
, buf
, sizeof(buf
));
1984 d_printf(" %s", buf
);
1988 wbcFreeMemory(info
);
1992 wbcFreeMemory(params
.blobs
);
1994 d_printf("plaintext password authentication %s\n",
1995 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1997 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
1999 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2000 "error message was: %s\n",
2003 (int)error
->nt_status
,
2004 error
->display_string
);
2005 wbcFreeMemory(error
);
2007 return WBC_ERROR_IS_OK(wbc_status
);
2010 /* Save creds with winbind */
2012 static bool wbinfo_ccache_save(char *username
)
2014 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2017 char *password
= NULL
;
2019 TALLOC_CTX
*frame
= talloc_stackframe();
2021 s
= talloc_strdup(frame
, username
);
2030 password
= talloc_strdup(frame
, p
);
2032 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
2037 wbc_status
= wbcCredentialSave(name
, password
);
2039 d_printf("saving creds %s\n",
2040 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2044 return WBC_ERROR_IS_OK(wbc_status
);
2047 #ifdef WITH_FAKE_KASERVER
2048 /* Authenticate a user with a plaintext password and set a token */
2050 static bool wbinfo_klog(char *username
)
2052 struct winbindd_request request
;
2053 struct winbindd_response response
;
2057 /* Send off request */
2059 ZERO_STRUCT(request
);
2060 ZERO_STRUCT(response
);
2062 p
= strchr(username
, '%');
2066 fstrcpy(request
.data
.auth
.user
, username
);
2067 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
2070 fstrcpy(request
.data
.auth
.user
, username
);
2071 (void) samba_getpass("Password: ",
2072 request
.data
.auth
.pass
,
2073 sizeof(request
.data
.auth
.pass
),
2077 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
2079 result
= winbindd_request_response(NULL
, WINBINDD_PAM_AUTH
, &request
,
2082 /* Display response */
2084 d_printf("plaintext password authentication %s\n",
2085 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
2087 if (response
.data
.auth
.nt_status
)
2089 "error code was %s (0x%x)\nerror message was: %s\n",
2090 response
.data
.auth
.nt_status_string
,
2091 response
.data
.auth
.nt_status
,
2092 response
.data
.auth
.error_string
);
2094 if (result
!= NSS_STATUS_SUCCESS
)
2097 if (response
.extra_data
.data
== NULL
) {
2098 d_fprintf(stderr
, "Did not get token data\n");
2102 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
2103 d_fprintf(stderr
, "Could not set token\n");
2107 d_printf("Successfully created AFS token\n");
2111 static bool wbinfo_klog(char *username
)
2113 d_fprintf(stderr
, "No AFS support compiled in.\n");
2118 /* Print domain users */
2120 static bool print_domain_users(const char *domain
)
2122 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2124 uint32_t num_users
= 0;
2125 const char **users
= NULL
;
2127 /* Send request to winbind daemon */
2129 if (domain
== NULL
) {
2130 domain
= get_winbind_domain();
2132 /* '.' is the special sign for our own domain */
2133 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2134 domain
= get_winbind_domain();
2135 /* '*' is the special sign for all domains */
2136 } else if (strcmp(domain
, "*") == 0) {
2141 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
2142 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2146 for (i
=0; i
< num_users
; i
++) {
2147 d_printf("%s\n", users
[i
]);
2150 wbcFreeMemory(users
);
2155 /* Print domain groups */
2157 static bool print_domain_groups(const char *domain
)
2159 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2161 uint32_t num_groups
= 0;
2162 const char **groups
= NULL
;
2164 /* Send request to winbind daemon */
2166 if (domain
== NULL
) {
2167 domain
= get_winbind_domain();
2169 /* '.' is the special sign for our own domain */
2170 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2171 domain
= get_winbind_domain();
2172 /* '*' is the special sign for all domains */
2173 } else if (strcmp(domain
, "*") == 0) {
2178 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
2179 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2180 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
2181 wbcErrorString(wbc_status
));
2185 for (i
=0; i
< num_groups
; i
++) {
2186 d_printf("%s\n", groups
[i
]);
2189 wbcFreeMemory(groups
);
2194 /* Set the authorised user for winbindd access in secrets.tdb */
2196 static bool wbinfo_set_auth_user(char *username
)
2198 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2199 "See 'net help setauthuser' for details.\n");
2203 static void wbinfo_get_auth_user(void)
2205 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2206 "See 'net help getauthuser' for details.\n");
2209 static bool wbinfo_ping(void)
2213 wbc_status
= wbcPing();
2215 /* Display response */
2217 d_printf("Ping to winbindd %s\n",
2218 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2220 return WBC_ERROR_IS_OK(wbc_status
);
2223 static bool wbinfo_change_user_password(const char *username
)
2226 char *old_password
= NULL
;
2227 char *new_password
= NULL
;
2228 TALLOC_CTX
*frame
= talloc_tos();
2230 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2231 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2233 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2235 /* Display response */
2237 d_printf("Password change for user %s %s\n", username
,
2238 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2240 return WBC_ERROR_IS_OK(wbc_status
);
2246 OPT_SET_AUTH_USER
= 1000,
2259 OPT_SET_UID_MAPPING
,
2260 OPT_SET_GID_MAPPING
,
2261 OPT_REMOVE_UID_MAPPING
,
2262 OPT_REMOVE_GID_MAPPING
,
2266 OPT_LIST_ALL_DOMAINS
,
2267 OPT_LIST_OWN_DOMAIN
,
2274 OPT_CHANGE_USER_PASSWORD
,
2276 OPT_SID_TO_FULLNAME
,
2287 int main(int argc
, const char **argv
, char **envp
)
2290 TALLOC_CTX
*frame
= talloc_stackframe();
2292 static char *string_arg
;
2293 char *string_subarg
= NULL
;
2294 static char *opt_domain_name
;
2296 int int_subarg
= -1;
2298 bool verbose
= false;
2299 bool use_ntlmv2
= true;
2300 bool use_lanman
= false;
2301 char *logoff_user
= getenv("USER");
2302 int logoff_uid
= geteuid();
2303 const char *opt_krb5ccname
= "FILE";
2305 struct poptOption long_options
[] = {
2308 /* longName, shortName, argInfo, argPtr, value, descrip,
2312 .longName
= "domain-users",
2314 .argInfo
= POPT_ARG_NONE
,
2316 .descrip
= "Lists all domain users",
2317 .argDescrip
= "domain"
2320 .longName
= "domain-groups",
2322 .argInfo
= POPT_ARG_NONE
,
2324 .descrip
= "Lists all domain groups",
2325 .argDescrip
= "domain"
2328 .longName
= "WINS-by-name",
2330 .argInfo
= POPT_ARG_STRING
,
2333 .descrip
= "Converts NetBIOS name to IP",
2334 .argDescrip
= "NETBIOS-NAME"
2337 .longName
= "WINS-by-ip",
2339 .argInfo
= POPT_ARG_STRING
,
2342 .descrip
= "Converts IP address to NetBIOS name",
2346 .longName
= "name-to-sid",
2348 .argInfo
= POPT_ARG_STRING
,
2351 .descrip
= "Converts name to sid",
2352 .argDescrip
= "NAME"
2355 .longName
= "sid-to-name",
2357 .argInfo
= POPT_ARG_STRING
,
2360 .descrip
= "Converts sid to name",
2364 .longName
= "sid-to-fullname",
2365 .argInfo
= POPT_ARG_STRING
,
2367 .val
= OPT_SID_TO_FULLNAME
,
2368 .descrip
= "Converts sid to fullname",
2372 .longName
= "lookup-rids",
2374 .argInfo
= POPT_ARG_STRING
,
2377 .descrip
= "Converts RIDs to names",
2378 .argDescrip
= "RIDs"
2381 .longName
= "lookup-sids",
2382 .argInfo
= POPT_ARG_STRING
,
2384 .val
= OPT_LOOKUP_SIDS
,
2385 .descrip
= "Converts SIDs to types and names",
2386 .argDescrip
= "Sid-List"
2389 .longName
= "uid-to-sid",
2391 .argInfo
= POPT_ARG_INT
,
2394 .descrip
= "Converts uid to sid",
2398 .longName
= "gid-to-sid",
2400 .argInfo
= POPT_ARG_INT
,
2403 .descrip
= "Converts gid to sid",
2407 .longName
= "sid-to-uid",
2409 .argInfo
= POPT_ARG_STRING
,
2412 .descrip
= "Converts sid to uid",
2416 .longName
= "sid-to-gid",
2418 .argInfo
= POPT_ARG_STRING
,
2421 .descrip
= "Converts sid to gid",
2425 .longName
= "allocate-uid",
2426 .argInfo
= POPT_ARG_NONE
,
2427 .val
= OPT_ALLOCATE_UID
,
2428 .descrip
= "Get a new UID out of idmap"
2431 .longName
= "allocate-gid",
2432 .argInfo
= POPT_ARG_NONE
,
2433 .val
= OPT_ALLOCATE_GID
,
2434 .descrip
= "Get a new GID out of idmap"
2437 .longName
= "set-uid-mapping",
2438 .argInfo
= POPT_ARG_STRING
,
2440 .val
= OPT_SET_UID_MAPPING
,
2441 .descrip
= "Create or modify uid to sid mapping in "
2443 .argDescrip
= "UID,SID"
2446 .longName
= "set-gid-mapping",
2447 .argInfo
= POPT_ARG_STRING
,
2449 .val
= OPT_SET_GID_MAPPING
,
2450 .descrip
= "Create or modify gid to sid mapping in "
2452 .argDescrip
= "GID,SID"
2455 .longName
= "remove-uid-mapping",
2456 .argInfo
= POPT_ARG_STRING
,
2458 .val
= OPT_REMOVE_UID_MAPPING
,
2459 .descrip
= "Remove uid to sid mapping in idmap",
2460 .argDescrip
= "UID,SID"
2463 .longName
= "remove-gid-mapping",
2464 .argInfo
= POPT_ARG_STRING
,
2466 .val
= OPT_REMOVE_GID_MAPPING
,
2467 .descrip
= "Remove gid to sid mapping in idmap",
2468 .argDescrip
= "GID,SID",
2471 .longName
= "sids-to-unix-ids",
2472 .argInfo
= POPT_ARG_STRING
,
2474 .val
= OPT_SIDS_TO_XIDS
,
2475 .descrip
= "Translate SIDs to Unix IDs",
2476 .argDescrip
= "Sid-List",
2479 .longName
= "unix-ids-to-sids",
2480 .argInfo
= POPT_ARG_STRING
,
2482 .val
= OPT_XIDS_TO_SIDS
,
2483 .descrip
= "Translate Unix IDs to SIDs",
2484 .argDescrip
= "ID-List (u<num> g<num>)",
2487 .longName
= "check-secret",
2489 .argInfo
= POPT_ARG_NONE
,
2491 .descrip
= "Check shared secret",
2494 .longName
= "change-secret",
2496 .argInfo
= POPT_ARG_NONE
,
2498 .descrip
= "Change shared secret",
2501 .longName
= "ping-dc",
2503 .argInfo
= POPT_ARG_NONE
,
2505 .descrip
= "Check the NETLOGON connection",
2508 .longName
= "trusted-domains",
2510 .argInfo
= POPT_ARG_NONE
,
2512 .descrip
= "List trusted domains",
2515 .longName
= "all-domains",
2516 .argInfo
= POPT_ARG_NONE
,
2517 .val
= OPT_LIST_ALL_DOMAINS
,
2518 .descrip
= "List all domains (trusted and own "
2522 .longName
= "own-domain",
2523 .argInfo
= POPT_ARG_NONE
,
2524 .val
= OPT_LIST_OWN_DOMAIN
,
2525 .descrip
= "List own domain",
2528 .longName
= "sequence",
2529 .argInfo
= POPT_ARG_NONE
,
2530 .val
= OPT_SEQUENCE
,
2531 .descrip
= "Deprecated command, see --online-status",
2534 .longName
= "online-status",
2535 .argInfo
= POPT_ARG_NONE
,
2536 .val
= OPT_ONLINESTATUS
,
2537 .descrip
= "Show whether domains maintain an active "
2541 .longName
= "domain-info",
2543 .argInfo
= POPT_ARG_STRING
,
2546 .descrip
= "Show most of the info we have about the "
2550 .longName
= "user-info",
2552 .argInfo
= POPT_ARG_STRING
,
2555 .descrip
= "Get user info",
2556 .argDescrip
= "USER",
2559 .longName
= "uid-info",
2560 .argInfo
= POPT_ARG_INT
,
2562 .val
= OPT_UID_INFO
,
2563 .descrip
= "Get user info from uid",
2564 .argDescrip
= "UID",
2567 .longName
= "group-info",
2568 .argInfo
= POPT_ARG_STRING
,
2570 .val
= OPT_GROUP_INFO
,
2571 .descrip
= "Get group info",
2572 .argDescrip
= "GROUP",
2575 .longName
= "user-sidinfo",
2576 .argInfo
= POPT_ARG_STRING
,
2578 .val
= OPT_USER_SIDINFO
,
2579 .descrip
= "Get user info from sid",
2580 .argDescrip
= "SID",
2583 .longName
= "gid-info",
2584 .argInfo
= POPT_ARG_INT
,
2586 .val
= OPT_GID_INFO
,
2587 .descrip
= "Get group info from gid",
2588 .argDescrip
= "GID",
2591 .longName
= "user-groups",
2593 .argInfo
= POPT_ARG_STRING
,
2596 .descrip
= "Get user groups",
2597 .argDescrip
= "USER",
2600 .longName
= "user-domgroups",
2601 .argInfo
= POPT_ARG_STRING
,
2603 .val
= OPT_USERDOMGROUPS
,
2604 .descrip
= "Get user domain groups",
2605 .argDescrip
= "SID",
2608 .longName
= "sid-aliases",
2609 .argInfo
= POPT_ARG_STRING
,
2611 .val
= OPT_SIDALIASES
,
2612 .descrip
= "Get sid aliases",
2613 .argDescrip
= "SID",
2616 .longName
= "user-sids",
2617 .argInfo
= POPT_ARG_STRING
,
2619 .val
= OPT_USERSIDS
,
2620 .descrip
= "Get user group sids for user SID",
2621 .argDescrip
= "SID",
2624 .longName
= "authenticate",
2626 .argInfo
= POPT_ARG_STRING
,
2629 .descrip
= "authenticate user",
2630 .argDescrip
= "user%password",
2633 .longName
= "pam-logon",
2634 .argInfo
= POPT_ARG_STRING
,
2636 .val
= OPT_PAM_LOGON
,
2637 .descrip
= "do a pam logon equivalent",
2638 .argDescrip
= "user%password",
2641 .longName
= "logoff",
2642 .argInfo
= POPT_ARG_NONE
,
2644 .descrip
= "log off user",
2645 .argDescrip
= "uid",
2648 .longName
= "logoff-user",
2649 .argInfo
= POPT_ARG_STRING
,
2650 .arg
= &logoff_user
,
2651 .val
= OPT_LOGOFF_USER
,
2652 .descrip
= "username to log off"
2655 .longName
= "logoff-uid",
2656 .argInfo
= POPT_ARG_INT
,
2658 .val
= OPT_LOGOFF_UID
,
2659 .descrip
= "uid to log off",
2662 .longName
= "set-auth-user",
2663 .argInfo
= POPT_ARG_STRING
,
2665 .val
= OPT_SET_AUTH_USER
,
2666 .descrip
= "Store user and password used by "
2667 "winbindd (root only)",
2668 .argDescrip
= "user%password",
2671 .longName
= "ccache-save",
2673 .argInfo
= POPT_ARG_STRING
,
2675 .val
= OPT_CCACHE_SAVE
,
2676 .descrip
= "Store user and password for ccache "
2678 .argDescrip
= "user%password",
2681 .longName
= "getdcname",
2682 .argInfo
= POPT_ARG_STRING
,
2684 .val
= OPT_GETDCNAME
,
2685 .descrip
= "Get a DC name for a foreign domain",
2686 .argDescrip
= "domainname",
2689 .longName
= "dsgetdcname",
2690 .argInfo
= POPT_ARG_STRING
,
2692 .val
= OPT_DSGETDCNAME
,
2693 .descrip
= "Find a DC for a domain",
2694 .argDescrip
= "domainname",
2697 .longName
= "dc-info",
2698 .argInfo
= POPT_ARG_STRING
,
2701 .descrip
= "Find the currently known DCs",
2702 .argDescrip
= "domainname",
2705 .longName
= "get-auth-user",
2706 .argInfo
= POPT_ARG_NONE
,
2707 .val
= OPT_GET_AUTH_USER
,
2708 .descrip
= "Retrieve user and password used by "
2709 "winbindd (root only)",
2714 .argInfo
= POPT_ARG_NONE
,
2717 .descrip
= "Ping winbindd to see if it is alive",
2720 .longName
= "domain",
2722 .argInfo
= POPT_ARG_STRING
,
2723 .arg
= &opt_domain_name
,
2724 .val
= OPT_DOMAIN_NAME
,
2725 .descrip
= "Define to the domain to restrict "
2727 .argDescrip
= "domain",
2729 #ifdef WITH_FAKE_KASERVER
2733 .argInfo
= POPT_ARG_STRING
,
2736 .descrip
= "set an AFS token from winbind",
2737 .argDescrip
= "user%password",
2742 .longName
= "krb5auth",
2744 .argInfo
= POPT_ARG_STRING
,
2747 .descrip
= "authenticate user using Kerberos",
2748 .argDescrip
= "user%password",
2750 /* destroys wbinfo --help output */
2751 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2754 .longName
= "krb5ccname",
2755 .argInfo
= POPT_ARG_STRING
,
2756 .arg
= &opt_krb5ccname
,
2757 .val
= OPT_KRB5CCNAME
,
2758 .descrip
= "authenticate user using Kerberos and "
2759 "specific credential cache type",
2760 .argDescrip
= "krb5ccname",
2764 .longName
= "separator",
2765 .argInfo
= POPT_ARG_NONE
,
2766 .val
= OPT_SEPARATOR
,
2767 .descrip
= "Get the active winbind separator",
2770 .longName
= "verbose",
2771 .argInfo
= POPT_ARG_NONE
,
2773 .descrip
= "Print additional information per command",
2776 .longName
= "change-user-password",
2777 .argInfo
= POPT_ARG_STRING
,
2779 .val
= OPT_CHANGE_USER_PASSWORD
,
2780 .descrip
= "Change the password for a user",
2783 .longName
= "ntlmv1",
2784 .argInfo
= POPT_ARG_NONE
,
2786 .descrip
= "Use NTLMv1 cryptography for user authentication",
2789 .longName
= "ntlmv2",
2790 .argInfo
= POPT_ARG_NONE
,
2792 .descrip
= "Use NTLMv2 cryptography for user authentication",
2795 .longName
= "lanman",
2796 .argInfo
= POPT_ARG_NONE
,
2798 .descrip
= "Use lanman cryptography for user authentication",
2804 /* Samba client initialisation */
2810 pc
= poptGetContext("wbinfo", argc
, argv
,
2813 /* Parse command line options */
2816 poptPrintHelp(pc
, stderr
, 0);
2820 while((opt
= poptGetNextOpt(pc
)) != -1) {
2821 /* get the generic configuration parameters like --domain */
2835 poptFreeContext(pc
);
2837 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2838 POPT_CONTEXT_KEEP_FIRST
);
2840 while((opt
= poptGetNextOpt(pc
)) != -1) {
2843 if (!print_domain_users(opt_domain_name
)) {
2845 "Error looking up domain users\n");
2850 if (!print_domain_groups(opt_domain_name
)) {
2852 "Error looking up domain groups\n");
2857 if (!wbinfo_lookupsid(string_arg
)) {
2859 "Could not lookup sid %s\n",
2864 case OPT_SID_TO_FULLNAME
:
2865 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2866 d_fprintf(stderr
, "Could not lookup sid %s\n",
2872 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2873 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2878 case OPT_LOOKUP_SIDS
:
2879 if (!wbinfo_lookup_sids(string_arg
)) {
2880 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2886 if (!wbinfo_lookupname(string_arg
)) {
2887 d_fprintf(stderr
, "Could not lookup name %s\n",
2893 if (!wbinfo_wins_byname(string_arg
)) {
2895 "Could not lookup WINS by name %s\n",
2901 if (!wbinfo_wins_byip(string_arg
)) {
2903 "Could not lookup WINS by IP %s\n",
2909 if (!wbinfo_uid_to_sid(int_arg
)) {
2911 "Could not convert uid %d to sid\n",
2917 if (!wbinfo_gid_to_sid(int_arg
)) {
2919 "Could not convert gid %d to sid\n",
2925 if (!wbinfo_sid_to_uid(string_arg
)) {
2927 "Could not convert sid %s to uid\n",
2933 if (!wbinfo_sid_to_gid(string_arg
)) {
2935 "Could not convert sid %s to gid\n",
2940 case OPT_ALLOCATE_UID
:
2941 if (!wbinfo_allocate_uid()) {
2942 d_fprintf(stderr
, "Could not allocate a uid\n");
2946 case OPT_ALLOCATE_GID
:
2947 if (!wbinfo_allocate_gid()) {
2948 d_fprintf(stderr
, "Could not allocate a gid\n");
2952 case OPT_SET_UID_MAPPING
:
2953 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2955 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2957 d_fprintf(stderr
, "Could not create or modify "
2958 "uid to sid mapping\n");
2962 case OPT_SET_GID_MAPPING
:
2963 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2965 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2967 d_fprintf(stderr
, "Could not create or modify "
2968 "gid to sid mapping\n");
2972 case OPT_REMOVE_UID_MAPPING
:
2973 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2975 !wbinfo_remove_uid_mapping(int_subarg
,
2978 d_fprintf(stderr
, "Could not remove uid to sid "
2983 case OPT_REMOVE_GID_MAPPING
:
2984 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2986 !wbinfo_remove_gid_mapping(int_subarg
,
2989 d_fprintf(stderr
, "Could not remove gid to sid "
2994 case OPT_SIDS_TO_XIDS
:
2995 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
2996 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
3001 case OPT_XIDS_TO_SIDS
:
3002 if (!wbinfo_xids_to_sids(string_arg
)) {
3003 d_fprintf(stderr
, "wbinfo_xids_to_sids "
3009 if (!wbinfo_check_secret(opt_domain_name
)) {
3010 d_fprintf(stderr
, "Could not check secret\n");
3015 if (!wbinfo_change_secret(opt_domain_name
)) {
3016 d_fprintf(stderr
, "Could not change secret\n");
3021 if (!wbinfo_ping_dc(opt_domain_name
)) {
3026 if (!wbinfo_list_domains(false, verbose
)) {
3028 "Could not list trusted domains\n");
3033 if (!wbinfo_show_sequence(opt_domain_name
)) {
3035 "Could not show sequence numbers\n");
3039 case OPT_ONLINESTATUS
:
3040 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
3042 "Could not show online-status\n");
3047 if (!wbinfo_domain_info(string_arg
)) {
3049 "Could not get domain info\n");
3054 if (!wbinfo_get_userinfo(string_arg
)) {
3056 "Could not get info for user %s\n",
3061 case OPT_USER_SIDINFO
:
3062 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
3064 "Could not get info for user "
3065 "sid %s\n", string_arg
);
3070 if ( !wbinfo_get_uidinfo(int_arg
)) {
3071 d_fprintf(stderr
, "Could not get info for uid "
3076 case OPT_GROUP_INFO
:
3077 if ( !wbinfo_get_groupinfo(string_arg
)) {
3078 d_fprintf(stderr
, "Could not get info for "
3079 "group %s\n", string_arg
);
3084 if ( !wbinfo_get_gidinfo(int_arg
)) {
3085 d_fprintf(stderr
, "Could not get info for gid "
3091 if (!wbinfo_get_usergroups(string_arg
)) {
3093 "Could not get groups for user %s\n",
3099 if (!wbinfo_get_usersids(string_arg
)) {
3100 d_fprintf(stderr
, "Could not get group SIDs "
3101 "for user SID %s\n",
3106 case OPT_USERDOMGROUPS
:
3107 if (!wbinfo_get_userdomgroups(string_arg
)) {
3108 d_fprintf(stderr
, "Could not get user's domain "
3109 "groups for user SID %s\n",
3114 case OPT_SIDALIASES
:
3115 if (!wbinfo_get_sidaliases(opt_domain_name
,
3117 d_fprintf(stderr
, "Could not get sid aliases "
3118 "for user SID %s\n", string_arg
);
3123 bool got_error
= false;
3125 if (!wbinfo_auth(string_arg
)) {
3127 "Could not authenticate user "
3128 "%s with plaintext "
3129 "password\n", string_arg
);
3133 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
3136 "Could not authenticate user "
3137 "%s with challenge/response\n",
3147 if (!wbinfo_pam_logon(string_arg
, verbose
)) {
3148 d_fprintf(stderr
, "pam_logon failed for %s\n",
3157 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
3159 d_printf("Logoff %s (%d): %s\n", logoff_user
,
3160 logoff_uid
, wbcErrorString(wbc_status
));
3164 uint32_t flags
= WBFLAG_PAM_KRB5
|
3165 WBFLAG_PAM_CACHED_LOGIN
|
3166 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
3167 WBFLAG_PAM_INFO3_TEXT
|
3168 WBFLAG_PAM_CONTACT_TRUSTDOM
;
3170 if (!wbinfo_auth_krb5(string_arg
, opt_krb5ccname
,
3173 "Could not authenticate user "
3174 "[%s] with Kerberos "
3175 "(ccache: %s)\n", string_arg
,
3182 if (!wbinfo_klog(string_arg
)) {
3183 d_fprintf(stderr
, "Could not klog user\n");
3188 if (!wbinfo_ping()) {
3189 d_fprintf(stderr
, "could not ping winbindd!\n");
3193 case OPT_SET_AUTH_USER
:
3194 if (!wbinfo_set_auth_user(string_arg
)) {
3198 case OPT_GET_AUTH_USER
:
3199 wbinfo_get_auth_user();
3202 case OPT_CCACHE_SAVE
:
3203 if (!wbinfo_ccache_save(string_arg
)) {
3208 if (!wbinfo_getdcname(string_arg
)) {
3212 case OPT_DSGETDCNAME
:
3213 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
3218 if (!wbinfo_dc_info(string_arg
)) {
3222 case OPT_SEPARATOR
: {
3223 const char sep
= winbind_separator();
3227 d_printf("%c\n", sep
);
3230 case OPT_LIST_ALL_DOMAINS
:
3231 if (!wbinfo_list_domains(true, verbose
)) {
3235 case OPT_LIST_OWN_DOMAIN
:
3236 if (!wbinfo_list_own_domain()) {
3240 case OPT_CHANGE_USER_PASSWORD
:
3241 if (!wbinfo_change_user_password(string_arg
)) {
3243 "Could not change user password "
3244 "for user %s\n", string_arg
);
3249 /* generic configuration options */
3250 case OPT_DOMAIN_NAME
:
3255 case OPT_LOGOFF_USER
:
3256 case OPT_LOGOFF_UID
:
3257 case OPT_KRB5CCNAME
:
3260 d_fprintf(stderr
, "Invalid option\n");
3261 poptPrintHelp(pc
, stderr
, 0);
3273 poptFreeContext(pc
);