2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "winbind_client.h"
25 #include "libwbclient/wbclient.h"
28 #define DBGC_CLASS DBGC_WINBIND
30 static struct wbcInterfaceDetails
*init_interface_details(void)
32 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
33 static struct wbcInterfaceDetails
*details
;
39 wbc_status
= wbcInterfaceDetails(&details
);
40 if (!WBC_ERROR_IS_OK(wbc_status
)) {
41 d_fprintf(stderr
, "could not obtain winbind interface details!\n");
47 static char winbind_separator_int(bool strict
)
49 struct wbcInterfaceDetails
*details
;
56 details
= init_interface_details();
59 d_fprintf(stderr
, "could not obtain winbind separator!\n");
63 /* HACK: (this module should not call lp_ funtions) */
64 return *lp_winbind_separator();
67 sep
= details
->winbind_separator
;
71 d_fprintf(stderr
, "winbind separator was NULL!\n");
75 /* HACK: (this module should not call lp_ funtions) */
76 sep
= *lp_winbind_separator();
82 static char winbind_separator(void)
84 return winbind_separator_int(false);
87 static const char *get_winbind_domain(void)
89 static struct wbcInterfaceDetails
*details
;
91 details
= init_interface_details();
94 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
96 /* HACK: (this module should not call lp_ functions) */
97 return lp_workgroup();
100 return details
->netbios_domain
;
103 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
104 form DOMAIN/user into a domain and a user */
106 static bool parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
110 char *p
= strchr(domuser
,winbind_separator());
113 /* Maybe it was a UPN? */
114 if ((p
= strchr(domuser
, '@')) != NULL
) {
116 fstrcpy(user
, domuser
);
120 fstrcpy(user
, domuser
);
121 fstrcpy(domain
, get_winbind_domain());
126 fstrcpy(domain
, domuser
);
127 domain
[PTR_DIFF(p
, domuser
)] = 0;
133 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
134 * Return true if input was valid, false otherwise. */
135 static bool parse_mapping_arg(char *arg
, int *id
, char **sid
)
142 tmp
= strtok(arg
, ",");
143 *sid
= strtok(NULL
, ",");
145 if (!tmp
|| !*tmp
|| !*sid
|| !**sid
)
148 /* Because atoi() can return 0 on invalid input, which would be a valid
149 * UID/GID we must use strtol() and do error checking */
150 *id
= strtol(tmp
, &endptr
, 10);
152 if (endptr
[0] != '\0')
158 /* pull pwent info for a given user */
160 static bool wbinfo_get_userinfo(char *user
)
162 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
163 struct passwd
*pwd
= NULL
;
165 wbc_status
= wbcGetpwnam(user
, &pwd
);
166 if (!WBC_ERROR_IS_OK(wbc_status
)) {
170 d_printf("%s:%s:%d:%d:%s:%s:%s\n",
182 /* pull pwent info for a given uid */
183 static bool wbinfo_get_uidinfo(int uid
)
185 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
186 struct passwd
*pwd
= NULL
;
188 wbc_status
= wbcGetpwuid(uid
, &pwd
);
189 if (!WBC_ERROR_IS_OK(wbc_status
)) {
193 d_printf("%s:%s:%d:%d:%s:%s:%s\n",
205 /* pull grent for a given group */
206 static bool wbinfo_get_groupinfo(const char *group
)
208 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
211 wbc_status
= wbcGetgrnam(group
, &grp
);
212 if (!WBC_ERROR_IS_OK(wbc_status
)) {
216 d_printf("%s:%s:%d\n",
226 /* List groups a user is a member of */
228 static bool wbinfo_get_usergroups(const char *user
)
230 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
233 gid_t
*groups
= NULL
;
237 wbc_status
= wbcGetGroups(user
, &num_groups
, &groups
);
238 if (!WBC_ERROR_IS_OK(wbc_status
)) {
242 for (i
= 0; i
< num_groups
; i
++) {
243 d_printf("%d\n", (int)groups
[i
]);
246 wbcFreeMemory(groups
);
252 /* List group SIDs a user SID is a member of */
253 static bool wbinfo_get_usersids(const char *user_sid_str
)
255 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
258 struct wbcDomainSid user_sid
, *sids
= NULL
;
262 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
263 if (!WBC_ERROR_IS_OK(wbc_status
)) {
267 wbc_status
= wbcLookupUserSids(&user_sid
, false, &num_sids
, &sids
);
268 if (!WBC_ERROR_IS_OK(wbc_status
)) {
272 for (i
= 0; i
< num_sids
; i
++) {
274 wbc_status
= wbcSidToString(&sids
[i
], &str
);
275 if (!WBC_ERROR_IS_OK(wbc_status
)) {
279 d_printf("%s\n", str
);
288 static bool wbinfo_get_userdomgroups(const char *user_sid_str
)
290 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
293 struct wbcDomainSid user_sid
, *sids
= NULL
;
297 wbc_status
= wbcStringToSid(user_sid_str
, &user_sid
);
298 if (!WBC_ERROR_IS_OK(wbc_status
)) {
302 wbc_status
= wbcLookupUserSids(&user_sid
, true, &num_sids
, &sids
);
303 if (!WBC_ERROR_IS_OK(wbc_status
)) {
307 for (i
= 0; i
< num_sids
; i
++) {
309 wbc_status
= wbcSidToString(&sids
[i
], &str
);
310 if (!WBC_ERROR_IS_OK(wbc_status
)) {
314 d_printf("%s\n", str
);
323 /* Convert NetBIOS name to IP */
325 static bool wbinfo_wins_byname(const char *name
)
327 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
330 wbc_status
= wbcResolveWinsByName(name
, &ip
);
331 if (!WBC_ERROR_IS_OK(wbc_status
)) {
335 /* Display response */
337 d_printf("%s\n", ip
);
344 /* Convert IP to NetBIOS name */
346 static bool wbinfo_wins_byip(const char *ip
)
348 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
351 wbc_status
= wbcResolveWinsByIP(ip
, &name
);
352 if (!WBC_ERROR_IS_OK(wbc_status
)) {
356 /* Display response */
358 d_printf("%s\n", name
);
365 /* List all/trusted domains */
367 static bool wbinfo_list_domains(bool list_all_domains
, bool verbose
)
369 struct wbcDomainInfo
*domain_list
= NULL
;
371 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
372 bool print_all
= !list_all_domains
&& verbose
;
375 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
376 if (!WBC_ERROR_IS_OK(wbc_status
)) {
381 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
382 "Domain Name", "DNS Domain", "Trust Type",
383 "Transitive", "In", "Out");
386 for (i
=0; i
<num_domains
; i
++) {
388 d_printf("%-16s", domain_list
[i
].short_name
);
390 d_printf("%s", domain_list
[i
].short_name
);
395 d_printf("%-24s", domain_list
[i
].dns_name
);
397 switch(domain_list
[i
].trust_type
) {
398 case WBC_DOMINFO_TRUSTTYPE_NONE
:
401 case WBC_DOMINFO_TRUSTTYPE_FOREST
:
404 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL
:
405 d_printf("External ");
407 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST
:
408 d_printf("In-Forest ");
412 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_TRANSITIVE
) {
418 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_INCOMING
) {
424 if (domain_list
[i
].trust_flags
& WBC_DOMINFO_TRUST_OUTGOING
) {
436 /* List own domain */
438 static bool wbinfo_list_own_domain(void)
440 d_printf("%s\n", get_winbind_domain());
445 /* show sequence numbers */
446 static bool wbinfo_show_sequence(const char *domain
)
448 d_printf("This command has been deprecated. Please use the --online-status option instead.\n");
452 /* show sequence numbers */
453 static bool wbinfo_show_onlinestatus(const char *domain
)
455 struct wbcDomainInfo
*domain_list
= NULL
;
457 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
460 wbc_status
= wbcListTrusts(&domain_list
, &num_domains
);
461 if (!WBC_ERROR_IS_OK(wbc_status
)) {
465 for (i
=0; i
<num_domains
; i
++) {
469 if (!strequal(domain_list
[i
].short_name
, domain
)) {
474 is_offline
= (domain_list
[i
].domain_flags
& WBC_DOMINFO_DOMAIN_OFFLINE
);
476 d_printf("%s : %s\n",
477 domain_list
[i
].short_name
,
478 is_offline
? "offline" : "online" );
485 /* Show domain info */
487 static bool wbinfo_domain_info(const char *domain
)
489 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
490 struct wbcDomainInfo
*dinfo
= NULL
;
491 char *sid_str
= NULL
;
493 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')) {
494 domain
= get_winbind_domain();
499 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
500 if (!WBC_ERROR_IS_OK(wbc_status
)) {
504 wbc_status
= wbcSidToString(&dinfo
->sid
, &sid_str
);
505 if (!WBC_ERROR_IS_OK(wbc_status
)) {
506 wbcFreeMemory(dinfo
);
510 /* Display response */
512 d_printf("Name : %s\n", dinfo
->short_name
);
513 d_printf("Alt_Name : %s\n", dinfo
->dns_name
);
515 d_printf("SID : %s\n", sid_str
);
517 d_printf("Active Directory : %s\n",
518 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_AD
) ? "Yes" : "No");
519 d_printf("Native : %s\n",
520 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_NATIVE
) ? "Yes" : "No");
522 d_printf("Primary : %s\n",
523 (dinfo
->domain_flags
& WBC_DOMINFO_DOMAIN_PRIMARY
) ? "Yes" : "No");
525 wbcFreeMemory(sid_str
);
526 wbcFreeMemory(dinfo
);
531 /* Get a foreign DC's name */
532 static bool wbinfo_getdcname(const char *domain_name
)
534 struct winbindd_request request
;
535 struct winbindd_response response
;
537 ZERO_STRUCT(request
);
538 ZERO_STRUCT(response
);
540 fstrcpy(request
.domain_name
, domain_name
);
544 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
, &response
) !=
545 NSS_STATUS_SUCCESS
) {
546 d_fprintf(stderr
, "Could not get dc name for %s\n", domain_name
);
550 /* Display response */
552 d_printf("%s\n", response
.data
.dc_name
);
558 static bool wbinfo_dsgetdcname(const char *domain_name
, uint32_t flags
)
560 struct winbindd_request request
;
561 struct winbindd_response response
;
563 ZERO_STRUCT(request
);
564 ZERO_STRUCT(response
);
566 fstrcpy(request
.data
.dsgetdcname
.domain_name
, domain_name
);
567 request
.data
.dsgetdcname
.flags
= flags
;
569 request
.flags
|= DS_DIRECTORY_SERVICE_REQUIRED
;
573 if (winbindd_request_response(WINBINDD_DSGETDCNAME
, &request
, &response
) !=
574 NSS_STATUS_SUCCESS
) {
575 d_fprintf(stderr
, "Could not find dc for %s\n", domain_name
);
579 /* Display response */
581 d_printf("%s\n", response
.data
.dsgetdcname
.dc_unc
);
582 d_printf("%s\n", response
.data
.dsgetdcname
.dc_address
);
583 d_printf("%d\n", response
.data
.dsgetdcname
.dc_address_type
);
584 d_printf("%s\n", response
.data
.dsgetdcname
.domain_guid
);
585 d_printf("%s\n", response
.data
.dsgetdcname
.domain_name
);
586 d_printf("%s\n", response
.data
.dsgetdcname
.forest_name
);
587 d_printf("0x%08x\n", response
.data
.dsgetdcname
.dc_flags
);
588 d_printf("%s\n", response
.data
.dsgetdcname
.dc_site_name
);
589 d_printf("%s\n", response
.data
.dsgetdcname
.client_site_name
);
594 /* Check trust account password */
596 static bool wbinfo_check_secret(void)
598 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
599 struct wbcAuthErrorInfo
*error
= NULL
;
601 wbc_status
= wbcCheckTrustCredentials(NULL
, &error
);
603 d_printf("checking the trust secret via RPC calls %s\n",
604 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
606 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
607 d_fprintf(stderr
, "error code was %s (0x%x)\n",
608 error
->nt_string
, error
->nt_status
);
609 wbcFreeMemory(error
);
611 if (!WBC_ERROR_IS_OK(wbc_status
)) {
618 /* Convert uid to sid */
620 static bool wbinfo_uid_to_sid(uid_t uid
)
622 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
623 struct wbcDomainSid sid
;
624 char *sid_str
= NULL
;
628 wbc_status
= wbcUidToSid(uid
, &sid
);
629 if (!WBC_ERROR_IS_OK(wbc_status
)) {
633 wbc_status
= wbcSidToString(&sid
, &sid_str
);
634 if (!WBC_ERROR_IS_OK(wbc_status
)) {
638 /* Display response */
640 d_printf("%s\n", sid_str
);
642 wbcFreeMemory(sid_str
);
647 /* Convert gid to sid */
649 static bool wbinfo_gid_to_sid(gid_t gid
)
651 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
652 struct wbcDomainSid sid
;
653 char *sid_str
= NULL
;
657 wbc_status
= wbcGidToSid(gid
, &sid
);
658 if (!WBC_ERROR_IS_OK(wbc_status
)) {
662 wbc_status
= wbcSidToString(&sid
, &sid_str
);
663 if (!WBC_ERROR_IS_OK(wbc_status
)) {
667 /* Display response */
669 d_printf("%s\n", sid_str
);
671 wbcFreeMemory(sid_str
);
676 /* Convert sid to uid */
678 static bool wbinfo_sid_to_uid(const char *sid_str
)
680 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
681 struct wbcDomainSid sid
;
686 wbc_status
= wbcStringToSid(sid_str
, &sid
);
687 if (!WBC_ERROR_IS_OK(wbc_status
)) {
691 wbc_status
= wbcSidToUid(&sid
, &uid
);
692 if (!WBC_ERROR_IS_OK(wbc_status
)) {
696 /* Display response */
698 d_printf("%d\n", (int)uid
);
703 static bool wbinfo_sid_to_gid(const char *sid_str
)
705 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
706 struct wbcDomainSid sid
;
711 wbc_status
= wbcStringToSid(sid_str
, &sid
);
712 if (!WBC_ERROR_IS_OK(wbc_status
)) {
716 wbc_status
= wbcSidToGid(&sid
, &gid
);
717 if (!WBC_ERROR_IS_OK(wbc_status
)) {
721 /* Display response */
723 d_printf("%d\n", (int)gid
);
728 static bool wbinfo_allocate_uid(void)
730 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
735 wbc_status
= wbcAllocateUid(&uid
);
736 if (!WBC_ERROR_IS_OK(wbc_status
)) {
740 /* Display response */
742 d_printf("New uid: %d\n", uid
);
747 static bool wbinfo_allocate_gid(void)
749 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
754 wbc_status
= wbcAllocateGid(&gid
);
755 if (!WBC_ERROR_IS_OK(wbc_status
)) {
759 /* Display response */
761 d_printf("New gid: %d\n", gid
);
766 static bool wbinfo_set_uid_mapping(uid_t uid
, const char *sid_str
)
768 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
769 struct wbcDomainSid sid
;
773 wbc_status
= wbcStringToSid(sid_str
, &sid
);
774 if (!WBC_ERROR_IS_OK(wbc_status
)) {
778 wbc_status
= wbcSetUidMapping(uid
, &sid
);
779 if (!WBC_ERROR_IS_OK(wbc_status
)) {
783 /* Display response */
785 d_printf("uid %d now mapped to sid %s\n", uid
, sid_str
);
790 static bool wbinfo_set_gid_mapping(gid_t gid
, const char *sid_str
)
792 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
793 struct wbcDomainSid sid
;
797 wbc_status
= wbcStringToSid(sid_str
, &sid
);
798 if (!WBC_ERROR_IS_OK(wbc_status
)) {
802 wbc_status
= wbcSetGidMapping(gid
, &sid
);
803 if (!WBC_ERROR_IS_OK(wbc_status
)) {
807 /* Display response */
809 d_printf("gid %d now mapped to sid %s\n", gid
, sid_str
);
814 static bool wbinfo_remove_uid_mapping(uid_t uid
, const char *sid_str
)
816 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
817 struct wbcDomainSid sid
;
821 wbc_status
= wbcStringToSid(sid_str
, &sid
);
822 if (!WBC_ERROR_IS_OK(wbc_status
)) {
826 wbc_status
= wbcRemoveUidMapping(uid
, &sid
);
827 if (!WBC_ERROR_IS_OK(wbc_status
)) {
831 /* Display response */
833 d_printf("Removed uid %d to sid %s mapping\n", uid
, sid_str
);
838 static bool wbinfo_remove_gid_mapping(gid_t gid
, const char *sid_str
)
840 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
841 struct wbcDomainSid sid
;
845 wbc_status
= wbcStringToSid(sid_str
, &sid
);
846 if (!WBC_ERROR_IS_OK(wbc_status
)) {
850 wbc_status
= wbcRemoveGidMapping(gid
, &sid
);
851 if (!WBC_ERROR_IS_OK(wbc_status
)) {
855 /* Display response */
857 d_printf("Removed gid %d to sid %s mapping\n", gid
, sid_str
);
862 /* Convert sid to string */
864 static bool wbinfo_lookupsid(const char *sid_str
)
866 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
867 struct wbcDomainSid sid
;
870 enum wbcSidType type
;
872 /* Send off request */
874 wbc_status
= wbcStringToSid(sid_str
, &sid
);
875 if (!WBC_ERROR_IS_OK(wbc_status
)) {
879 wbc_status
= wbcLookupSid(&sid
, &domain
, &name
, &type
);
880 if (!WBC_ERROR_IS_OK(wbc_status
)) {
884 /* Display response */
886 d_printf("%s%c%s %d\n",
887 domain
, winbind_separator(), name
, type
);
892 /* Convert sid to fullname */
894 static bool wbinfo_lookupsid_fullname(const char *sid_str
)
896 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
897 struct wbcDomainSid sid
;
900 enum wbcSidType type
;
902 /* Send off request */
904 wbc_status
= wbcStringToSid(sid_str
, &sid
);
905 if (!WBC_ERROR_IS_OK(wbc_status
)) {
909 wbc_status
= wbcGetDisplayName(&sid
, &domain
, &name
, &type
);
910 if (!WBC_ERROR_IS_OK(wbc_status
)) {
914 /* Display response */
916 d_printf("%s%c%s %d\n",
917 domain
, winbind_separator(), name
, type
);
922 /* Lookup a list of RIDs */
924 static bool wbinfo_lookuprids(const char *domain
, const char *arg
)
926 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
927 struct wbcDomainInfo
*dinfo
= NULL
;
928 char *domain_name
= NULL
;
929 const char **names
= NULL
;
930 enum wbcSidType
*types
= NULL
;
936 TALLOC_CTX
*mem_ctx
= NULL
;
939 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0')) {
940 domain
= get_winbind_domain();
945 wbc_status
= wbcDomainInfo(domain
, &dinfo
);
946 if (!WBC_ERROR_IS_OK(wbc_status
)) {
947 d_printf("wbcDomainInfo(%s) failed: %s\n", domain
,
948 wbcErrorString(wbc_status
));
952 mem_ctx
= talloc_new(NULL
);
953 if (mem_ctx
== NULL
) {
954 d_printf("talloc_new failed\n");
962 while (next_token_talloc(mem_ctx
, &p
, &ridstr
, " ,\n")) {
963 uint32 rid
= strtoul(ridstr
, NULL
, 10);
964 ADD_TO_ARRAY(mem_ctx
, uint32
, rid
, &rids
, &num_rids
);
968 d_printf("no rids\n");
972 wbc_status
= wbcLookupRids(&dinfo
->sid
, num_rids
, rids
,
973 (const char **)&domain_name
, &names
, &types
);
974 if (!WBC_ERROR_IS_OK(wbc_status
)) {
975 d_printf("winbind_lookup_rids failed: %s\n",
976 wbcErrorString(wbc_status
));
980 d_printf("Domain: %s\n", domain_name
);
982 for (i
=0; i
<num_rids
; i
++) {
983 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
984 sid_type_lookup(types
[i
]));
990 wbcFreeMemory(dinfo
);
993 wbcFreeMemory(domain_name
);
996 wbcFreeMemory(names
);
999 wbcFreeMemory(types
);
1001 TALLOC_FREE(mem_ctx
);
1005 /* Convert string to sid */
1007 static bool wbinfo_lookupname(const char *full_name
)
1009 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1010 struct wbcDomainSid sid
;
1012 enum wbcSidType type
;
1013 fstring domain_name
;
1014 fstring account_name
;
1016 /* Send off request */
1018 parse_wbinfo_domain_user(full_name
, domain_name
,
1021 wbc_status
= wbcLookupName(domain_name
, account_name
,
1023 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1027 wbc_status
= wbcSidToString(&sid
, &sid_str
);
1028 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1032 /* Display response */
1034 d_printf("%s %s (%d)\n", sid_str
, sid_type_lookup(type
), type
);
1036 wbcFreeMemory(sid_str
);
1041 static char *wbinfo_prompt_pass(const char *prefix
,
1042 const char *username
)
1045 const char *ret
= NULL
;
1047 prompt
= talloc_asprintf(talloc_tos(), "Enter %s's ", username
);
1052 prompt
= talloc_asprintf_append(prompt
, "%s ", prefix
);
1057 prompt
= talloc_asprintf_append(prompt
, "password: ");
1062 ret
= getpass(prompt
);
1063 TALLOC_FREE(prompt
);
1065 return SMB_STRDUP(ret
);
1068 /* Authenticate a user with a plaintext password */
1070 static bool wbinfo_auth_krb5(char *username
, const char *cctype
, uint32 flags
)
1072 struct winbindd_request request
;
1073 struct winbindd_response response
;
1078 /* Send off request */
1080 ZERO_STRUCT(request
);
1081 ZERO_STRUCT(response
);
1083 p
= strchr(username
, '%');
1087 fstrcpy(request
.data
.auth
.user
, username
);
1088 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
1091 fstrcpy(request
.data
.auth
.user
, username
);
1092 password
= wbinfo_prompt_pass(NULL
, username
);
1093 fstrcpy(request
.data
.auth
.pass
, password
);
1094 SAFE_FREE(password
);
1097 request
.flags
= flags
;
1099 fstrcpy(request
.data
.auth
.krb5_cc_type
, cctype
);
1101 request
.data
.auth
.uid
= geteuid();
1103 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
1105 /* Display response */
1107 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
1108 username
, (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", cctype
);
1110 if (response
.data
.auth
.nt_status
)
1111 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
1112 response
.data
.auth
.nt_status_string
,
1113 response
.data
.auth
.nt_status
,
1114 response
.data
.auth
.error_string
);
1116 if (result
== NSS_STATUS_SUCCESS
) {
1118 if (request
.flags
& WBFLAG_PAM_INFO3_TEXT
) {
1119 if (response
.data
.auth
.info3
.user_flgs
& NETLOGON_CACHED_ACCOUNT
) {
1120 d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
1124 if (response
.data
.auth
.krb5ccname
[0] != '\0') {
1125 d_printf("credentials were put in: %s\n", response
.data
.auth
.krb5ccname
);
1127 d_printf("no credentials cached\n");
1131 return result
== NSS_STATUS_SUCCESS
;
1134 /* Authenticate a user with a plaintext password */
1136 static bool wbinfo_auth(char *username
)
1138 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1141 char *password
= NULL
;
1144 if ((s
= SMB_STRDUP(username
)) == NULL
) {
1148 if ((p
= strchr(s
, '%')) != NULL
) {
1151 password
= SMB_STRDUP(p
);
1153 password
= wbinfo_prompt_pass(NULL
, username
);
1158 wbc_status
= wbcAuthenticateUser(name
, password
);
1160 d_printf("plaintext password authentication %s\n",
1161 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1164 if (response
.data
.auth
.nt_status
)
1165 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
1166 response
.data
.auth
.nt_status_string
,
1167 response
.data
.auth
.nt_status
,
1168 response
.data
.auth
.error_string
);
1172 SAFE_FREE(password
);
1174 return WBC_ERROR_IS_OK(wbc_status
);
1177 /* Authenticate a user with a challenge/response */
1179 static bool wbinfo_auth_crap(char *username
)
1181 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1182 struct wbcAuthUserParams params
;
1183 struct wbcAuthUserInfo
*info
= NULL
;
1184 struct wbcAuthErrorInfo
*err
= NULL
;
1185 DATA_BLOB lm
= data_blob_null
;
1186 DATA_BLOB nt
= data_blob_null
;
1188 fstring name_domain
;
1192 p
= strchr(username
, '%');
1196 pass
= SMB_STRDUP(p
+ 1);
1198 pass
= wbinfo_prompt_pass(NULL
, username
);
1201 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
1203 params
.account_name
= name_user
;
1204 params
.domain_name
= name_domain
;
1205 params
.workstation_name
= NULL
;
1208 params
.parameter_control
= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
|
1209 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
1211 params
.level
= WBC_AUTH_USER_LEVEL_RESPONSE
;
1213 generate_random_buffer(params
.password
.response
.challenge
, 8);
1215 if (lp_client_ntlmv2_auth()) {
1216 DATA_BLOB server_chal
;
1217 DATA_BLOB names_blob
;
1219 server_chal
= data_blob(params
.password
.response
.challenge
, 8);
1221 /* Pretend this is a login to 'us', for blob purposes */
1222 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
1224 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
1227 data_blob_free(&names_blob
);
1228 data_blob_free(&server_chal
);
1232 data_blob_free(&names_blob
);
1233 data_blob_free(&server_chal
);
1236 if (lp_client_lanman_auth()) {
1238 lm
= data_blob(NULL
, 24);
1239 ok
= SMBencrypt(pass
, params
.password
.response
.challenge
,
1242 data_blob_free(&lm
);
1245 nt
= data_blob(NULL
, 24);
1246 SMBNTencrypt(pass
, params
.password
.response
.challenge
,
1250 params
.password
.response
.nt_length
= nt
.length
;
1251 params
.password
.response
.nt_data
= nt
.data
;
1252 params
.password
.response
.lm_length
= lm
.length
;
1253 params
.password
.response
.lm_data
= lm
.data
;
1255 wbc_status
= wbcAuthenticateUserEx(¶ms
, &info
, &err
);
1257 /* Display response */
1259 d_printf("challenge/response password authentication %s\n",
1260 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1262 if (wbc_status
== WBC_ERR_AUTH_ERROR
) {
1263 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
1266 err
->display_string
);
1268 } else if (WBC_ERROR_IS_OK(wbc_status
)) {
1269 wbcFreeMemory(info
);
1272 data_blob_free(&nt
);
1273 data_blob_free(&lm
);
1276 return WBC_ERROR_IS_OK(wbc_status
);
1279 /* Authenticate a user with a plaintext password and set a token */
1281 static bool wbinfo_klog(char *username
)
1283 struct winbindd_request request
;
1284 struct winbindd_response response
;
1288 /* Send off request */
1290 ZERO_STRUCT(request
);
1291 ZERO_STRUCT(response
);
1293 p
= strchr(username
, '%');
1297 fstrcpy(request
.data
.auth
.user
, username
);
1298 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
1301 fstrcpy(request
.data
.auth
.user
, username
);
1302 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
1305 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
1307 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
1309 /* Display response */
1311 d_printf("plaintext password authentication %s\n",
1312 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
1314 if (response
.data
.auth
.nt_status
)
1315 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
1316 response
.data
.auth
.nt_status_string
,
1317 response
.data
.auth
.nt_status
,
1318 response
.data
.auth
.error_string
);
1320 if (result
!= NSS_STATUS_SUCCESS
)
1323 if (response
.extra_data
.data
== NULL
) {
1324 d_fprintf(stderr
, "Did not get token data\n");
1328 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
1329 d_fprintf(stderr
, "Could not set token\n");
1333 d_printf("Successfully created AFS token\n");
1337 /* Print domain users */
1339 static bool print_domain_users(const char *domain
)
1341 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1343 uint32_t num_users
= 0;
1344 const char **users
= NULL
;
1346 /* Send request to winbind daemon */
1348 /* '.' is the special sign for our own domain */
1349 if (domain
&& strcmp(domain
, ".") == 0) {
1350 domain
= get_winbind_domain();
1353 wbc_status
= wbcListUsers(domain
, &num_users
, &users
);
1354 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1358 for (i
=0; i
< num_users
; i
++) {
1359 d_printf("%s\n", users
[i
]);
1362 wbcFreeMemory(users
);
1367 /* Print domain groups */
1369 static bool print_domain_groups(const char *domain
)
1371 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
1373 uint32_t num_groups
= 0;
1374 const char **groups
= NULL
;
1376 /* Send request to winbind daemon */
1378 /* '.' is the special sign for our own domain */
1379 if (domain
&& strcmp(domain
, ".") == 0) {
1380 domain
= get_winbind_domain();
1383 wbc_status
= wbcListGroups(domain
, &num_groups
, &groups
);
1384 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1388 for (i
=0; i
< num_groups
; i
++) {
1389 d_printf("%s\n", groups
[i
]);
1392 wbcFreeMemory(groups
);
1397 /* Set the authorised user for winbindd access in secrets.tdb */
1399 static bool wbinfo_set_auth_user(char *username
)
1401 const char *password
;
1403 fstring user
, domain
;
1405 /* Separate into user and password */
1407 parse_wbinfo_domain_user(username
, domain
, user
);
1409 p
= strchr(user
, '%');
1415 char *thepass
= getpass("Password: ");
1422 /* Store or remove DOMAIN\username%password in secrets.tdb */
1428 if (!secrets_store(SECRETS_AUTH_USER
, user
,
1429 strlen(user
) + 1)) {
1430 d_fprintf(stderr
, "error storing username\n");
1434 /* We always have a domain name added by the
1435 parse_wbinfo_domain_user() function. */
1437 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
1438 strlen(domain
) + 1)) {
1439 d_fprintf(stderr
, "error storing domain name\n");
1444 secrets_delete(SECRETS_AUTH_USER
);
1445 secrets_delete(SECRETS_AUTH_DOMAIN
);
1450 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
1451 strlen(password
) + 1)) {
1452 d_fprintf(stderr
, "error storing password\n");
1457 secrets_delete(SECRETS_AUTH_PASSWORD
);
1462 static void wbinfo_get_auth_user(void)
1464 char *user
, *domain
, *password
;
1466 /* Lift data from secrets file */
1468 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1470 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1474 SAFE_FREE(password
);
1475 d_printf("No authorised user configured\n");
1479 /* Pretty print authorised user info */
1481 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1482 user
, password
? "%" : "", password
? password
: "");
1486 SAFE_FREE(password
);
1489 static bool wbinfo_ping(void)
1493 wbc_status
= wbcPing();
1495 /* Display response */
1497 d_printf("Ping to winbindd %s\n",
1498 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1500 return WBC_ERROR_IS_OK(wbc_status
);
1503 static bool wbinfo_change_user_password(const char *username
)
1506 char *old_password
= NULL
;
1507 char *new_password
= NULL
;
1509 old_password
= wbinfo_prompt_pass("old", username
);
1510 new_password
= wbinfo_prompt_pass("new", username
);
1512 wbc_status
= wbcChangeUserPassword(username
, old_password
, new_password
);
1514 /* Display response */
1516 d_printf("Password change for user %s %s\n", username
,
1517 WBC_ERROR_IS_OK(wbc_status
) ? "succeeded" : "failed");
1519 SAFE_FREE(old_password
);
1520 SAFE_FREE(new_password
);
1522 return WBC_ERROR_IS_OK(wbc_status
);
1528 OPT_SET_AUTH_USER
= 1000,
1538 OPT_SET_UID_MAPPING
,
1539 OPT_SET_GID_MAPPING
,
1540 OPT_REMOVE_UID_MAPPING
,
1541 OPT_REMOVE_GID_MAPPING
,
1543 OPT_LIST_ALL_DOMAINS
,
1544 OPT_LIST_OWN_DOMAIN
,
1549 OPT_CHANGE_USER_PASSWORD
,
1553 int main(int argc
, char **argv
, char **envp
)
1556 TALLOC_CTX
*frame
= talloc_stackframe();
1558 static char *string_arg
;
1559 char *string_subarg
= NULL
;
1560 static char *opt_domain_name
;
1562 int int_subarg
= -1;
1564 bool verbose
= false;
1566 struct poptOption long_options
[] = {
1569 /* longName, shortName, argInfo, argPtr, value, descrip,
1572 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1573 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1574 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1575 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1576 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1577 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1578 { "sid-to-fullname", 0, POPT_ARG_STRING
, &string_arg
,
1579 OPT_SID_TO_FULLNAME
, "Converts sid to fullname", "SID" },
1580 { "lookup-rids", 'R', POPT_ARG_STRING
, &string_arg
, 'R', "Converts RIDs to names", "RIDs" },
1581 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1582 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1583 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1584 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1585 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1586 "Get a new UID out of idmap" },
1587 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1588 "Get a new GID out of idmap" },
1589 { "set-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_UID_MAPPING
, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1590 { "set-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_GID_MAPPING
, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1591 { "remove-uid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_UID_MAPPING
, "Remove uid to sid mapping in idmap", "UID,SID" },
1592 { "remove-gid-mapping", 0, POPT_ARG_STRING
, &string_arg
, OPT_REMOVE_GID_MAPPING
, "Remove gid to sid mapping in idmap", "GID,SID" },
1593 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1594 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1595 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1596 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
1597 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1598 { "online-status", 0, POPT_ARG_NONE
, 0, OPT_ONLINESTATUS
, "Show whether domains are marked as online or offline"},
1599 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1600 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1601 { "uid-info", 0, POPT_ARG_INT
, &int_arg
, OPT_UID_INFO
, "Get user info from uid", "UID" },
1602 { "group-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_GROUP_INFO
, "Get group info", "GROUP" },
1603 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1604 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1605 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1606 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1607 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1608 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1609 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1610 "Get a DC name for a foreign domain", "domainname" },
1611 { "dsgetdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_DSGETDCNAME
, "Find a DC for a domain", "domainname" },
1612 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1613 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1614 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1615 #ifdef WITH_FAKE_KASERVER
1616 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1619 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1620 /* destroys wbinfo --help output */
1621 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1623 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1624 { "verbose", 0, POPT_ARG_NONE
, 0, OPT_VERBOSE
, "Print additional information per command", NULL
},
1625 { "change-user-password", 0, POPT_ARG_STRING
, &string_arg
, OPT_CHANGE_USER_PASSWORD
, "Change the password for a user", NULL
},
1626 POPT_COMMON_CONFIGFILE
1631 /* Samba client initialisation */
1637 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1639 /* Parse command line options */
1642 poptPrintHelp(pc
, stderr
, 0);
1646 while((opt
= poptGetNextOpt(pc
)) != -1) {
1647 /* get the generic configuration parameters like --domain */
1655 poptFreeContext(pc
);
1657 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) {
1658 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1659 get_dyn_CONFIGFILE(), strerror(errno
));
1668 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1669 POPT_CONTEXT_KEEP_FIRST
);
1671 while((opt
= poptGetNextOpt(pc
)) != -1) {
1674 if (!print_domain_users(opt_domain_name
)) {
1675 d_fprintf(stderr
, "Error looking up domain users\n");
1680 if (!print_domain_groups(opt_domain_name
)) {
1681 d_fprintf(stderr
, "Error looking up domain groups\n");
1686 if (!wbinfo_lookupsid(string_arg
)) {
1687 d_fprintf(stderr
, "Could not lookup sid %s\n", string_arg
);
1691 case OPT_SID_TO_FULLNAME
:
1692 if (!wbinfo_lookupsid_fullname(string_arg
)) {
1693 d_fprintf(stderr
, "Could not lookup sid %s\n",
1699 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
1700 d_fprintf(stderr
, "Could not lookup RIDs %s\n", string_arg
);
1705 if (!wbinfo_lookupname(string_arg
)) {
1706 d_fprintf(stderr
, "Could not lookup name %s\n", string_arg
);
1711 if (!wbinfo_wins_byname(string_arg
)) {
1712 d_fprintf(stderr
, "Could not lookup WINS by name %s\n", string_arg
);
1717 if (!wbinfo_wins_byip(string_arg
)) {
1718 d_fprintf(stderr
, "Could not lookup WINS by IP %s\n", string_arg
);
1723 if (!wbinfo_uid_to_sid(int_arg
)) {
1724 d_fprintf(stderr
, "Could not convert uid %d to sid\n", int_arg
);
1729 if (!wbinfo_gid_to_sid(int_arg
)) {
1730 d_fprintf(stderr
, "Could not convert gid %d to sid\n",
1736 if (!wbinfo_sid_to_uid(string_arg
)) {
1737 d_fprintf(stderr
, "Could not convert sid %s to uid\n",
1743 if (!wbinfo_sid_to_gid(string_arg
)) {
1744 d_fprintf(stderr
, "Could not convert sid %s to gid\n",
1749 case OPT_ALLOCATE_UID
:
1750 if (!wbinfo_allocate_uid()) {
1751 d_fprintf(stderr
, "Could not allocate a uid\n");
1755 case OPT_ALLOCATE_GID
:
1756 if (!wbinfo_allocate_gid()) {
1757 d_fprintf(stderr
, "Could not allocate a gid\n");
1761 case OPT_SET_UID_MAPPING
:
1762 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1764 !wbinfo_set_uid_mapping(int_subarg
, string_subarg
))
1766 d_fprintf(stderr
, "Could not create or modify "
1767 "uid to sid mapping\n");
1771 case OPT_SET_GID_MAPPING
:
1772 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1774 !wbinfo_set_gid_mapping(int_subarg
, string_subarg
))
1776 d_fprintf(stderr
, "Could not create or modify "
1777 "gid to sid mapping\n");
1781 case OPT_REMOVE_UID_MAPPING
:
1782 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1784 !wbinfo_remove_uid_mapping(int_subarg
,
1787 d_fprintf(stderr
, "Could not remove uid to sid "
1792 case OPT_REMOVE_GID_MAPPING
:
1793 if (!parse_mapping_arg(string_arg
, &int_subarg
,
1795 !wbinfo_remove_gid_mapping(int_subarg
,
1798 d_fprintf(stderr
, "Could not remove gid to sid "
1804 if (!wbinfo_check_secret()) {
1805 d_fprintf(stderr
, "Could not check secret\n");
1810 if (!wbinfo_list_domains(false, verbose
)) {
1811 d_fprintf(stderr
, "Could not list trusted domains\n");
1816 if (!wbinfo_show_sequence(opt_domain_name
)) {
1817 d_fprintf(stderr
, "Could not show sequence numbers\n");
1821 case OPT_ONLINESTATUS
:
1822 if (!wbinfo_show_onlinestatus(opt_domain_name
)) {
1823 d_fprintf(stderr
, "Could not show online-status\n");
1828 if (!wbinfo_domain_info(string_arg
)) {
1829 d_fprintf(stderr
, "Could not get domain info\n");
1834 if (!wbinfo_get_userinfo(string_arg
)) {
1835 d_fprintf(stderr
, "Could not get info for user %s\n",
1841 if ( !wbinfo_get_uidinfo(int_arg
)) {
1842 d_fprintf(stderr
, "Could not get info for uid "
1847 case OPT_GROUP_INFO
:
1848 if ( !wbinfo_get_groupinfo(string_arg
)) {
1849 d_fprintf(stderr
, "Could not get info for "
1850 "group %s\n", string_arg
);
1855 if (!wbinfo_get_usergroups(string_arg
)) {
1856 d_fprintf(stderr
, "Could not get groups for user %s\n",
1862 if (!wbinfo_get_usersids(string_arg
)) {
1863 d_fprintf(stderr
, "Could not get group SIDs for user SID %s\n",
1868 case OPT_USERDOMGROUPS
:
1869 if (!wbinfo_get_userdomgroups(string_arg
)) {
1870 d_fprintf(stderr
, "Could not get user's domain groups "
1871 "for user SID %s\n", string_arg
);
1876 bool got_error
= false;
1878 if (!wbinfo_auth(string_arg
)) {
1879 d_fprintf(stderr
, "Could not authenticate user %s with "
1880 "plaintext password\n", string_arg
);
1884 if (!wbinfo_auth_crap(string_arg
)) {
1885 d_fprintf(stderr
, "Could not authenticate user %s with "
1886 "challenge/response\n", string_arg
);
1895 uint32 flags
= WBFLAG_PAM_KRB5
|
1896 WBFLAG_PAM_CACHED_LOGIN
|
1897 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
1898 WBFLAG_PAM_INFO3_TEXT
;
1900 if (!wbinfo_auth_krb5(string_arg
, "FILE", flags
)) {
1901 d_fprintf(stderr
, "Could not authenticate user [%s] with "
1902 "Kerberos (ccache: %s)\n", string_arg
, "FILE");
1908 if (!wbinfo_klog(string_arg
)) {
1909 d_fprintf(stderr
, "Could not klog user\n");
1914 if (!wbinfo_ping()) {
1915 d_fprintf(stderr
, "could not ping winbindd!\n");
1919 case OPT_SET_AUTH_USER
:
1920 if (!wbinfo_set_auth_user(string_arg
)) {
1924 case OPT_GET_AUTH_USER
:
1925 wbinfo_get_auth_user();
1928 if (!wbinfo_getdcname(string_arg
)) {
1932 case OPT_DSGETDCNAME
:
1933 if (!wbinfo_dsgetdcname(string_arg
, 0)) {
1937 case OPT_SEPARATOR
: {
1938 const char sep
= winbind_separator_int(true);
1942 d_printf("%c\n", sep
);
1945 case OPT_LIST_ALL_DOMAINS
:
1946 if (!wbinfo_list_domains(true, verbose
)) {
1950 case OPT_LIST_OWN_DOMAIN
:
1951 if (!wbinfo_list_own_domain()) {
1955 case OPT_CHANGE_USER_PASSWORD
:
1956 if (!wbinfo_change_user_password(string_arg
)) {
1957 d_fprintf(stderr
, "Could not change user password "
1958 "for user %s\n", string_arg
);
1963 /* generic configuration options */
1964 case OPT_DOMAIN_NAME
:
1969 d_fprintf(stderr
, "Invalid option\n");
1970 poptPrintHelp(pc
, stderr
, 0);
1980 talloc_destroy(frame
);
1982 poptFreeContext(pc
);