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/cmdline.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 wbcDomainSid dsid
;
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();
1399 wbc_status
= wbcStringToSid(domain
, &dsid
);
1400 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1401 struct wbcDomainInfo
*dinfo
= NULL
;
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
));
1411 wbcFreeMemory(dinfo
);
1414 mem_ctx
= talloc_new(NULL
);
1415 if (mem_ctx
== NULL
) {
1416 d_printf("talloc_new failed\n");
1424 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1428 rid
= smb_strtoul(ridstr
, NULL
, 10, &error
, SMB_STR_STANDARD
);
1430 d_printf("failed to convert rid\n");
1433 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1435 d_printf("talloc_realloc failed\n");
1437 rids
[num_rids
] = rid
;
1442 d_printf("no rids\n");
1446 wbc_status
= wbcLookupRids(
1447 &dsid
, num_rids
, rids
, &p
, &names
, &types
);
1448 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1449 d_printf("winbind_lookup_rids failed: %s\n",
1450 wbcErrorString(wbc_status
));
1454 domain_name
= discard_const_p(char, p
);
1455 d_printf("Domain: %s\n", domain_name
);
1457 for (i
=0; i
<num_rids
; i
++) {
1458 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1459 wbcSidTypeString(types
[i
]));
1464 wbcFreeMemory(domain_name
);
1465 wbcFreeMemory(names
);
1466 wbcFreeMemory(types
);
1467 TALLOC_FREE(mem_ctx
);
1471 static bool wbinfo_lookup_sids(const char *arg
)
1473 char sidstr
[WBC_SID_STRING_BUFLEN
];
1474 struct wbcDomainSid
*sids
;
1475 struct wbcDomainInfo
*domains
;
1476 struct wbcTranslatedName
*names
;
1487 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1488 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1491 d_fprintf(stderr
, "talloc failed\n");
1494 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1495 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1496 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1497 sidstr
, wbcErrorString(wbc_status
));
1504 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1506 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1507 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1508 wbcErrorString(wbc_status
));
1513 for (i
=0; i
<num_sids
; i
++) {
1514 const char *domain
= NULL
;
1516 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1518 if (names
[i
].domain_index
>= num_domains
) {
1520 } else if (names
[i
].domain_index
< 0) {
1523 domain
= domains
[names
[i
].domain_index
].short_name
;
1526 if (names
[i
].type
== WBC_SID_NAME_DOMAIN
) {
1527 d_printf("%s -> %s %d\n", sidstr
,
1531 d_printf("%s -> %s%c%s %d\n", sidstr
,
1533 winbind_separator(),
1534 names
[i
].name
, names
[i
].type
);
1537 wbcFreeMemory(names
);
1538 wbcFreeMemory(domains
);
1542 /* Convert string to sid */
1544 static bool wbinfo_lookupname(const char *full_name
)
1546 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1547 struct wbcDomainSid sid
;
1548 char sid_str
[WBC_SID_STRING_BUFLEN
];
1549 enum wbcSidType type
;
1550 fstring domain_name
;
1551 fstring account_name
;
1553 /* Send off request */
1555 parse_wbinfo_domain_user(full_name
, domain_name
,
1558 wbc_status
= wbcLookupName(domain_name
, account_name
,
1560 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1561 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1562 wbcErrorString(wbc_status
));
1566 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1568 /* Display response */
1570 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1575 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1577 const char *username
)
1580 char buf
[1024] = {0};
1583 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1588 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1593 prompt
= talloc_asprintf_append(prompt
, "password: ");
1598 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1599 TALLOC_FREE(prompt
);
1604 return talloc_strdup(mem_ctx
, buf
);
1607 /* Authenticate a user with a plaintext password */
1609 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1611 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1614 char *password
= NULL
;
1616 char *local_cctype
= NULL
;
1618 struct wbcLogonUserParams params
;
1619 struct wbcLogonUserInfo
*info
;
1620 struct wbcAuthErrorInfo
*error
;
1621 struct wbcUserPasswordPolicyInfo
*policy
;
1622 TALLOC_CTX
*frame
= talloc_tos();
1624 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1628 if ((p
= strchr(s
, '%')) != NULL
) {
1631 password
= talloc_strdup(frame
, p
);
1633 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1636 local_cctype
= talloc_strdup(frame
, cctype
);
1642 params
.username
= name
;
1643 params
.password
= password
;
1644 params
.num_blobs
= 0;
1645 params
.blobs
= NULL
;
1647 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1653 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1654 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1655 wbcErrorString(wbc_status
));
1659 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1665 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1666 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1667 wbcErrorString(wbc_status
));
1671 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1675 (uint8_t *)local_cctype
,
1677 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1678 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1679 wbcErrorString(wbc_status
));
1683 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1685 d_printf("plaintext kerberos password authentication for [%s] %s "
1686 "(requesting cctype: %s)\n",
1687 name
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1692 "wbcLogonUser(%s): error code was %s (0x%x)\n"
1693 "error message was: %s\n",
1694 params
.username
, error
->nt_string
,
1696 error
->display_string
);
1699 if (WBC_ERROR_IS_OK(wbc_status
)) {
1700 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1701 if (info
&& info
->info
&& info
->info
->user_flags
&
1702 NETLOGON_CACHED_ACCOUNT
) {
1703 d_printf("user_flgs: "
1704 "NETLOGON_CACHED_ACCOUNT\n");
1710 for (i
=0; i
< info
->num_blobs
; i
++) {
1711 if (strequal(info
->blobs
[i
].name
,
1713 d_printf("credentials were put "
1716 info
->blobs
[i
].blob
.data
);
1721 d_printf("no credentials cached\n");
1726 wbcFreeMemory(params
.blobs
);
1728 return WBC_ERROR_IS_OK(wbc_status
);
1731 /* Authenticate a user with a plaintext password */
1733 static bool wbinfo_auth(char *username
)
1735 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1738 char *password
= NULL
;
1740 TALLOC_CTX
*frame
= talloc_tos();
1742 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1746 if ((p
= strchr(s
, '%')) != NULL
) {
1749 password
= talloc_strdup(frame
, p
);
1751 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1756 wbc_status
= wbcAuthenticateUser(name
, password
);
1758 d_printf("plaintext password authentication %s\n",
1759 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1762 if (response
.data
.auth
.nt_status
)
1764 "error code was %s (0x%x)\nerror message was: %s\n",
1765 response
.data
.auth
.nt_status_string
,
1766 response
.data
.auth
.nt_status
,
1767 response
.data
.auth
.error_string
);
1770 return WBC_ERROR_IS_OK(wbc_status
);
1773 /* Authenticate a user with a challenge/response */
1775 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1777 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1778 struct wbcAuthUserParams params
;
1779 struct wbcAuthUserInfo
*info
= NULL
;
1780 struct wbcAuthErrorInfo
*err
= NULL
;
1781 DATA_BLOB lm
= data_blob_null
;
1782 DATA_BLOB nt
= data_blob_null
;
1784 fstring name_domain
;
1787 TALLOC_CTX
*frame
= talloc_tos();
1789 p
= strchr(username
, '%');
1793 pass
= talloc_strdup(frame
, p
+ 1);
1795 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1798 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1800 params
.account_name
= name_user
;
1801 params
.domain_name
= name_domain
;
1802 params
.workstation_name
= NULL
;
1805 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1806 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1808 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1810 generate_random_buffer(params
.password
.response
.challenge
, 8);
1813 DATA_BLOB server_chal
;
1814 DATA_BLOB names_blob
;
1815 const char *netbios_name
= NULL
;
1816 const char *domain
= NULL
;
1818 netbios_name
= get_winbind_netbios_name(),
1819 domain
= get_winbind_domain();
1820 if (domain
== NULL
) {
1821 d_fprintf(stderr
, "Failed to get domain from winbindd\n");
1825 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1827 /* Pretend this is a login to 'us', for blob purposes */
1828 names_blob
= NTLMv2_generate_names_blob(NULL
,
1833 !SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1836 &lm
, &nt
, NULL
, NULL
)) {
1837 data_blob_free(&names_blob
);
1838 data_blob_free(&server_chal
);
1842 data_blob_free(&names_blob
);
1843 data_blob_free(&server_chal
);
1848 lm
= data_blob(NULL
, 24);
1849 ok
= SMBencrypt(pass
,
1850 params
.password
.response
.challenge
,
1853 data_blob_free(&lm
);
1856 nt
= data_blob(NULL
, 24);
1857 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1861 params
.password
.response
.nt_length
= nt
.length
;
1862 params
.password
.response
.nt_data
= nt
.data
;
1863 params
.password
.response
.lm_length
= lm
.length
;
1864 params
.password
.response
.lm_data
= lm
.data
;
1866 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1868 /* Display response */
1870 d_printf("challenge/response password authentication %s\n",
1871 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1873 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1875 "wbcAuthenticateUserEx(%s%c%s): error code was "
1876 "%s (0x%x, authoritative=%"PRIu8
")\n"
1877 "error message was: %s\n",
1879 winbind_separator(),
1884 err
->display_string
);
1886 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1887 wbcFreeMemory(info
);
1890 data_blob_free(&nt
);
1891 data_blob_free(&lm
);
1893 return WBC_ERROR_IS_OK(wbc_status
);
1896 /* Authenticate a user with a plaintext password */
1898 static bool wbinfo_pam_logon(char *username
, bool verbose
)
1900 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1901 struct wbcLogonUserParams params
;
1902 struct wbcLogonUserInfo
*info
= NULL
;
1903 struct wbcAuthErrorInfo
*error
= NULL
;
1906 TALLOC_CTX
*frame
= talloc_tos();
1910 ZERO_STRUCT(params
);
1912 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1916 if ((p
= strchr(s
, '%')) != NULL
) {
1919 params
.password
= talloc_strdup(frame
, p
);
1921 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1923 params
.username
= s
;
1925 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1927 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1929 (uint8_t *)&flags
, sizeof(flags
));
1930 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1931 d_printf("wbcAddNamedBlob failed: %s\n",
1932 wbcErrorString(wbc_status
));
1938 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1940 (uint8_t *)&uid
, sizeof(uid
));
1941 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1942 d_printf("wbcAddNamedBlob failed: %s\n",
1943 wbcErrorString(wbc_status
));
1947 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, NULL
);
1949 if (verbose
&& (info
!= NULL
)) {
1950 struct wbcAuthUserInfo
*i
= info
->info
;
1953 if (i
->account_name
!= NULL
) {
1954 d_printf("account_name: %s\n", i
->account_name
);
1956 if (i
->user_principal
!= NULL
) {
1957 d_printf("user_principal: %s\n", i
->user_principal
);
1959 if (i
->full_name
!= NULL
) {
1960 d_printf("full_name: %s\n", i
->full_name
);
1962 if (i
->domain_name
!= NULL
) {
1963 d_printf("domain_name: %s\n", i
->domain_name
);
1965 if (i
->dns_domain_name
!= NULL
) {
1966 d_printf("dns_domain_name: %s\n", i
->dns_domain_name
);
1968 if (i
->logon_server
!= NULL
) {
1969 d_printf("logon_server: %s\n", i
->logon_server
);
1971 if (i
->logon_script
!= NULL
) {
1972 d_printf("logon_script: %s\n", i
->logon_script
);
1974 if (i
->profile_path
!= NULL
) {
1975 d_printf("profile_path: %s\n", i
->profile_path
);
1977 if (i
->home_directory
!= NULL
) {
1978 d_printf("home_directory: %s\n", i
->home_directory
);
1980 if (i
->home_drive
!= NULL
) {
1981 d_printf("home_drive: %s\n", i
->home_drive
);
1986 for (j
=0; j
<i
->num_sids
; j
++) {
1987 char buf
[WBC_SID_STRING_BUFLEN
];
1988 wbcSidToStringBuf(&i
->sids
[j
].sid
, buf
, sizeof(buf
));
1989 d_printf(" %s", buf
);
1993 wbcFreeMemory(info
);
1997 wbcFreeMemory(params
.blobs
);
1999 d_printf("plaintext password authentication %s\n",
2000 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2002 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
2004 "wbcLogonUser(%s): error code was %s (0x%x)\n"
2005 "error message was: %s\n",
2008 (int)error
->nt_status
,
2009 error
->display_string
);
2010 wbcFreeMemory(error
);
2012 return WBC_ERROR_IS_OK(wbc_status
);
2015 /* Save creds with winbind */
2017 static bool wbinfo_ccache_save(char *username
)
2019 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2022 char *password
= NULL
;
2024 TALLOC_CTX
*frame
= talloc_stackframe();
2026 s
= talloc_strdup(frame
, username
);
2035 password
= talloc_strdup(frame
, p
);
2037 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
2042 wbc_status
= wbcCredentialSave(name
, password
);
2044 d_printf("saving creds %s\n",
2045 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2049 return WBC_ERROR_IS_OK(wbc_status
);
2052 #ifdef WITH_FAKE_KASERVER
2053 /* Authenticate a user with a plaintext password and set a token */
2055 static bool wbinfo_klog(char *username
)
2057 struct winbindd_request request
;
2058 struct winbindd_response response
;
2062 /* Send off request */
2064 ZERO_STRUCT(request
);
2065 ZERO_STRUCT(response
);
2067 p
= strchr(username
, '%');
2071 fstrcpy(request
.data
.auth
.user
, username
);
2072 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
2075 fstrcpy(request
.data
.auth
.user
, username
);
2076 (void) samba_getpass("Password: ",
2077 request
.data
.auth
.pass
,
2078 sizeof(request
.data
.auth
.pass
),
2082 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
2084 result
= winbindd_request_response(NULL
, WINBINDD_PAM_AUTH
, &request
,
2087 /* Display response */
2089 d_printf("plaintext password authentication %s\n",
2090 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
2092 if (response
.data
.auth
.nt_status
)
2094 "error code was %s (0x%x)\nerror message was: %s\n",
2095 response
.data
.auth
.nt_status_string
,
2096 response
.data
.auth
.nt_status
,
2097 response
.data
.auth
.error_string
);
2099 if (result
!= NSS_STATUS_SUCCESS
)
2102 if (response
.extra_data
.data
== NULL
) {
2103 d_fprintf(stderr
, "Did not get token data\n");
2107 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
2108 d_fprintf(stderr
, "Could not set token\n");
2112 d_printf("Successfully created AFS token\n");
2116 static bool wbinfo_klog(char *username
)
2118 d_fprintf(stderr
, "No AFS support compiled in.\n");
2123 /* Print domain users */
2125 static bool print_domain_users(const char *domain
)
2127 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2129 uint32_t num_users
= 0;
2130 const char **users
= NULL
;
2132 /* Send request to winbind daemon */
2134 if (domain
== NULL
) {
2135 domain
= get_winbind_domain();
2137 /* '.' is the special sign for our own domain */
2138 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2139 domain
= get_winbind_domain();
2140 /* '*' is the special sign for all domains */
2141 } else if (strcmp(domain
, "*") == 0) {
2146 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
2147 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2151 for (i
=0; i
< num_users
; i
++) {
2152 d_printf("%s\n", users
[i
]);
2155 wbcFreeMemory(users
);
2160 /* Print domain groups */
2162 static bool print_domain_groups(const char *domain
)
2164 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2166 uint32_t num_groups
= 0;
2167 const char **groups
= NULL
;
2169 /* Send request to winbind daemon */
2171 if (domain
== NULL
) {
2172 domain
= get_winbind_domain();
2174 /* '.' is the special sign for our own domain */
2175 if ((domain
[0] == '\0') || strcmp(domain
, ".") == 0) {
2176 domain
= get_winbind_domain();
2177 /* '*' is the special sign for all domains */
2178 } else if (strcmp(domain
, "*") == 0) {
2183 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
2184 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2185 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
2186 wbcErrorString(wbc_status
));
2190 for (i
=0; i
< num_groups
; i
++) {
2191 d_printf("%s\n", groups
[i
]);
2194 wbcFreeMemory(groups
);
2199 /* Set the authorised user for winbindd access in secrets.tdb */
2201 static bool wbinfo_set_auth_user(char *username
)
2203 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2204 "See 'net help setauthuser' for details.\n");
2208 static void wbinfo_get_auth_user(void)
2210 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
2211 "See 'net help getauthuser' for details.\n");
2214 static bool wbinfo_ping(void)
2218 wbc_status
= wbcPing();
2220 /* Display response */
2222 d_printf("Ping to winbindd %s\n",
2223 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2225 return WBC_ERROR_IS_OK(wbc_status
);
2228 static bool wbinfo_change_user_password(const char *username
)
2231 char *old_password
= NULL
;
2232 char *new_password
= NULL
;
2233 TALLOC_CTX
*frame
= talloc_tos();
2235 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2236 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2238 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2240 /* Display response */
2242 d_printf("Password change for user %s %s\n", username
,
2243 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2245 return WBC_ERROR_IS_OK(wbc_status
);
2251 OPT_SET_AUTH_USER
= 1000,
2264 OPT_SET_UID_MAPPING
,
2265 OPT_SET_GID_MAPPING
,
2266 OPT_REMOVE_UID_MAPPING
,
2267 OPT_REMOVE_GID_MAPPING
,
2271 OPT_LIST_ALL_DOMAINS
,
2272 OPT_LIST_OWN_DOMAIN
,
2279 OPT_CHANGE_USER_PASSWORD
,
2281 OPT_SID_TO_FULLNAME
,
2292 int main(int argc
, const char **argv
, char **envp
)
2295 TALLOC_CTX
*frame
= talloc_stackframe();
2297 static char *string_arg
;
2298 char *string_subarg
= NULL
;
2299 static char *opt_domain_name
;
2301 int int_subarg
= -1;
2303 bool verbose
= false;
2304 bool use_ntlmv2
= true;
2305 bool use_lanman
= false;
2306 char *logoff_user
= getenv("USER");
2307 int logoff_uid
= geteuid();
2308 const char *opt_krb5ccname
= "FILE";
2310 struct poptOption long_options
[] = {
2313 /* longName, shortName, argInfo, argPtr, value, descrip,
2317 .longName
= "domain-users",
2319 .argInfo
= POPT_ARG_NONE
,
2321 .descrip
= "Lists all domain users",
2322 .argDescrip
= "domain"
2325 .longName
= "domain-groups",
2327 .argInfo
= POPT_ARG_NONE
,
2329 .descrip
= "Lists all domain groups",
2330 .argDescrip
= "domain"
2333 .longName
= "WINS-by-name",
2335 .argInfo
= POPT_ARG_STRING
,
2338 .descrip
= "Converts NetBIOS name to IP",
2339 .argDescrip
= "NETBIOS-NAME"
2342 .longName
= "WINS-by-ip",
2344 .argInfo
= POPT_ARG_STRING
,
2347 .descrip
= "Converts IP address to NetBIOS name",
2351 .longName
= "name-to-sid",
2353 .argInfo
= POPT_ARG_STRING
,
2356 .descrip
= "Converts name to sid",
2357 .argDescrip
= "NAME"
2360 .longName
= "sid-to-name",
2362 .argInfo
= POPT_ARG_STRING
,
2365 .descrip
= "Converts sid to name",
2369 .longName
= "sid-to-fullname",
2370 .argInfo
= POPT_ARG_STRING
,
2372 .val
= OPT_SID_TO_FULLNAME
,
2373 .descrip
= "Converts sid to fullname",
2377 .longName
= "lookup-rids",
2379 .argInfo
= POPT_ARG_STRING
,
2382 .descrip
= "Converts RIDs to names",
2383 .argDescrip
= "RIDs"
2386 .longName
= "lookup-sids",
2387 .argInfo
= POPT_ARG_STRING
,
2389 .val
= OPT_LOOKUP_SIDS
,
2390 .descrip
= "Converts SIDs to types and names",
2391 .argDescrip
= "Sid-List"
2394 .longName
= "uid-to-sid",
2396 .argInfo
= POPT_ARG_INT
,
2399 .descrip
= "Converts uid to sid",
2403 .longName
= "gid-to-sid",
2405 .argInfo
= POPT_ARG_INT
,
2408 .descrip
= "Converts gid to sid",
2412 .longName
= "sid-to-uid",
2414 .argInfo
= POPT_ARG_STRING
,
2417 .descrip
= "Converts sid to uid",
2421 .longName
= "sid-to-gid",
2423 .argInfo
= POPT_ARG_STRING
,
2426 .descrip
= "Converts sid to gid",
2430 .longName
= "allocate-uid",
2431 .argInfo
= POPT_ARG_NONE
,
2432 .val
= OPT_ALLOCATE_UID
,
2433 .descrip
= "Get a new UID out of idmap"
2436 .longName
= "allocate-gid",
2437 .argInfo
= POPT_ARG_NONE
,
2438 .val
= OPT_ALLOCATE_GID
,
2439 .descrip
= "Get a new GID out of idmap"
2442 .longName
= "set-uid-mapping",
2443 .argInfo
= POPT_ARG_STRING
,
2445 .val
= OPT_SET_UID_MAPPING
,
2446 .descrip
= "Create or modify uid to sid mapping in "
2448 .argDescrip
= "UID,SID"
2451 .longName
= "set-gid-mapping",
2452 .argInfo
= POPT_ARG_STRING
,
2454 .val
= OPT_SET_GID_MAPPING
,
2455 .descrip
= "Create or modify gid to sid mapping in "
2457 .argDescrip
= "GID,SID"
2460 .longName
= "remove-uid-mapping",
2461 .argInfo
= POPT_ARG_STRING
,
2463 .val
= OPT_REMOVE_UID_MAPPING
,
2464 .descrip
= "Remove uid to sid mapping in idmap",
2465 .argDescrip
= "UID,SID"
2468 .longName
= "remove-gid-mapping",
2469 .argInfo
= POPT_ARG_STRING
,
2471 .val
= OPT_REMOVE_GID_MAPPING
,
2472 .descrip
= "Remove gid to sid mapping in idmap",
2473 .argDescrip
= "GID,SID",
2476 .longName
= "sids-to-unix-ids",
2477 .argInfo
= POPT_ARG_STRING
,
2479 .val
= OPT_SIDS_TO_XIDS
,
2480 .descrip
= "Translate SIDs to Unix IDs",
2481 .argDescrip
= "Sid-List",
2484 .longName
= "unix-ids-to-sids",
2485 .argInfo
= POPT_ARG_STRING
,
2487 .val
= OPT_XIDS_TO_SIDS
,
2488 .descrip
= "Translate Unix IDs to SIDs",
2489 .argDescrip
= "ID-List (u<num> g<num>)",
2492 .longName
= "check-secret",
2494 .argInfo
= POPT_ARG_NONE
,
2496 .descrip
= "Check shared secret",
2499 .longName
= "change-secret",
2501 .argInfo
= POPT_ARG_NONE
,
2503 .descrip
= "Change shared secret",
2506 .longName
= "ping-dc",
2508 .argInfo
= POPT_ARG_NONE
,
2510 .descrip
= "Check the NETLOGON connection",
2513 .longName
= "trusted-domains",
2515 .argInfo
= POPT_ARG_NONE
,
2517 .descrip
= "List trusted domains",
2520 .longName
= "all-domains",
2521 .argInfo
= POPT_ARG_NONE
,
2522 .val
= OPT_LIST_ALL_DOMAINS
,
2523 .descrip
= "List all domains (trusted and own "
2527 .longName
= "own-domain",
2528 .argInfo
= POPT_ARG_NONE
,
2529 .val
= OPT_LIST_OWN_DOMAIN
,
2530 .descrip
= "List own domain",
2533 .longName
= "sequence",
2534 .argInfo
= POPT_ARG_NONE
,
2535 .val
= OPT_SEQUENCE
,
2536 .descrip
= "Deprecated command, see --online-status",
2539 .longName
= "online-status",
2540 .argInfo
= POPT_ARG_NONE
,
2541 .val
= OPT_ONLINESTATUS
,
2542 .descrip
= "Show whether domains maintain an active "
2546 .longName
= "domain-info",
2548 .argInfo
= POPT_ARG_STRING
,
2551 .descrip
= "Show most of the info we have about the "
2555 .longName
= "user-info",
2557 .argInfo
= POPT_ARG_STRING
,
2560 .descrip
= "Get user info",
2561 .argDescrip
= "USER",
2564 .longName
= "uid-info",
2565 .argInfo
= POPT_ARG_INT
,
2567 .val
= OPT_UID_INFO
,
2568 .descrip
= "Get user info from uid",
2569 .argDescrip
= "UID",
2572 .longName
= "group-info",
2573 .argInfo
= POPT_ARG_STRING
,
2575 .val
= OPT_GROUP_INFO
,
2576 .descrip
= "Get group info",
2577 .argDescrip
= "GROUP",
2580 .longName
= "user-sidinfo",
2581 .argInfo
= POPT_ARG_STRING
,
2583 .val
= OPT_USER_SIDINFO
,
2584 .descrip
= "Get user info from sid",
2585 .argDescrip
= "SID",
2588 .longName
= "gid-info",
2589 .argInfo
= POPT_ARG_INT
,
2591 .val
= OPT_GID_INFO
,
2592 .descrip
= "Get group info from gid",
2593 .argDescrip
= "GID",
2596 .longName
= "user-groups",
2598 .argInfo
= POPT_ARG_STRING
,
2601 .descrip
= "Get user groups",
2602 .argDescrip
= "USER",
2605 .longName
= "user-domgroups",
2606 .argInfo
= POPT_ARG_STRING
,
2608 .val
= OPT_USERDOMGROUPS
,
2609 .descrip
= "Get user domain groups",
2610 .argDescrip
= "SID",
2613 .longName
= "sid-aliases",
2614 .argInfo
= POPT_ARG_STRING
,
2616 .val
= OPT_SIDALIASES
,
2617 .descrip
= "Get sid aliases",
2618 .argDescrip
= "SID",
2621 .longName
= "user-sids",
2622 .argInfo
= POPT_ARG_STRING
,
2624 .val
= OPT_USERSIDS
,
2625 .descrip
= "Get user group sids for user SID",
2626 .argDescrip
= "SID",
2629 .longName
= "authenticate",
2631 .argInfo
= POPT_ARG_STRING
,
2634 .descrip
= "authenticate user",
2635 .argDescrip
= "user%password",
2638 .longName
= "pam-logon",
2639 .argInfo
= POPT_ARG_STRING
,
2641 .val
= OPT_PAM_LOGON
,
2642 .descrip
= "do a pam logon equivalent",
2643 .argDescrip
= "user%password",
2646 .longName
= "logoff",
2647 .argInfo
= POPT_ARG_NONE
,
2649 .descrip
= "log off user",
2650 .argDescrip
= "uid",
2653 .longName
= "logoff-user",
2654 .argInfo
= POPT_ARG_STRING
,
2655 .arg
= &logoff_user
,
2656 .val
= OPT_LOGOFF_USER
,
2657 .descrip
= "username to log off"
2660 .longName
= "logoff-uid",
2661 .argInfo
= POPT_ARG_INT
,
2663 .val
= OPT_LOGOFF_UID
,
2664 .descrip
= "uid to log off",
2667 .longName
= "set-auth-user",
2668 .argInfo
= POPT_ARG_STRING
,
2670 .val
= OPT_SET_AUTH_USER
,
2671 .descrip
= "Store user and password used by "
2672 "winbindd (root only)",
2673 .argDescrip
= "user%password",
2676 .longName
= "ccache-save",
2678 .argInfo
= POPT_ARG_STRING
,
2680 .val
= OPT_CCACHE_SAVE
,
2681 .descrip
= "Store user and password for ccache "
2683 .argDescrip
= "user%password",
2686 .longName
= "getdcname",
2687 .argInfo
= POPT_ARG_STRING
,
2689 .val
= OPT_GETDCNAME
,
2690 .descrip
= "Get a DC name for a foreign domain",
2691 .argDescrip
= "domainname",
2694 .longName
= "dsgetdcname",
2695 .argInfo
= POPT_ARG_STRING
,
2697 .val
= OPT_DSGETDCNAME
,
2698 .descrip
= "Find a DC for a domain",
2699 .argDescrip
= "domainname",
2702 .longName
= "dc-info",
2703 .argInfo
= POPT_ARG_STRING
,
2706 .descrip
= "Find the currently known DCs",
2707 .argDescrip
= "domainname",
2710 .longName
= "get-auth-user",
2711 .argInfo
= POPT_ARG_NONE
,
2712 .val
= OPT_GET_AUTH_USER
,
2713 .descrip
= "Retrieve user and password used by "
2714 "winbindd (root only)",
2719 .argInfo
= POPT_ARG_NONE
,
2722 .descrip
= "Ping winbindd to see if it is alive",
2725 .longName
= "domain",
2727 .argInfo
= POPT_ARG_STRING
,
2728 .arg
= &opt_domain_name
,
2729 .val
= OPT_DOMAIN_NAME
,
2730 .descrip
= "Define to the domain to restrict "
2732 .argDescrip
= "domain",
2734 #ifdef WITH_FAKE_KASERVER
2738 .argInfo
= POPT_ARG_STRING
,
2741 .descrip
= "set an AFS token from winbind",
2742 .argDescrip
= "user%password",
2747 .longName
= "krb5auth",
2749 .argInfo
= POPT_ARG_STRING
,
2752 .descrip
= "authenticate user using Kerberos",
2753 .argDescrip
= "user%password",
2755 /* destroys wbinfo --help output */
2756 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" },
2759 .longName
= "krb5ccname",
2760 .argInfo
= POPT_ARG_STRING
,
2761 .arg
= &opt_krb5ccname
,
2762 .val
= OPT_KRB5CCNAME
,
2763 .descrip
= "authenticate user using Kerberos and "
2764 "specific credential cache type",
2765 .argDescrip
= "krb5ccname",
2769 .longName
= "separator",
2770 .argInfo
= POPT_ARG_NONE
,
2771 .val
= OPT_SEPARATOR
,
2772 .descrip
= "Get the active winbind separator",
2775 .longName
= "verbose",
2776 .argInfo
= POPT_ARG_NONE
,
2778 .descrip
= "Print additional information per command",
2781 .longName
= "change-user-password",
2782 .argInfo
= POPT_ARG_STRING
,
2784 .val
= OPT_CHANGE_USER_PASSWORD
,
2785 .descrip
= "Change the password for a user",
2788 .longName
= "ntlmv1",
2789 .argInfo
= POPT_ARG_NONE
,
2791 .descrip
= "Use NTLMv1 cryptography for user authentication",
2794 .longName
= "ntlmv2",
2795 .argInfo
= POPT_ARG_NONE
,
2797 .descrip
= "Use NTLMv2 cryptography for user authentication",
2800 .longName
= "lanman",
2801 .argInfo
= POPT_ARG_NONE
,
2803 .descrip
= "Use lanman cryptography for user authentication",
2809 /* Samba client initialisation */
2815 pc
= samba_popt_get_context(getprogname(),
2821 DBG_ERR("Failed to setup popt context!\n");
2825 /* Parse command line options */
2828 poptPrintHelp(pc
, stderr
, 0);
2832 while((opt
= poptGetNextOpt(pc
)) != -1) {
2833 /* get the generic configuration parameters like --domain */
2847 poptFreeContext(pc
);
2849 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2850 POPT_CONTEXT_KEEP_FIRST
);
2852 while((opt
= poptGetNextOpt(pc
)) != -1) {
2855 if (!print_domain_users(opt_domain_name
)) {
2857 "Error looking up domain users\n");
2862 if (!print_domain_groups(opt_domain_name
)) {
2864 "Error looking up domain groups\n");
2869 if (!wbinfo_lookupsid(string_arg
)) {
2871 "Could not lookup sid %s\n",
2876 case OPT_SID_TO_FULLNAME
:
2877 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2878 d_fprintf(stderr
, "Could not lookup sid %s\n",
2884 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2885 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2890 case OPT_LOOKUP_SIDS
:
2891 if (!wbinfo_lookup_sids(string_arg
)) {
2892 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2898 if (!wbinfo_lookupname(string_arg
)) {
2899 d_fprintf(stderr
, "Could not lookup name %s\n",
2905 if (!wbinfo_wins_byname(string_arg
)) {
2907 "Could not lookup WINS by name %s\n",
2913 if (!wbinfo_wins_byip(string_arg
)) {
2915 "Could not lookup WINS by IP %s\n",
2921 if (!wbinfo_uid_to_sid(int_arg
)) {
2923 "Could not convert uid %d to sid\n",
2929 if (!wbinfo_gid_to_sid(int_arg
)) {
2931 "Could not convert gid %d to sid\n",
2937 if (!wbinfo_sid_to_uid(string_arg
)) {
2939 "Could not convert sid %s to uid\n",
2945 if (!wbinfo_sid_to_gid(string_arg
)) {
2947 "Could not convert sid %s to gid\n",
2952 case OPT_ALLOCATE_UID
:
2953 if (!wbinfo_allocate_uid()) {
2954 d_fprintf(stderr
, "Could not allocate a uid\n");
2958 case OPT_ALLOCATE_GID
:
2959 if (!wbinfo_allocate_gid()) {
2960 d_fprintf(stderr
, "Could not allocate a gid\n");
2964 case OPT_SET_UID_MAPPING
:
2965 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2967 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2969 d_fprintf(stderr
, "Could not create or modify "
2970 "uid to sid mapping\n");
2974 case OPT_SET_GID_MAPPING
:
2975 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2977 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2979 d_fprintf(stderr
, "Could not create or modify "
2980 "gid to sid mapping\n");
2984 case OPT_REMOVE_UID_MAPPING
:
2985 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2987 !wbinfo_remove_uid_mapping(int_subarg
,
2990 d_fprintf(stderr
, "Could not remove uid to sid "
2995 case OPT_REMOVE_GID_MAPPING
:
2996 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2998 !wbinfo_remove_gid_mapping(int_subarg
,
3001 d_fprintf(stderr
, "Could not remove gid to sid "
3006 case OPT_SIDS_TO_XIDS
:
3007 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
3008 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
3013 case OPT_XIDS_TO_SIDS
:
3014 if (!wbinfo_xids_to_sids(string_arg
)) {
3015 d_fprintf(stderr
, "wbinfo_xids_to_sids "
3021 if (!wbinfo_check_secret(opt_domain_name
)) {
3022 d_fprintf(stderr
, "Could not check secret\n");
3027 if (!wbinfo_change_secret(opt_domain_name
)) {
3028 d_fprintf(stderr
, "Could not change secret\n");
3033 if (!wbinfo_ping_dc(opt_domain_name
)) {
3038 if (!wbinfo_list_domains(false, verbose
)) {
3040 "Could not list trusted domains\n");
3045 if (!wbinfo_show_sequence(opt_domain_name
)) {
3047 "Could not show sequence numbers\n");
3051 case OPT_ONLINESTATUS
:
3052 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
3054 "Could not show online-status\n");
3059 if (!wbinfo_domain_info(string_arg
)) {
3061 "Could not get domain info\n");
3066 if (!wbinfo_get_userinfo(string_arg
)) {
3068 "Could not get info for user %s\n",
3073 case OPT_USER_SIDINFO
:
3074 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
3076 "Could not get info for user "
3077 "sid %s\n", string_arg
);
3082 if ( !wbinfo_get_uidinfo(int_arg
)) {
3083 d_fprintf(stderr
, "Could not get info for uid "
3088 case OPT_GROUP_INFO
:
3089 if ( !wbinfo_get_groupinfo(string_arg
)) {
3090 d_fprintf(stderr
, "Could not get info for "
3091 "group %s\n", string_arg
);
3096 if ( !wbinfo_get_gidinfo(int_arg
)) {
3097 d_fprintf(stderr
, "Could not get info for gid "
3103 if (!wbinfo_get_usergroups(string_arg
)) {
3105 "Could not get groups for user %s\n",
3111 if (!wbinfo_get_usersids(string_arg
)) {
3112 d_fprintf(stderr
, "Could not get group SIDs "
3113 "for user SID %s\n",
3118 case OPT_USERDOMGROUPS
:
3119 if (!wbinfo_get_userdomgroups(string_arg
)) {
3120 d_fprintf(stderr
, "Could not get user's domain "
3121 "groups for user SID %s\n",
3126 case OPT_SIDALIASES
:
3127 if (!wbinfo_get_sidaliases(opt_domain_name
,
3129 d_fprintf(stderr
, "Could not get sid aliases "
3130 "for user SID %s\n", string_arg
);
3135 bool got_error
= false;
3137 if (!wbinfo_auth(string_arg
)) {
3139 "Could not authenticate user "
3140 "%s with plaintext "
3141 "password\n", string_arg
);
3145 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
3148 "Could not authenticate user "
3149 "%s with challenge/response\n",
3159 if (!wbinfo_pam_logon(string_arg
, verbose
)) {
3160 d_fprintf(stderr
, "pam_logon failed for %s\n",
3169 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
3171 d_printf("Logoff %s (%d): %s\n", logoff_user
,
3172 logoff_uid
, wbcErrorString(wbc_status
));
3176 uint32_t flags
= WBFLAG_PAM_KRB5
|
3177 WBFLAG_PAM_CACHED_LOGIN
|
3178 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
3179 WBFLAG_PAM_INFO3_TEXT
|
3180 WBFLAG_PAM_CONTACT_TRUSTDOM
;
3182 if (!wbinfo_auth_krb5(string_arg
, opt_krb5ccname
,
3185 "Could not authenticate user "
3186 "[%s] with Kerberos "
3187 "(ccache: %s)\n", string_arg
,
3194 if (!wbinfo_klog(string_arg
)) {
3195 d_fprintf(stderr
, "Could not klog user\n");
3200 if (!wbinfo_ping()) {
3201 d_fprintf(stderr
, "could not ping winbindd!\n");
3205 case OPT_SET_AUTH_USER
:
3206 if (!wbinfo_set_auth_user(string_arg
)) {
3210 case OPT_GET_AUTH_USER
:
3211 wbinfo_get_auth_user();
3214 case OPT_CCACHE_SAVE
:
3215 if (!wbinfo_ccache_save(string_arg
)) {
3220 if (!wbinfo_getdcname(string_arg
)) {
3224 case OPT_DSGETDCNAME
:
3225 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
3230 if (!wbinfo_dc_info(string_arg
)) {
3234 case OPT_SEPARATOR
: {
3235 const char sep
= winbind_separator();
3239 d_printf("%c\n", sep
);
3242 case OPT_LIST_ALL_DOMAINS
:
3243 if (!wbinfo_list_domains(true, verbose
)) {
3247 case OPT_LIST_OWN_DOMAIN
:
3248 if (!wbinfo_list_own_domain()) {
3252 case OPT_CHANGE_USER_PASSWORD
:
3253 if (!wbinfo_change_user_password(string_arg
)) {
3255 "Could not change user password "
3256 "for user %s\n", string_arg
);
3261 /* generic configuration options */
3262 case OPT_DOMAIN_NAME
:
3267 case OPT_LOGOFF_USER
:
3268 case OPT_LOGOFF_UID
:
3269 case OPT_KRB5CCNAME
:
3272 d_fprintf(stderr
, "Invalid option\n");
3273 poptPrintHelp(pc
, stderr
, 0);
3285 poptFreeContext(pc
);