2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "winbind_client.h"
26 #include "libwbclient/wbclient.h"
27 #include "lib/popt/popt.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #if (_SAMBA_BUILD_) >= 4
30 #include "lib/cmdline/popt_common.h"
32 #include "popt_common.h"
37 #define DBGC_CLASS DBGC_WINBIND
40 static struct wbcInterfaceDetails
*init_interface_details(void)
42 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
43 static struct wbcInterfaceDetails
*details
;
49 wbc_status
= wbcInterfaceDetails(&details
);
50 if (!WBC_ERROR_IS_OK(wbc_status
)) {
51 d_fprintf(stderr
, "could not obtain winbind interface "
52 "details: %s\n", wbcErrorString(wbc_status
));
58 static char winbind_separator(void)
60 struct wbcInterfaceDetails
*details
;
67 details
= init_interface_details();
70 d_fprintf(stderr
, "could not obtain winbind separator!\n");
74 sep
= details
->winbind_separator
;
78 d_fprintf(stderr
, "winbind separator was NULL!\n");
85 static const char *get_winbind_domain(void)
87 static struct wbcInterfaceDetails
*details
;
89 details
= init_interface_details();
92 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
96 return details
->netbios_domain
;
99 static const char *get_winbind_netbios_name(void)
101 static struct wbcInterfaceDetails
*details
;
103 details
= init_interface_details();
106 d_fprintf(stderr
, "could not obtain winbind netbios name!\n");
110 return details
->netbios_name
;
113 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
114 form DOMAIN/user into a domain and a user */
116 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
120 char *p
= strchr(domuser
,winbind_separator());
123 /* Maybe it was a UPN? */
124 p
= strchr(domuser
, '@');
127 fstrcpy(user
, domuser
);
131 fstrcpy(user
, domuser
);
132 fstrcpy(domain
, get_winbind_domain());
137 fstrcpy(domain
, domuser
);
138 domain
[PTR_DIFF(p
, domuser
)] = 0;
143 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
144 * Return true if input was valid, false otherwise. */
145 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
152 tmp
= strtok(arg
, ",");
153 *sid
= strtok(NULL
, ",");
155 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
158 /* Because atoi() can return 0 on invalid input, which would be a valid
159 * UID/GID we must use strtoul() and do error checking */
160 *id
= strtoul(tmp
, &endptr
, 10);
162 if (endptr
[0] != '\0')
168 /* pull pwent info for a given user */
170 static bool wbinfo_get_userinfo(char *user
)
172 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
173 struct passwd
*pwd
= NULL
;
175 wbc_status
= wbcGetpwnam(user
, &pwd
);
176 if (!WBC_ERROR_IS_OK(wbc_status
)) {
177 d_fprintf(stderr
, "failed to call wbcGetpwnam: %s\n",
178 wbcErrorString(wbc_status
));
182 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
185 (unsigned int)pwd
->pw_uid
,
186 (unsigned int)pwd
->pw_gid
,
196 /* pull pwent info for a given uid */
197 static bool wbinfo_get_uidinfo(int uid
)
199 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
200 struct passwd
*pwd
= NULL
;
202 wbc_status
= wbcGetpwuid(uid
, &pwd
);
203 if (!WBC_ERROR_IS_OK(wbc_status
)) {
204 d_fprintf(stderr
, "failed to call wbcGetpwuid: %s\n",
205 wbcErrorString(wbc_status
));
209 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
212 (unsigned int)pwd
->pw_uid
,
213 (unsigned int)pwd
->pw_gid
,
223 static bool wbinfo_get_user_sidinfo(const char *sid_str
)
225 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
226 struct passwd
*pwd
= NULL
;
227 struct wbcDomainSid sid
;
229 wbc_status
= wbcStringToSid(sid_str
, &sid
);
230 wbc_status
= wbcGetpwsid(&sid
, &pwd
);
231 if (!WBC_ERROR_IS_OK(wbc_status
)) {
232 d_fprintf(stderr
, "failed to call wbcGetpwsid: %s\n",
233 wbcErrorString(wbc_status
));
237 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
240 (unsigned int)pwd
->pw_uid
,
241 (unsigned int)pwd
->pw_gid
,
252 /* pull grent for a given group */
253 static bool wbinfo_get_groupinfo(const char *group
)
255 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
259 wbc_status
= wbcGetgrnam(group
, &grp
);
260 if (!WBC_ERROR_IS_OK(wbc_status
)) {
261 d_fprintf(stderr
, "failed to call wbcGetgrnam: %s\n",
262 wbcErrorString(wbc_status
));
266 d_printf("%s:%s:%u:",
269 (unsigned int)grp
->gr_gid
);
272 while (*mem
!= NULL
) {
273 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
283 /* pull grent for a given gid */
284 static bool wbinfo_get_gidinfo(int gid
)
286 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
290 wbc_status
= wbcGetgrgid(gid
, &grp
);
291 if (!WBC_ERROR_IS_OK(wbc_status
)) {
292 d_fprintf(stderr
, "failed to call wbcGetgrgid: %s\n",
293 wbcErrorString(wbc_status
));
297 d_printf("%s:%s:%u:",
300 (unsigned int)grp
->gr_gid
);
303 while (*mem
!= NULL
) {
304 d_printf("%s%s", *mem
, *(mem
+1) != NULL
? "," : "");
314 /* List groups a user is a member of */
316 static bool wbinfo_get_usergroups(const char *user
)
318 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
321 gid_t
*groups
= NULL
;
325 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
326 if (!WBC_ERROR_IS_OK(wbc_status
)) {
327 d_fprintf(stderr
, "failed to call wbcGetGroups: %s\n",
328 wbcErrorString(wbc_status
));
332 for (i
= 0; i
< num_groups
; i
++) {
333 d_printf("%d\n", (int)groups
[i
]);
336 wbcFreeMemory(groups
);
342 /* List group SIDs a user SID is a member of */
343 static bool wbinfo_get_usersids(const char *user_sid_str
)
345 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
348 struct wbcDomainSid user_sid
, *sids
= NULL
;
352 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
353 if (!WBC_ERROR_IS_OK(wbc_status
)) {
354 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
355 wbcErrorString(wbc_status
));
359 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
360 if (!WBC_ERROR_IS_OK(wbc_status
)) {
361 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
362 wbcErrorString(wbc_status
));
366 for (i
= 0; i
< num_sids
; i
++) {
367 char str
[WBC_SID_STRING_BUFLEN
];
368 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
369 d_printf("%s\n", str
);
377 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
379 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
382 struct wbcDomainSid user_sid
, *sids
= NULL
;
386 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
387 if (!WBC_ERROR_IS_OK(wbc_status
)) {
388 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
389 wbcErrorString(wbc_status
));
393 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
394 if (!WBC_ERROR_IS_OK(wbc_status
)) {
395 d_fprintf(stderr
, "failed to call wbcLookupUserSids: %s\n",
396 wbcErrorString(wbc_status
));
400 for (i
= 0; i
< num_sids
; i
++) {
401 char str
[WBC_SID_STRING_BUFLEN
];
402 wbcSidToStringBuf(&sids
[i
], str
, sizeof(str
));
403 d_printf("%s\n", str
);
411 static bool wbinfo_get_sidaliases(const char *domain
,
412 const char *user_sid_str
)
414 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
415 struct wbcDomainInfo
*dinfo
= NULL
;
417 struct wbcDomainSid user_sid
;
418 uint32_t *alias_rids
= NULL
;
419 uint32_t num_alias_rids
;
420 char domain_sid_str
[WBC_SID_STRING_BUFLEN
];
423 if ((domain
== NULL
) || (strequal(domain
, ".")) ||
424 (domain
[0] == '\0')) {
425 domain
= get_winbind_domain();
430 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
431 if (!WBC_ERROR_IS_OK(wbc_status
)) {
432 d_fprintf(stderr
, "wbcDomainInfo(%s) failed: %s\n", domain
,
433 wbcErrorString(wbc_status
));
436 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
437 if (!WBC_ERROR_IS_OK(wbc_status
)) {
441 wbc_status
= wbcGetSidAliases(&dinfo
->sid
, &user_sid
, 1,
442 &alias_rids
, &num_alias_rids
);
443 if (!WBC_ERROR_IS_OK(wbc_status
)) {
447 wbcSidToStringBuf(&dinfo
->sid
, domain_sid_str
, sizeof(domain_sid_str
));
449 for (i
= 0; i
< num_alias_rids
; i
++) {
450 d_printf("%s-%d\n", domain_sid_str
, alias_rids
[i
]);
453 wbcFreeMemory(alias_rids
);
456 wbcFreeMemory(dinfo
);
457 return (WBC_ERR_SUCCESS
== wbc_status
);
461 /* Convert NetBIOS name to IP */
463 static bool wbinfo_wins_byname(const char *name
)
465 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
468 wbc_status
= wbcResolveWinsByName(name
, &ip
);
469 if (!WBC_ERROR_IS_OK(wbc_status
)) {
470 d_fprintf(stderr
, "failed to call wbcResolveWinsByName: %s\n",
471 wbcErrorString(wbc_status
));
475 /* Display response */
477 d_printf("%s\n", ip
);
484 /* Convert IP to NetBIOS name */
486 static bool wbinfo_wins_byip(const char *ip
)
488 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
491 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
492 if (!WBC_ERROR_IS_OK(wbc_status
)) {
493 d_fprintf(stderr
, "failed to call wbcResolveWinsByIP: %s\n",
494 wbcErrorString(wbc_status
));
498 /* Display response */
500 d_printf("%s\n", name
);
507 /* List all/trusted domains */
509 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
511 struct wbcDomainInfo
*domain_list
= NULL
;
513 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
514 bool print_all
= !list_all_domains
&& verbose
;
517 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
518 if (!WBC_ERROR_IS_OK(wbc_status
)) {
519 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
520 wbcErrorString(wbc_status
));
525 d_printf("%-16s%-65s%-12s%-12s%-5s%-5s\n",
526 "Domain Name", "DNS Domain", "Trust Type",
527 "Transitive", "In", "Out");
530 for (i
=0; i
<num_domains
; i
++) {
532 d_printf("%-16s", domain_list
[i
].short_name
);
534 d_printf("%s", domain_list
[i
].short_name
);
539 d_printf("%-65s", domain_list
[i
].dns_name
);
541 switch(domain_list
[i
].trust_type
) {
542 case WBC_DOMINFO_TRUSTTYPE_NONE
:
545 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
548 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
549 d_printf("External ");
551 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
552 d_printf("In-Forest ");
556 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
562 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
568 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
577 wbcFreeMemory(domain_list
);
582 /* List own domain */
584 static bool wbinfo_list_own_domain(void)
586 d_printf("%s\n", get_winbind_domain());
591 /* show sequence numbers */
592 static bool wbinfo_show_sequence(const char *domain
)
594 d_printf("This command has been deprecated. Please use the "
595 "--online-status option instead.\n");
599 /* show sequence numbers */
600 static bool wbinfo_show_onlinestatus(const char *domain
)
602 struct wbcDomainInfo
*domain_list
= NULL
;
604 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
607 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
608 if (!WBC_ERROR_IS_OK(wbc_status
)) {
609 d_fprintf(stderr
, "failed to call wbcListTrusts: %s\n",
610 wbcErrorString(wbc_status
));
614 for (i
=0; i
<num_domains
; i
++) {
618 if (!strequal(domain_list
[i
].short_name
, domain
)) {
623 is_offline
= (domain_list
[i
].domain_flags
&
624 WBC_DOMINFO_DOMAIN_OFFLINE
);
626 d_printf("%s : %s\n",
627 domain_list
[i
].short_name
,
628 is_offline
? "offline" : "online" );
631 wbcFreeMemory(domain_list
);
637 /* Show domain info */
639 static bool wbinfo_domain_info(const char *domain
)
641 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
642 struct wbcDomainInfo
*dinfo
= NULL
;
643 char sid_str
[WBC_SID_STRING_BUFLEN
];
645 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
646 domain
= get_winbind_domain();
651 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
652 if (!WBC_ERROR_IS_OK(wbc_status
)) {
653 d_fprintf(stderr
, "failed to call wbcDomainInfo: %s\n",
654 wbcErrorString(wbc_status
));
658 wbcSidToStringBuf(&dinfo
->sid
, sid_str
, sizeof(sid_str
));
660 /* Display response */
662 d_printf("Name : %s\n", dinfo
->short_name
);
663 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
665 d_printf("SID : %s\n", sid_str
);
667 d_printf("Active Directory : %s\n",
668 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
669 d_printf("Native : %s\n",
670 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ?
673 d_printf("Primary : %s\n",
674 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ?
677 wbcFreeMemory(dinfo
);
682 /* Get a foreign DC's name */
683 static bool wbinfo_getdcname(const char *domain_name
)
685 struct winbindd_request request
;
686 struct winbindd_response response
;
688 ZERO_STRUCT(request
);
689 ZERO_STRUCT(response
);
691 fstrcpy(request
.domain_name
, domain_name
);
695 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
,
696 &response
) != NSS_STATUS_SUCCESS
) {
697 d_fprintf(stderr
, "Could not get dc name for %s\n",domain_name
);
701 /* Display response */
703 d_printf("%s\n", response
.data
.dc_name
);
709 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
711 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
712 struct wbcDomainControllerInfoEx
*dc_info
;
715 wbc_status
= wbcLookupDomainControllerEx(domain_name
, NULL
, NULL
,
716 flags
| DS_DIRECTORY_SERVICE_REQUIRED
,
718 if (!WBC_ERROR_IS_OK(wbc_status
)) {
719 printf("Could not find dc for %s\n", domain_name
);
723 wbcGuidToString(dc_info
->domain_guid
, &str
);
725 d_printf("%s\n", dc_info
->dc_unc
);
726 d_printf("%s\n", dc_info
->dc_address
);
727 d_printf("%d\n", dc_info
->dc_address_type
);
728 d_printf("%s\n", str
);
729 d_printf("%s\n", dc_info
->domain_name
);
730 d_printf("%s\n", dc_info
->forest_name
);
731 d_printf("0x%08x\n", dc_info
->dc_flags
);
732 d_printf("%s\n", dc_info
->dc_site_name
);
733 d_printf("%s\n", dc_info
->client_site_name
);
738 /* Check trust account password */
740 static bool wbinfo_check_secret(const char *domain
)
742 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
743 struct wbcAuthErrorInfo
*error
= NULL
;
744 const char *domain_name
;
747 domain_name
= domain
;
749 domain_name
= get_winbind_domain();
752 wbc_status
= wbcCheckTrustCredentials(domain_name
, &error
);
754 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
756 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
758 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
759 d_fprintf(stderr
, "error code was %s (0x%x)\n",
760 error
->nt_string
, error
->nt_status
);
761 wbcFreeMemory(error
);
763 if (!WBC_ERROR_IS_OK(wbc_status
)) {
764 d_fprintf(stderr
, "failed to call wbcCheckTrustCredentials: "
765 "%s\n", wbcErrorString(wbc_status
));
772 /* Find the currently connected DCs */
774 static bool wbinfo_dc_info(const char *domain_name
)
776 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
778 const char **dc_names
, **dc_ips
;
780 wbc_status
= wbcDcInfo(domain_name
, &num_dcs
,
782 if (!WBC_ERROR_IS_OK(wbc_status
)) {
783 printf("Could not find dc info %s\n",
784 domain_name
? domain_name
: "our domain");
788 for (i
=0; i
<num_dcs
; i
++) {
789 printf("%s (%s)\n", dc_names
[i
], dc_ips
[i
]);
791 wbcFreeMemory(dc_names
);
792 wbcFreeMemory(dc_ips
);
797 /* Change trust account password */
799 static bool wbinfo_change_secret(const char *domain
)
801 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
802 struct wbcAuthErrorInfo
*error
= NULL
;
803 const char *domain_name
;
806 domain_name
= domain
;
808 domain_name
= get_winbind_domain();
811 wbc_status
= wbcChangeTrustCredentials(domain_name
, &error
);
813 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
815 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
817 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
818 d_fprintf(stderr
, "error code was %s (0x%x)\n",
819 error
->nt_string
, error
->nt_status
);
820 wbcFreeMemory(error
);
822 if (!WBC_ERROR_IS_OK(wbc_status
)) {
823 d_fprintf(stderr
, "failed to call wbcChangeTrustCredentials: "
824 "%s\n", wbcErrorString(wbc_status
));
831 /* Check DC connection */
833 static bool wbinfo_ping_dc(void)
835 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
836 struct wbcAuthErrorInfo
*error
= NULL
;
839 wbc_status
= wbcPingDc2(NULL
, &error
, &dcname
);
841 d_printf("checking the NETLOGON dc connection to \"%s\" %s\n",
842 dcname
? dcname
: "",
843 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
845 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
846 d_fprintf(stderr
, "error code was %s (0x%x)\n",
847 error
->nt_string
, error
->nt_status
);
848 wbcFreeMemory(error
);
851 if (!WBC_ERROR_IS_OK(wbc_status
)) {
852 d_fprintf(stderr
, "failed to call wbcPingDc: %s\n",
853 wbcErrorString(wbc_status
));
860 /* Convert uid to sid */
862 static bool wbinfo_uid_to_sid(uid_t uid
)
864 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
865 struct wbcDomainSid sid
;
866 char sid_str
[WBC_SID_STRING_BUFLEN
];
870 wbc_status
= wbcUidToSid(uid
, &sid
);
871 if (!WBC_ERROR_IS_OK(wbc_status
)) {
872 d_fprintf(stderr
, "failed to call wbcUidToSid: %s\n",
873 wbcErrorString(wbc_status
));
877 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
879 /* Display response */
881 d_printf("%s\n", sid_str
);
886 /* Convert gid to sid */
888 static bool wbinfo_gid_to_sid(gid_t gid
)
890 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
891 struct wbcDomainSid sid
;
892 char sid_str
[WBC_SID_STRING_BUFLEN
];
896 wbc_status
= wbcGidToSid(gid
, &sid
);
897 if (!WBC_ERROR_IS_OK(wbc_status
)) {
898 d_fprintf(stderr
, "failed to call wbcGidToSid: %s\n",
899 wbcErrorString(wbc_status
));
903 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
905 /* Display response */
907 d_printf("%s\n", sid_str
);
912 /* Convert sid to uid */
914 static bool wbinfo_sid_to_uid(const char *sid_str
)
916 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
917 struct wbcDomainSid sid
;
922 wbc_status
= wbcStringToSid(sid_str
, &sid
);
923 if (!WBC_ERROR_IS_OK(wbc_status
)) {
924 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
925 wbcErrorString(wbc_status
));
929 wbc_status
= wbcSidToUid(&sid
, &uid
);
930 if (!WBC_ERROR_IS_OK(wbc_status
)) {
931 d_fprintf(stderr
, "failed to call wbcSidToUid: %s\n",
932 wbcErrorString(wbc_status
));
936 /* Display response */
938 d_printf("%d\n", (int)uid
);
943 static bool wbinfo_sid_to_gid(const char *sid_str
)
945 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
946 struct wbcDomainSid sid
;
951 wbc_status
= wbcStringToSid(sid_str
, &sid
);
952 if (!WBC_ERROR_IS_OK(wbc_status
)) {
953 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
954 wbcErrorString(wbc_status
));
958 wbc_status
= wbcSidToGid(&sid
, &gid
);
959 if (!WBC_ERROR_IS_OK(wbc_status
)) {
960 d_fprintf(stderr
, "failed to call wbcSidToGid: %s\n",
961 wbcErrorString(wbc_status
));
965 /* Display response */
967 d_printf("%d\n", (int)gid
);
972 static bool wbinfo_sids_to_unix_ids(const char *arg
)
974 char sidstr
[WBC_SID_STRING_BUFLEN
];
975 struct wbcDomainSid
*sids
;
976 struct wbcUnixId
*unix_ids
;
986 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
987 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
990 d_fprintf(stderr
, "talloc failed\n");
993 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
994 if (!WBC_ERROR_IS_OK(wbc_status
)) {
995 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
996 sidstr
, wbcErrorString(wbc_status
));
1003 unix_ids
= talloc_array(talloc_tos(), struct wbcUnixId
, num_sids
);
1004 if (unix_ids
== NULL
) {
1009 wbc_status
= wbcSidsToUnixIds(sids
, num_sids
, unix_ids
);
1010 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1011 d_fprintf(stderr
, "wbcSidsToUnixIds failed: %s\n",
1012 wbcErrorString(wbc_status
));
1017 for (i
=0; i
<num_sids
; i
++) {
1019 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1021 switch(unix_ids
[i
].type
) {
1022 case WBC_ID_TYPE_UID
:
1023 d_printf("%s -> uid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1025 case WBC_ID_TYPE_GID
:
1026 d_printf("%s -> gid %d\n", sidstr
, unix_ids
[i
].id
.gid
);
1028 case WBC_ID_TYPE_BOTH
:
1029 d_printf("%s -> uid/gid %d\n", sidstr
, unix_ids
[i
].id
.uid
);
1032 d_printf("%s -> unmapped\n", sidstr
);
1038 TALLOC_FREE(unix_ids
);
1043 static bool wbinfo_allocate_uid(void)
1045 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1050 wbc_status
= wbcAllocateUid(&uid
);
1051 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1052 d_fprintf(stderr
, "failed to call wbcAllocateUid: %s\n",
1053 wbcErrorString(wbc_status
));
1057 /* Display response */
1059 d_printf("New uid: %u\n", (unsigned int)uid
);
1064 static bool wbinfo_allocate_gid(void)
1066 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1071 wbc_status
= wbcAllocateGid(&gid
);
1072 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1073 d_fprintf(stderr
, "failed to call wbcAllocateGid: %s\n",
1074 wbcErrorString(wbc_status
));
1078 /* Display response */
1080 d_printf("New gid: %u\n", (unsigned int)gid
);
1085 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
1087 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1088 struct wbcDomainSid sid
;
1092 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1093 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1094 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1095 wbcErrorString(wbc_status
));
1099 wbc_status
= wbcSetUidMapping(uid
, &sid
);
1100 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1101 d_fprintf(stderr
, "failed to call wbcSetUidMapping: %s\n",
1102 wbcErrorString(wbc_status
));
1106 /* Display response */
1108 d_printf("uid %u now mapped to sid %s\n",
1109 (unsigned int)uid
, sid_str
);
1114 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
1116 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1117 struct wbcDomainSid sid
;
1121 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1122 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1123 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1124 wbcErrorString(wbc_status
));
1128 wbc_status
= wbcSetGidMapping(gid
, &sid
);
1129 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1130 d_fprintf(stderr
, "failed to call wbcSetGidMapping: %s\n",
1131 wbcErrorString(wbc_status
));
1135 /* Display response */
1137 d_printf("gid %u now mapped to sid %s\n",
1138 (unsigned int)gid
, sid_str
);
1143 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
1145 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1146 struct wbcDomainSid sid
;
1150 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1151 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1152 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1153 wbcErrorString(wbc_status
));
1157 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
1158 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1159 d_fprintf(stderr
, "failed to call wbcRemoveUidMapping: %s\n",
1160 wbcErrorString(wbc_status
));
1164 /* Display response */
1166 d_printf("Removed uid %u to sid %s mapping\n",
1167 (unsigned int)uid
, sid_str
);
1172 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
1174 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1175 struct wbcDomainSid sid
;
1179 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1180 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1181 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1182 wbcErrorString(wbc_status
));
1186 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
1187 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1188 d_fprintf(stderr
, "failed to call wbcRemoveGidMapping: %s\n",
1189 wbcErrorString(wbc_status
));
1193 /* Display response */
1195 d_printf("Removed gid %u to sid %s mapping\n",
1196 (unsigned int)gid
, sid_str
);
1201 /* Convert sid to string */
1203 static bool wbinfo_lookupsid(const char *sid_str
)
1205 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1206 struct wbcDomainSid sid
;
1209 enum wbcSidType type
;
1211 /* Send off request */
1213 wbc_status
= wbcStringToSid(sid_str
, &sid
);
1214 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1215 d_fprintf(stderr
, "failed to call wbcStringToSid: %s\n",
1216 wbcErrorString(wbc_status
));
1220 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
1221 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1222 d_fprintf(stderr
, "failed to call wbcLookupSid: %s\n",
1223 wbcErrorString(wbc_status
));
1227 /* Display response */
1229 d_printf("%s%c%s %d\n",
1230 domain
, winbind_separator(), name
, type
);
1232 wbcFreeMemory(domain
);
1233 wbcFreeMemory(name
);
1238 /* Convert sid to fullname */
1240 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
1242 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1243 struct wbcDomainSid sid
;
1246 enum wbcSidType type
;
1248 /* Send off request */
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
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
1258 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1259 d_fprintf(stderr
, "failed to call wbcGetDisplayName: %s\n",
1260 wbcErrorString(wbc_status
));
1264 /* Display response */
1266 d_printf("%s%c%s %d\n",
1267 domain
, winbind_separator(), name
, type
);
1269 wbcFreeMemory(domain
);
1270 wbcFreeMemory(name
);
1275 /* Lookup a list of RIDs */
1277 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
1279 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1280 struct wbcDomainInfo
*dinfo
= NULL
;
1281 char *domain_name
= NULL
;
1282 const char **names
= NULL
;
1283 enum wbcSidType
*types
= NULL
;
1286 uint32_t *rids
= NULL
;
1289 TALLOC_CTX
*mem_ctx
= NULL
;
1292 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')){
1293 domain
= get_winbind_domain();
1298 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
1299 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1300 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
1301 wbcErrorString(wbc_status
));
1305 mem_ctx
= talloc_new(NULL
);
1306 if (mem_ctx
== NULL
) {
1307 d_printf("talloc_new failed\n");
1315 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
1316 uint32_t rid
= strtoul(ridstr
, NULL
, 10);
1317 rids
= talloc_realloc(mem_ctx
, rids
, uint32_t, num_rids
+ 1);
1319 d_printf("talloc_realloc failed\n");
1321 rids
[num_rids
] = rid
;
1326 d_printf("no rids\n");
1330 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
1331 (const char **)&domain_name
, &names
, &types
);
1332 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1333 d_printf("winbind_lookup_rids failed: %s\n",
1334 wbcErrorString(wbc_status
));
1338 d_printf("Domain: %s\n", domain_name
);
1340 for (i
=0; i
<num_rids
; i
++) {
1341 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
1342 wbcSidTypeString(types
[i
]));
1347 wbcFreeMemory(dinfo
);
1348 wbcFreeMemory(domain_name
);
1349 wbcFreeMemory(names
);
1350 wbcFreeMemory(types
);
1351 TALLOC_FREE(mem_ctx
);
1355 static bool wbinfo_lookup_sids(const char *arg
)
1357 char sidstr
[WBC_SID_STRING_BUFLEN
];
1358 struct wbcDomainSid
*sids
;
1359 struct wbcDomainInfo
*domains
;
1360 struct wbcTranslatedName
*names
;
1371 while (next_token(&p
, sidstr
, LIST_SEP
, sizeof(sidstr
))) {
1372 sids
= talloc_realloc(talloc_tos(), sids
, struct wbcDomainSid
,
1375 d_fprintf(stderr
, "talloc failed\n");
1378 wbc_status
= wbcStringToSid(sidstr
, &sids
[num_sids
]);
1379 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1380 d_fprintf(stderr
, "wbcSidToString(%s) failed: %s\n",
1381 sidstr
, wbcErrorString(wbc_status
));
1388 wbc_status
= wbcLookupSids(sids
, num_sids
, &domains
, &num_domains
,
1390 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1391 d_fprintf(stderr
, "wbcLookupSids failed: %s\n",
1392 wbcErrorString(wbc_status
));
1397 for (i
=0; i
<num_sids
; i
++) {
1398 wbcSidToStringBuf(&sids
[i
], sidstr
, sizeof(sidstr
));
1400 d_printf("%s -> %s\\%s %d\n", sidstr
,
1401 domains
[names
[i
].domain_index
].short_name
,
1402 names
[i
].name
, names
[i
].type
);
1404 wbcFreeMemory(names
);
1405 wbcFreeMemory(domains
);
1409 /* Convert string to sid */
1411 static bool wbinfo_lookupname(const char *full_name
)
1413 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1414 struct wbcDomainSid sid
;
1415 char sid_str
[WBC_SID_STRING_BUFLEN
];
1416 enum wbcSidType type
;
1417 fstring domain_name
;
1418 fstring account_name
;
1420 /* Send off request */
1422 parse_wbinfo_domain_user(full_name
, domain_name
,
1425 wbc_status
= wbcLookupName(domain_name
, account_name
,
1427 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1428 d_fprintf(stderr
, "failed to call wbcLookupName: %s\n",
1429 wbcErrorString(wbc_status
));
1433 wbcSidToStringBuf(&sid
, sid_str
, sizeof(sid_str
));
1435 /* Display response */
1437 d_printf("%s %s (%d)\n", sid_str
, wbcSidTypeString(type
), type
);
1442 static char *wbinfo_prompt_pass(TALLOC_CTX
*mem_ctx
,
1444 const char *username
)
1447 char buf
[1024] = {0};
1450 prompt
= talloc_asprintf(mem_ctx
, "Enter %s's ", username
);
1455 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1460 prompt
= talloc_asprintf_append(prompt
, "password: ");
1465 rc
= samba_getpass(prompt
, buf
, sizeof(buf
), false, false);
1466 TALLOC_FREE(prompt
);
1471 return talloc_strdup(mem_ctx
, buf
);
1474 /* Authenticate a user with a plaintext password */
1476 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32_t flags
)
1478 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1481 char *password
= NULL
;
1483 char *local_cctype
= NULL
;
1485 struct wbcLogonUserParams params
;
1486 struct wbcLogonUserInfo
*info
;
1487 struct wbcAuthErrorInfo
*error
;
1488 struct wbcUserPasswordPolicyInfo
*policy
;
1489 TALLOC_CTX
*frame
= talloc_tos();
1491 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1495 if ((p
= strchr(s
, '%')) != NULL
) {
1498 password
= talloc_strdup(frame
, p
);
1500 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1503 local_cctype
= talloc_strdup(frame
, cctype
);
1509 params
.username
= name
;
1510 params
.password
= password
;
1511 params
.num_blobs
= 0;
1512 params
.blobs
= NULL
;
1514 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1520 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1521 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1522 wbcErrorString(wbc_status
));
1526 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1532 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1533 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1534 wbcErrorString(wbc_status
));
1538 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
,
1542 (uint8_t *)local_cctype
,
1544 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1545 d_fprintf(stderr
, "failed to call wbcAddNamedBlob: %s\n",
1546 wbcErrorString(wbc_status
));
1550 wbc_status
= wbcLogonUser(¶ms
, &info
, &error
, &policy
);
1552 d_printf("plaintext kerberos password authentication for [%s] %s "
1553 "(requesting cctype: %s)\n",
1554 username
, WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed",
1559 "error code was %s (0x%x)\nerror message was: %s\n",
1562 error
->display_string
);
1565 if (WBC_ERROR_IS_OK(wbc_status
)) {
1566 if (flags
& WBFLAG_PAM_INFO3_TEXT
) {
1567 if (info
&& info
->info
&& info
->info
->user_flags
&
1568 NETLOGON_CACHED_ACCOUNT
) {
1569 d_printf("user_flgs: "
1570 "NETLOGON_CACHED_ACCOUNT\n");
1576 for (i
=0; i
< info
->num_blobs
; i
++) {
1577 if (strequal(info
->blobs
[i
].name
,
1579 d_printf("credentials were put "
1582 info
->blobs
[i
].blob
.data
);
1587 d_printf("no credentials cached\n");
1592 wbcFreeMemory(params
.blobs
);
1594 return WBC_ERROR_IS_OK(wbc_status
);
1597 /* Authenticate a user with a plaintext password */
1599 static bool wbinfo_auth(char *username
)
1601 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1604 char *password
= NULL
;
1606 TALLOC_CTX
*frame
= talloc_tos();
1608 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1612 if ((p
= strchr(s
, '%')) != NULL
) {
1615 password
= talloc_strdup(frame
, p
);
1617 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1622 wbc_status
= wbcAuthenticateUser(name
, password
);
1624 d_printf("plaintext password authentication %s\n",
1625 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1628 if (response
.data
.auth
.nt_status
)
1630 "error code was %s (0x%x)\nerror message was: %s\n",
1631 response
.data
.auth
.nt_status_string
,
1632 response
.data
.auth
.nt_status
,
1633 response
.data
.auth
.error_string
);
1636 return WBC_ERROR_IS_OK(wbc_status
);
1639 /* Authenticate a user with a challenge/response */
1641 static bool wbinfo_auth_crap(char *username
, bool use_ntlmv2
, bool use_lanman
)
1643 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1644 struct wbcAuthUserParams params
;
1645 struct wbcAuthUserInfo
*info
= NULL
;
1646 struct wbcAuthErrorInfo
*err
= NULL
;
1647 DATA_BLOB lm
= data_blob_null
;
1648 DATA_BLOB nt
= data_blob_null
;
1650 fstring name_domain
;
1653 TALLOC_CTX
*frame
= talloc_tos();
1655 p
= strchr(username
, '%');
1659 pass
= talloc_strdup(frame
, p
+ 1);
1661 pass
= wbinfo_prompt_pass(frame
, NULL
, username
);
1664 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1666 params
.account_name
= name_user
;
1667 params
.domain_name
= name_domain
;
1668 params
.workstation_name
= NULL
;
1671 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1672 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1674 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1676 generate_random_buffer(params
.password
.response
.challenge
, 8);
1679 DATA_BLOB server_chal
;
1680 DATA_BLOB names_blob
;
1682 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1684 /* Pretend this is a login to 'us', for blob purposes */
1685 names_blob
= NTLMv2_generate_names_blob(NULL
,
1686 get_winbind_netbios_name(),
1687 get_winbind_domain());
1689 if (!SMBNTLMv2encrypt(NULL
, name_user
, name_domain
, pass
,
1692 &lm
, &nt
, NULL
, NULL
)) {
1693 data_blob_free(&names_blob
);
1694 data_blob_free(&server_chal
);
1698 data_blob_free(&names_blob
);
1699 data_blob_free(&server_chal
);
1704 lm
= data_blob(NULL
, 24);
1705 ok
= SMBencrypt(pass
,
1706 params
.password
.response
.challenge
,
1709 data_blob_free(&lm
);
1712 nt
= data_blob(NULL
, 24);
1713 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1717 params
.password
.response
.nt_length
= nt
.length
;
1718 params
.password
.response
.nt_data
= nt
.data
;
1719 params
.password
.response
.lm_length
= lm
.length
;
1720 params
.password
.response
.lm_data
= lm
.data
;
1722 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1724 /* Display response */
1726 d_printf("challenge/response password authentication %s\n",
1727 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1729 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1731 "error code was %s (0x%x)\nerror message was: %s\n",
1734 err
->display_string
);
1736 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1737 wbcFreeMemory(info
);
1740 data_blob_free(&nt
);
1741 data_blob_free(&lm
);
1743 return WBC_ERROR_IS_OK(wbc_status
);
1746 /* Authenticate a user with a plaintext password */
1748 static bool wbinfo_pam_logon(char *username
)
1750 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1751 struct wbcLogonUserParams params
;
1752 struct wbcAuthErrorInfo
*error
= NULL
;
1755 TALLOC_CTX
*frame
= talloc_tos();
1759 ZERO_STRUCT(params
);
1761 if ((s
= talloc_strdup(frame
, username
)) == NULL
) {
1765 if ((p
= strchr(s
, '%')) != NULL
) {
1768 params
.password
= talloc_strdup(frame
, p
);
1770 params
.password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1772 params
.username
= s
;
1774 flags
= WBFLAG_PAM_CACHED_LOGIN
;
1776 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1778 (uint8_t *)&flags
, sizeof(flags
));
1779 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1780 d_printf("wbcAddNamedBlob failed: %s\n",
1781 wbcErrorString(wbc_status
));
1787 wbc_status
= wbcAddNamedBlob(¶ms
.num_blobs
, ¶ms
.blobs
,
1789 (uint8_t *)&uid
, sizeof(uid
));
1790 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1791 d_printf("wbcAddNamedBlob failed: %s\n",
1792 wbcErrorString(wbc_status
));
1796 wbc_status
= wbcLogonUser(¶ms
, NULL
, &error
, NULL
);
1798 wbcFreeMemory(params
.blobs
);
1800 d_printf("plaintext password authentication %s\n",
1801 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1803 if (!WBC_ERROR_IS_OK(wbc_status
) && (error
!= NULL
)) {
1805 "error code was %s (0x%x)\nerror message was: %s\n",
1807 (int)error
->nt_status
,
1808 error
->display_string
);
1809 wbcFreeMemory(error
);
1811 return WBC_ERROR_IS_OK(wbc_status
);
1814 /* Save creds with winbind */
1816 static bool wbinfo_ccache_save(char *username
)
1818 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1821 char *password
= NULL
;
1823 TALLOC_CTX
*frame
= talloc_stackframe();
1825 s
= talloc_strdup(frame
, username
);
1834 password
= talloc_strdup(frame
, p
);
1836 password
= wbinfo_prompt_pass(frame
, NULL
, username
);
1841 wbc_status
= wbcCredentialSave(name
, password
);
1843 d_printf("saving creds %s\n",
1844 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1848 return WBC_ERROR_IS_OK(wbc_status
);
1851 #ifdef WITH_FAKE_KASERVER
1852 /* Authenticate a user with a plaintext password and set a token */
1854 static bool wbinfo_klog(char *username
)
1856 struct winbindd_request request
;
1857 struct winbindd_response response
;
1861 /* Send off request */
1863 ZERO_STRUCT(request
);
1864 ZERO_STRUCT(response
);
1866 p
= strchr(username
, '%');
1870 fstrcpy(request
.data
.auth
.user
, username
);
1871 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
1874 fstrcpy(request
.data
.auth
.user
, username
);
1875 (void) samba_getpass("Password: ",
1876 request
.data
.auth
.pass
,
1877 sizeof(request
.data
.auth
.pass
),
1881 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
1883 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
,
1886 /* Display response */
1888 d_printf("plaintext password authentication %s\n",
1889 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
1891 if (response
.data
.auth
.nt_status
)
1893 "error code was %s (0x%x)\nerror message was: %s\n",
1894 response
.data
.auth
.nt_status_string
,
1895 response
.data
.auth
.nt_status
,
1896 response
.data
.auth
.error_string
);
1898 if (result
!= NSS_STATUS_SUCCESS
)
1901 if (response
.extra_data
.data
== NULL
) {
1902 d_fprintf(stderr
, "Did not get token data\n");
1906 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
1907 d_fprintf(stderr
, "Could not set token\n");
1911 d_printf("Successfully created AFS token\n");
1915 static bool wbinfo_klog(char *username
)
1917 d_fprintf(stderr
, "No AFS support compiled in.\n");
1922 /* Print domain users */
1924 static bool print_domain_users(const char *domain
)
1926 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1928 uint32_t num_users
= 0;
1929 const char **users
= NULL
;
1931 /* Send request to winbind daemon */
1933 /* '.' is the special sign for our own domain */
1934 if (domain
&& strcmp(domain
, ".") == 0) {
1935 domain
= get_winbind_domain();
1938 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
1939 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1943 for (i
=0; i
< num_users
; i
++) {
1944 d_printf("%s\n", users
[i
]);
1947 wbcFreeMemory(users
);
1952 /* Print domain groups */
1954 static bool print_domain_groups(const char *domain
)
1956 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1958 uint32_t num_groups
= 0;
1959 const char **groups
= NULL
;
1961 /* Send request to winbind daemon */
1963 /* '.' is the special sign for our own domain */
1964 if (domain
&& strcmp(domain
, ".") == 0) {
1965 domain
= get_winbind_domain();
1968 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
1969 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1970 d_fprintf(stderr
, "failed to call wbcListGroups: %s\n",
1971 wbcErrorString(wbc_status
));
1975 for (i
=0; i
< num_groups
; i
++) {
1976 d_printf("%s\n", groups
[i
]);
1979 wbcFreeMemory(groups
);
1984 /* Set the authorised user for winbindd access in secrets.tdb */
1986 static bool wbinfo_set_auth_user(char *username
)
1988 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1989 "See 'net help setauthuser' for details.\n");
1993 static void wbinfo_get_auth_user(void)
1995 d_fprintf(stderr
, "This functionality was moved to the 'net' utility.\n"
1996 "See 'net help getauthuser' for details.\n");
1999 static bool wbinfo_ping(void)
2003 wbc_status
= wbcPing();
2005 /* Display response */
2007 d_printf("Ping to winbindd %s\n",
2008 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2010 return WBC_ERROR_IS_OK(wbc_status
);
2013 static bool wbinfo_change_user_password(const char *username
)
2016 char *old_password
= NULL
;
2017 char *new_password
= NULL
;
2018 TALLOC_CTX
*frame
= talloc_tos();
2020 old_password
= wbinfo_prompt_pass(frame
, "old", username
);
2021 new_password
= wbinfo_prompt_pass(frame
, "new", username
);
2023 wbc_status
= wbcChangeUserPassword(username
, old_password
,new_password
);
2025 /* Display response */
2027 d_printf("Password change for user %s %s\n", username
,
2028 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
2030 return WBC_ERROR_IS_OK(wbc_status
);
2036 OPT_SET_AUTH_USER
= 1000,
2049 OPT_SET_UID_MAPPING
,
2050 OPT_SET_GID_MAPPING
,
2051 OPT_REMOVE_UID_MAPPING
,
2052 OPT_REMOVE_GID_MAPPING
,
2055 OPT_LIST_ALL_DOMAINS
,
2056 OPT_LIST_OWN_DOMAIN
,
2063 OPT_CHANGE_USER_PASSWORD
,
2065 OPT_SID_TO_FULLNAME
,
2074 int main(int argc
, char **argv
, char **envp
)
2077 TALLOC_CTX
*frame
= talloc_stackframe();
2079 static char *string_arg
;
2080 char *string_subarg
= NULL
;
2081 static char *opt_domain_name
;
2083 int int_subarg
= -1;
2085 bool verbose
= false;
2086 bool use_ntlmv2
= false;
2087 bool use_lanman
= false;
2088 char *logoff_user
= getenv("USER");
2089 int logoff_uid
= geteuid();
2091 struct poptOption long_options
[] = {
2094 /* longName, shortName, argInfo, argPtr, value, descrip,
2097 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
2098 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
2099 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
2100 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
2101 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
2102 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
2103 { "sid-to-fullname", 0, POPT_ARG_STRING
, &string_arg
,
2104 OPT_SID_TO_FULLNAME
, "Converts sid to fullname", "SID" },
2105 { "lookup-rids", 'R', POPT_ARG_STRING
, &string_arg
, 'R', "Converts RIDs to names", "RIDs" },
2106 { "lookup-sids", 0, POPT_ARG_STRING
, &string_arg
,
2107 OPT_LOOKUP_SIDS
, "Converts SIDs to types and names",
2109 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
2110 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
2111 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
2112 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
2113 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
2114 "Get a new UID out of idmap" },
2115 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
2116 "Get a new GID out of idmap" },
2117 { "set-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_UID_MAPPING
, "Create or modify uid to sid mapping in idmap", "UID,SID" },
2118 { "set-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_GID_MAPPING
, "Create or modify gid to sid mapping in idmap", "GID,SID" },
2119 { "remove-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_UID_MAPPING
, "Remove uid to sid mapping in idmap", "UID,SID" },
2120 { "remove-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_GID_MAPPING
, "Remove gid to sid mapping in idmap", "GID,SID" },
2121 { "sids-to-unix-ids", 0, POPT_ARG_STRING
, &string_arg
,
2122 OPT_SIDS_TO_XIDS
, "Translate SIDs to Unix IDs", "Sid-List" },
2123 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
2124 { "change-secret", 'c', POPT_ARG_NONE
, 0, 'c', "Change shared secret" },
2125 { "ping-dc", 'P', POPT_ARG_NONE
, 0, 'P',
2126 "Check the NETLOGON connection" },
2127 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
2128 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
2129 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
2130 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Deprecated command, see --online-status" },
2131 { "online-status", 0, POPT_ARG_NONE
, 0, OPT_ONLINESTATUS
, "Show whether domains are marked as online or offline"},
2132 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
2133 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
2134 { "uid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_UID_INFO
, "Get user info from uid", "UID" },
2135 { "group-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_GROUP_INFO
, "Get group info", "GROUP" },
2136 { "user-sidinfo", 0, POPT_ARG_STRING
, &string_arg
, OPT_USER_SIDINFO
, "Get user info from sid", "SID" },
2137 { "gid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_GID_INFO
, "Get group info from gid", "GID" },
2138 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
2139 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
2140 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
2141 { "sid-aliases", 0, POPT_ARG_STRING
, &string_arg
, OPT_SIDALIASES
, "Get sid aliases", "SID" },
2142 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
2143 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
2144 { "pam-logon", 0, POPT_ARG_STRING
, &string_arg
, OPT_PAM_LOGON
,
2145 "do a pam logon equivalent", "user%password" },
2146 { "logoff", 0, POPT_ARG_NONE
, NULL
, OPT_LOGOFF
,
2147 "log off user", "uid" },
2148 { "logoff-user", 0, POPT_ARG_STRING
, &logoff_user
,
2149 OPT_LOGOFF_USER
, "username to log off" },
2150 { "logoff-uid", 0, POPT_ARG_INT
, &logoff_uid
,
2151 OPT_LOGOFF_UID
, "uid to log off" },
2152 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
2153 { "ccache-save", 0, POPT_ARG_STRING
, &string_arg
,
2154 OPT_CCACHE_SAVE
, "Store user and password for ccache "
2155 "operation", "user%password" },
2156 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
2157 "Get a DC name for a foreign domain", "domainname" },
2158 { "dsgetdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_DSGETDCNAME
, "Find a DC for a domain", "domainname" },
2159 { "dc-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_DC_INFO
,
2160 "Find the currently known DCs", "domainname" },
2161 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
2162 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
2163 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
2164 #ifdef WITH_FAKE_KASERVER
2165 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
2168 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
2169 /* destroys wbinfo --help output */
2170 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
2172 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
2173 { "verbose", 0, POPT_ARG_NONE
, 0, OPT_VERBOSE
, "Print additional information per command", NULL
},
2174 { "change-user-password", 0, POPT_ARG_STRING
, &string_arg
, OPT_CHANGE_USER_PASSWORD
, "Change the password for a user", NULL
},
2175 { "ntlmv2", 0, POPT_ARG_NONE
, 0, OPT_NTLMV2
, "Use NTLMv2 cryptography for user authentication", NULL
},
2176 { "lanman", 0, POPT_ARG_NONE
, 0, OPT_LANMAN
, "Use lanman cryptography for user authentication", NULL
},
2181 /* Samba client initialisation */
2187 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
,
2190 /* Parse command line options */
2193 poptPrintHelp(pc
, stderr
, 0);
2197 while((opt
= poptGetNextOpt(pc
)) != -1) {
2198 /* get the generic configuration parameters like --domain */
2212 poptFreeContext(pc
);
2214 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
2215 POPT_CONTEXT_KEEP_FIRST
);
2217 while((opt
= poptGetNextOpt(pc
)) != -1) {
2220 if (!print_domain_users(opt_domain_name
)) {
2222 "Error looking up domain users\n");
2227 if (!print_domain_groups(opt_domain_name
)) {
2229 "Error looking up domain groups\n");
2234 if (!wbinfo_lookupsid(string_arg
)) {
2236 "Could not lookup sid %s\n",
2241 case OPT_SID_TO_FULLNAME
:
2242 if (!wbinfo_lookupsid_fullname(string_arg
)) {
2243 d_fprintf(stderr
, "Could not lookup sid %s\n",
2249 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
2250 d_fprintf(stderr
, "Could not lookup RIDs %s\n",
2255 case OPT_LOOKUP_SIDS
:
2256 if (!wbinfo_lookup_sids(string_arg
)) {
2257 d_fprintf(stderr
, "Could not lookup SIDs %s\n",
2263 if (!wbinfo_lookupname(string_arg
)) {
2264 d_fprintf(stderr
, "Could not lookup name %s\n",
2270 if (!wbinfo_wins_byname(string_arg
)) {
2272 "Could not lookup WINS by name %s\n",
2278 if (!wbinfo_wins_byip(string_arg
)) {
2280 "Could not lookup WINS by IP %s\n",
2286 if (!wbinfo_uid_to_sid(int_arg
)) {
2288 "Could not convert uid %d to sid\n",
2294 if (!wbinfo_gid_to_sid(int_arg
)) {
2296 "Could not convert gid %d to sid\n",
2302 if (!wbinfo_sid_to_uid(string_arg
)) {
2304 "Could not convert sid %s to uid\n",
2310 if (!wbinfo_sid_to_gid(string_arg
)) {
2312 "Could not convert sid %s to gid\n",
2317 case OPT_ALLOCATE_UID
:
2318 if (!wbinfo_allocate_uid()) {
2319 d_fprintf(stderr
, "Could not allocate a uid\n");
2323 case OPT_ALLOCATE_GID
:
2324 if (!wbinfo_allocate_gid()) {
2325 d_fprintf(stderr
, "Could not allocate a gid\n");
2329 case OPT_SET_UID_MAPPING
:
2330 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2332 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
2334 d_fprintf(stderr
, "Could not create or modify "
2335 "uid to sid mapping\n");
2339 case OPT_SET_GID_MAPPING
:
2340 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2342 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
2344 d_fprintf(stderr
, "Could not create or modify "
2345 "gid to sid mapping\n");
2349 case OPT_REMOVE_UID_MAPPING
:
2350 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2352 !wbinfo_remove_uid_mapping(int_subarg
,
2355 d_fprintf(stderr
, "Could not remove uid to sid "
2360 case OPT_REMOVE_GID_MAPPING
:
2361 if (!parse_mapping_arg(string_arg
, &int_subarg
,
2363 !wbinfo_remove_gid_mapping(int_subarg
,
2366 d_fprintf(stderr
, "Could not remove gid to sid "
2371 case OPT_SIDS_TO_XIDS
:
2372 if (!wbinfo_sids_to_unix_ids(string_arg
)) {
2373 d_fprintf(stderr
, "wbinfo_sids_to_unix_ids "
2379 if (!wbinfo_check_secret(opt_domain_name
)) {
2380 d_fprintf(stderr
, "Could not check secret\n");
2385 if (!wbinfo_change_secret(opt_domain_name
)) {
2386 d_fprintf(stderr
, "Could not change secret\n");
2391 if (!wbinfo_ping_dc()) {
2396 if (!wbinfo_list_domains(false, verbose
)) {
2398 "Could not list trusted domains\n");
2403 if (!wbinfo_show_sequence(opt_domain_name
)) {
2405 "Could not show sequence numbers\n");
2409 case OPT_ONLINESTATUS
:
2410 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
2412 "Could not show online-status\n");
2417 if (!wbinfo_domain_info(string_arg
)) {
2419 "Could not get domain info\n");
2424 if (!wbinfo_get_userinfo(string_arg
)) {
2426 "Could not get info for user %s\n",
2431 case OPT_USER_SIDINFO
:
2432 if ( !wbinfo_get_user_sidinfo(string_arg
)) {
2434 "Could not get info for user "
2435 "sid %s\n", string_arg
);
2440 if ( !wbinfo_get_uidinfo(int_arg
)) {
2441 d_fprintf(stderr
, "Could not get info for uid "
2446 case OPT_GROUP_INFO
:
2447 if ( !wbinfo_get_groupinfo(string_arg
)) {
2448 d_fprintf(stderr
, "Could not get info for "
2449 "group %s\n", string_arg
);
2454 if ( !wbinfo_get_gidinfo(int_arg
)) {
2455 d_fprintf(stderr
, "Could not get info for gid "
2461 if (!wbinfo_get_usergroups(string_arg
)) {
2463 "Could not get groups for user %s\n",
2469 if (!wbinfo_get_usersids(string_arg
)) {
2470 d_fprintf(stderr
, "Could not get group SIDs "
2471 "for user SID %s\n",
2476 case OPT_USERDOMGROUPS
:
2477 if (!wbinfo_get_userdomgroups(string_arg
)) {
2478 d_fprintf(stderr
, "Could not get user's domain "
2479 "groups for user SID %s\n",
2484 case OPT_SIDALIASES
:
2485 if (!wbinfo_get_sidaliases(opt_domain_name
,
2487 d_fprintf(stderr
, "Could not get sid aliases "
2488 "for user SID %s\n", string_arg
);
2493 bool got_error
= false;
2495 if (!wbinfo_auth(string_arg
)) {
2497 "Could not authenticate user "
2498 "%s with plaintext "
2499 "password\n", string_arg
);
2503 if (!wbinfo_auth_crap(string_arg
, use_ntlmv2
,
2506 "Could not authenticate user "
2507 "%s with challenge/response\n",
2517 if (!wbinfo_pam_logon(string_arg
)) {
2518 d_fprintf(stderr
, "pam_logon failed for %s\n",
2527 wbc_status
= wbcLogoffUser(logoff_user
, logoff_uid
,
2529 d_printf("Logoff %s (%d): %s\n", logoff_user
,
2530 logoff_uid
, wbcErrorString(wbc_status
));
2534 uint32_t flags
= WBFLAG_PAM_KRB5
|
2535 WBFLAG_PAM_CACHED_LOGIN
|
2536 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
2537 WBFLAG_PAM_INFO3_TEXT
|
2538 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2540 if (!wbinfo_auth_krb5(string_arg
, "FILE",
2543 "Could not authenticate user "
2544 "[%s] with Kerberos "
2545 "(ccache: %s)\n", string_arg
,
2552 if (!wbinfo_klog(string_arg
)) {
2553 d_fprintf(stderr
, "Could not klog user\n");
2558 if (!wbinfo_ping()) {
2559 d_fprintf(stderr
, "could not ping winbindd!\n");
2563 case OPT_SET_AUTH_USER
:
2564 if (!wbinfo_set_auth_user(string_arg
)) {
2568 case OPT_GET_AUTH_USER
:
2569 wbinfo_get_auth_user();
2572 case OPT_CCACHE_SAVE
:
2573 if (!wbinfo_ccache_save(string_arg
)) {
2578 if (!wbinfo_getdcname(string_arg
)) {
2582 case OPT_DSGETDCNAME
:
2583 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
2588 if (!wbinfo_dc_info(string_arg
)) {
2592 case OPT_SEPARATOR
: {
2593 const char sep
= winbind_separator();
2597 d_printf("%c\n", sep
);
2600 case OPT_LIST_ALL_DOMAINS
:
2601 if (!wbinfo_list_domains(true, verbose
)) {
2605 case OPT_LIST_OWN_DOMAIN
:
2606 if (!wbinfo_list_own_domain()) {
2610 case OPT_CHANGE_USER_PASSWORD
:
2611 if (!wbinfo_change_user_password(string_arg
)) {
2613 "Could not change user password "
2614 "for user %s\n", string_arg
);
2619 /* generic configuration options */
2620 case OPT_DOMAIN_NAME
:
2624 case OPT_LOGOFF_USER
:
2625 case OPT_LOGOFF_UID
:
2628 d_fprintf(stderr
, "Invalid option\n");
2629 poptPrintHelp(pc
, stderr
, 0);
2641 poptFreeContext(pc
);