wbinfo: use wbcLookupSid()
[Samba.git] / source / nsswitch / wbinfo.c
blobaac9f3fcb903a3f722b28c3c099abf90a67074ce
1 /*
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/>.
23 #include "includes.h"
24 #include "winbind_client.h"
25 #include "libwbclient/wbclient.h"
27 #undef DBGC_CLASS
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;
35 if (details) {
36 return 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");
44 return details;
47 static char winbind_separator_int(bool strict)
49 struct wbcInterfaceDetails *details;
50 static bool got_sep;
51 static char sep;
53 if (got_sep)
54 return sep;
56 details = init_interface_details();
58 if (!details) {
59 d_fprintf(stderr, "could not obtain winbind separator!\n");
60 if (strict) {
61 return 0;
63 /* HACK: (this module should not call lp_ funtions) */
64 return *lp_winbind_separator();
67 sep = details->winbind_separator;
68 got_sep = true;
70 if (!sep) {
71 d_fprintf(stderr, "winbind separator was NULL!\n");
72 if (strict) {
73 return 0;
75 /* HACK: (this module should not call lp_ funtions) */
76 sep = *lp_winbind_separator();
79 return sep;
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();
93 if (!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,
107 fstring user)
110 char *p = strchr(domuser,winbind_separator());
112 if (!p) {
113 /* Maybe it was a UPN? */
114 if ((p = strchr(domuser, '@')) != NULL) {
115 fstrcpy(domain, "");
116 fstrcpy(user, domuser);
117 return true;
120 fstrcpy(user, domuser);
121 fstrcpy(domain, get_winbind_domain());
122 return true;
125 fstrcpy(user, p+1);
126 fstrcpy(domain, domuser);
127 domain[PTR_DIFF(p, domuser)] = 0;
128 strupper_m(domain);
130 return true;
133 /* pull pwent info for a given user */
135 static bool wbinfo_get_userinfo(char *user)
137 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
138 struct passwd *pwd = NULL;
140 wbc_status = wbcGetpwnam(user, &pwd);
141 if (!WBC_ERROR_IS_OK(wbc_status)) {
142 return false;
145 d_printf("%s:%s:%d:%d:%s:%s:%s\n",
146 pwd->pw_name,
147 pwd->pw_passwd,
148 pwd->pw_uid,
149 pwd->pw_gid,
150 pwd->pw_gecos,
151 pwd->pw_dir,
152 pwd->pw_shell);
154 return true;
157 /* pull pwent info for a given uid */
158 static bool wbinfo_get_uidinfo(int uid)
160 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
161 struct passwd *pwd = NULL;
163 wbc_status = wbcGetpwuid(uid, &pwd);
164 if (!WBC_ERROR_IS_OK(wbc_status)) {
165 return false;
168 d_printf("%s:%s:%d:%d:%s:%s:%s\n",
169 pwd->pw_name,
170 pwd->pw_passwd,
171 pwd->pw_uid,
172 pwd->pw_gid,
173 pwd->pw_gecos,
174 pwd->pw_dir,
175 pwd->pw_shell);
177 return true;
180 /* pull grent for a given group */
181 static bool wbinfo_get_groupinfo(const char *group)
183 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
184 struct group *grp;
186 wbc_status = wbcGetgrnam(group, &grp);
187 if (!WBC_ERROR_IS_OK(wbc_status)) {
188 return false;
191 d_printf("%s:%s:%d\n",
192 grp->gr_name,
193 grp->gr_passwd,
194 grp->gr_gid);
196 wbcFreeMemory(grp);
198 return true;
201 /* List groups a user is a member of */
203 static bool wbinfo_get_usergroups(char *user)
205 struct winbindd_request request;
206 struct winbindd_response response;
207 NSS_STATUS result;
208 int i;
210 ZERO_STRUCT(request);
211 ZERO_STRUCT(response);
213 /* Send request */
215 fstrcpy(request.data.username, user);
217 result = winbindd_request_response(WINBINDD_GETGROUPS, &request, &response);
219 if (result != NSS_STATUS_SUCCESS)
220 return false;
222 for (i = 0; i < response.data.num_entries; i++)
223 d_printf("%d\n", (int)((gid_t *)response.extra_data.data)[i]);
225 SAFE_FREE(response.extra_data.data);
227 return true;
231 /* List group SIDs a user SID is a member of */
232 static bool wbinfo_get_usersids(const char *user_sid_str)
234 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
235 uint32_t num_sids;
236 uint32_t i;
237 struct wbcDomainSid user_sid, *sids = NULL;
239 /* Send request */
241 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
242 if (!WBC_ERROR_IS_OK(wbc_status)) {
243 return false;
246 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
247 if (!WBC_ERROR_IS_OK(wbc_status)) {
248 return false;
251 for (i = 0; i < num_sids; i++) {
252 char *str = NULL;
253 wbc_status = wbcSidToString(&sids[i], &str);
254 if (!WBC_ERROR_IS_OK(wbc_status)) {
255 wbcFreeMemory(sids);
256 return false;
258 d_printf("%s\n", str);
259 wbcFreeMemory(str);
262 wbcFreeMemory(sids);
264 return true;
267 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
269 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
270 uint32_t num_sids;
271 uint32_t i;
272 struct wbcDomainSid user_sid, *sids = NULL;
274 /* Send request */
276 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
277 if (!WBC_ERROR_IS_OK(wbc_status)) {
278 return false;
281 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
282 if (!WBC_ERROR_IS_OK(wbc_status)) {
283 return false;
286 for (i = 0; i < num_sids; i++) {
287 char *str = NULL;
288 wbc_status = wbcSidToString(&sids[i], &str);
289 if (!WBC_ERROR_IS_OK(wbc_status)) {
290 wbcFreeMemory(sids);
291 return false;
293 d_printf("%s\n", str);
294 wbcFreeMemory(str);
297 wbcFreeMemory(sids);
299 return true;
302 /* Convert NetBIOS name to IP */
304 static bool wbinfo_wins_byname(char *name)
306 struct winbindd_request request;
307 struct winbindd_response response;
309 ZERO_STRUCT(request);
310 ZERO_STRUCT(response);
312 /* Send request */
314 fstrcpy(request.data.winsreq, name);
316 if (winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response) !=
317 NSS_STATUS_SUCCESS) {
318 return false;
321 /* Display response */
323 d_printf("%s\n", response.data.winsresp);
325 return true;
328 /* Convert IP to NetBIOS name */
330 static bool wbinfo_wins_byip(char *ip)
332 struct winbindd_request request;
333 struct winbindd_response response;
335 ZERO_STRUCT(request);
336 ZERO_STRUCT(response);
338 /* Send request */
340 fstrcpy(request.data.winsreq, ip);
342 if (winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response) !=
343 NSS_STATUS_SUCCESS) {
344 return false;
347 /* Display response */
349 d_printf("%s\n", response.data.winsresp);
351 return true;
354 /* List all/trusted domains */
356 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
358 struct winbindd_request request;
359 struct winbindd_response response;
361 bool print_all = !list_all_domains && verbose;
363 ZERO_STRUCT(request);
364 ZERO_STRUCT(response);
366 /* Send request */
368 request.data.list_all_domains = list_all_domains;
370 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, &request, &response) !=
371 NSS_STATUS_SUCCESS)
372 return false;
374 /* Display response */
376 if (response.extra_data.data) {
377 const char *extra_data = (char *)response.extra_data.data;
378 char *name;
379 char *beg, *end;
380 TALLOC_CTX *frame = talloc_stackframe();
382 if (print_all) {
383 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
384 "Domain Name", "DNS Domain", "Trust Type",
385 "Transitive", "In", "Out");
388 while(next_token_talloc(frame,&extra_data,&name,"\n")) {
389 /* Print Domain Name */
390 if ((beg = strchr(name, '\\')) == NULL)
391 goto error;
392 *beg = 0;
393 beg++;
394 if ((end = strchr(beg, '\\')) == NULL)
395 goto error;
396 *end = 0;
398 /* Print short name */
400 d_printf("%-16s", name);
402 if (!print_all) {
403 d_printf("\n");
404 continue;
407 /* Print DNS domain */
409 if (beg) {
410 d_printf("%-24s", beg);
413 /* Skip SID */
414 beg = ++end;
415 if ((end = strchr(beg, '\\')) == NULL)
416 goto error;
418 /* Print Trust Type */
419 beg = ++end;
420 if ((end = strchr(beg, '\\')) == NULL)
421 goto error;
422 *end = 0;
423 d_printf("%-12s", beg);
425 /* Print Transitive */
426 beg = ++end;
427 if ((end = strchr(beg, '\\')) == NULL)
428 goto error;
429 *end = 0;
430 d_printf("%-12s", beg);
432 /* Print Incoming */
433 beg = ++end;
434 if ((end = strchr(beg, '\\')) == NULL)
435 goto error;
436 *end = 0;
437 d_printf("%-5s", beg);
439 /* Print Outgoing */
440 beg = ++end;
441 d_printf("%-5s\n", beg);
443 goto out;
445 error:
446 d_fprintf(stderr, "Got invalid response: %s\n", extra_data);
447 TALLOC_FREE(frame);
448 SAFE_FREE(response.extra_data.data);
449 return false;
450 out:
451 TALLOC_FREE(frame);
452 SAFE_FREE(response.extra_data.data);
455 return true;
458 /* List own domain */
460 static bool wbinfo_list_own_domain(void)
462 d_printf("%s\n", get_winbind_domain());
464 return true;
467 /* show sequence numbers */
468 static bool wbinfo_show_sequence(const char *domain)
470 struct winbindd_request request;
471 struct winbindd_response response;
473 ZERO_STRUCT(response);
474 ZERO_STRUCT(request);
476 if ( domain )
477 fstrcpy( request.domain_name, domain );
479 /* Send request */
481 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
482 NSS_STATUS_SUCCESS)
483 return false;
485 /* Display response */
487 if (domain) {
488 d_printf("%s : ", domain);
489 if (response.data.sequence_number == (uint32_t)-1) {
490 d_printf("DISCONNECTED\n");
491 } else {
492 d_printf("%d\n", response.data.sequence_number);
494 } else if (response.extra_data.data) {
495 char *extra_data = (char *)response.extra_data.data;
496 d_printf("%s", extra_data);
497 SAFE_FREE(response.extra_data.data);
500 return true;
503 /* Show domain info */
505 static bool wbinfo_domain_info(const char *domain)
507 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
508 struct wbcDomainInfo *dinfo = NULL;
509 char *sid_str = NULL;
511 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')) {
512 domain = get_winbind_domain();
515 /* Send request */
517 wbc_status = wbcDomainInfo(domain, &dinfo);
518 if (!WBC_ERROR_IS_OK(wbc_status)) {
519 return false;
522 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
523 if (!WBC_ERROR_IS_OK(wbc_status)) {
524 wbcFreeMemory(dinfo);
525 return false;
528 /* Display response */
530 d_printf("Name : %s\n", dinfo->short_name);
531 d_printf("Alt_Name : %s\n", dinfo->dns_name);
533 d_printf("SID : %s\n", sid_str);
535 d_printf("Active Directory : %s\n",
536 (dinfo->flags & WBC_DOMINFO_AD) ? "Yes" : "No");
537 d_printf("Native : %s\n",
538 (dinfo->flags & WBC_DOMINFO_NATIVE) ? "Yes" : "No");
540 d_printf("Primary : %s\n",
541 (dinfo->flags & WBC_DOMINFO_PRIMARY) ? "Yes" : "No");
543 wbcFreeMemory(sid_str);
544 wbcFreeMemory(dinfo);
546 return true;
549 /* Get a foreign DC's name */
550 static bool wbinfo_getdcname(const char *domain_name)
552 struct winbindd_request request;
553 struct winbindd_response response;
555 ZERO_STRUCT(request);
556 ZERO_STRUCT(response);
558 fstrcpy(request.domain_name, domain_name);
560 /* Send request */
562 if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) !=
563 NSS_STATUS_SUCCESS) {
564 d_fprintf(stderr, "Could not get dc name for %s\n", domain_name);
565 return false;
568 /* Display response */
570 d_printf("%s\n", response.data.dc_name);
572 return true;
575 /* Find a DC */
576 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
578 struct winbindd_request request;
579 struct winbindd_response response;
581 ZERO_STRUCT(request);
582 ZERO_STRUCT(response);
584 fstrcpy(request.domain_name, domain_name);
585 request.flags = flags;
587 request.flags |= DS_DIRECTORY_SERVICE_REQUIRED;
589 /* Send request */
591 if (winbindd_request_response(WINBINDD_DSGETDCNAME, &request, &response) !=
592 NSS_STATUS_SUCCESS) {
593 d_fprintf(stderr, "Could not find dc for %s\n", domain_name);
594 return false;
597 /* Display response */
599 d_printf("%s\n", response.data.dc_name);
601 return true;
604 /* Check trust account password */
606 static bool wbinfo_check_secret(void)
608 struct winbindd_response response;
609 NSS_STATUS result;
611 ZERO_STRUCT(response);
613 result = winbindd_request_response(WINBINDD_CHECK_MACHACC, NULL, &response);
615 d_printf("checking the trust secret via RPC calls %s\n",
616 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
618 if (result != NSS_STATUS_SUCCESS)
619 d_fprintf(stderr, "error code was %s (0x%x)\n",
620 response.data.auth.nt_status_string,
621 response.data.auth.nt_status);
623 return result == NSS_STATUS_SUCCESS;
626 /* Convert uid to sid */
628 static bool wbinfo_uid_to_sid(uid_t uid)
630 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
631 struct wbcDomainSid sid;
632 char *sid_str = NULL;
634 /* Send request */
636 wbc_status = wbcUidToSid(uid, &sid);
637 if (!WBC_ERROR_IS_OK(wbc_status)) {
638 return false;
641 wbc_status = wbcSidToString(&sid, &sid_str);
642 if (!WBC_ERROR_IS_OK(wbc_status)) {
643 return false;
646 /* Display response */
648 d_printf("%s\n", sid_str);
650 wbcFreeMemory(sid_str);
652 return true;
655 /* Convert gid to sid */
657 static bool wbinfo_gid_to_sid(gid_t gid)
659 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
660 struct wbcDomainSid sid;
661 char *sid_str = NULL;
663 /* Send request */
665 wbc_status = wbcGidToSid(gid, &sid);
666 if (!WBC_ERROR_IS_OK(wbc_status)) {
667 return false;
670 wbc_status = wbcSidToString(&sid, &sid_str);
671 if (!WBC_ERROR_IS_OK(wbc_status)) {
672 return false;
675 /* Display response */
677 d_printf("%s\n", sid_str);
679 wbcFreeMemory(sid_str);
681 return true;
684 /* Convert sid to uid */
686 static bool wbinfo_sid_to_uid(const char *sid_str)
688 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
689 struct wbcDomainSid sid;
690 uid_t uid;
692 /* Send request */
694 wbc_status = wbcStringToSid(sid_str, &sid);
695 if (!WBC_ERROR_IS_OK(wbc_status)) {
696 return false;
699 wbc_status = wbcSidToUid(&sid, &uid);
700 if (!WBC_ERROR_IS_OK(wbc_status)) {
701 return false;
704 /* Display response */
706 d_printf("%d\n", (int)uid);
708 return true;
711 static bool wbinfo_sid_to_gid(const char *sid_str)
713 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
714 struct wbcDomainSid sid;
715 gid_t gid;
717 /* Send request */
719 wbc_status = wbcStringToSid(sid_str, &sid);
720 if (!WBC_ERROR_IS_OK(wbc_status)) {
721 return false;
724 wbc_status = wbcSidToGid(&sid, &gid);
725 if (!WBC_ERROR_IS_OK(wbc_status)) {
726 return false;
729 /* Display response */
731 d_printf("%d\n", (int)gid);
733 return true;
736 static bool wbinfo_allocate_uid(void)
738 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
739 uid_t uid;
741 /* Send request */
743 wbc_status = wbcAllocateUid(&uid);
744 if (!WBC_ERROR_IS_OK(wbc_status)) {
745 return false;
748 /* Display response */
750 d_printf("New uid: %d\n", uid);
752 return true;
755 static bool wbinfo_allocate_gid(void)
757 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
758 gid_t gid;
760 /* Send request */
762 wbc_status = wbcAllocateGid(&gid);
763 if (!WBC_ERROR_IS_OK(wbc_status)) {
764 return false;
767 /* Display response */
769 d_printf("New gid: %d\n", gid);
771 return true;
774 /* Convert sid to string */
776 static bool wbinfo_lookupsid(const char *sid_str)
778 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
779 struct wbcDomainSid sid;
780 char *domain;
781 char *name;
782 enum wbcSidType type;
784 /* Send off request */
786 wbc_status = wbcStringToSid(sid_str, &sid);
787 if (!WBC_ERROR_IS_OK(wbc_status)) {
788 return false;
791 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
792 if (!WBC_ERROR_IS_OK(wbc_status)) {
793 return false;
796 /* Display response */
798 d_printf("%s%c%s %d\n",
799 domain, winbind_separator(), name, type);
801 return true;
804 /* Lookup a list of RIDs */
806 static bool wbinfo_lookuprids(char *domain, char *arg)
808 size_t i;
809 DOM_SID sid;
810 int num_rids;
811 uint32 *rids;
812 const char *p;
813 char *ridstr;
814 const char **names;
815 enum lsa_SidType *types;
816 const char *domain_name;
817 TALLOC_CTX *mem_ctx;
818 struct winbindd_request request;
819 struct winbindd_response response;
821 ZERO_STRUCT(request);
822 ZERO_STRUCT(response);
824 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0'))
825 fstrcpy(request.domain_name, get_winbind_domain());
826 else
827 fstrcpy(request.domain_name, domain);
829 /* Send request */
831 if (winbindd_request_response(WINBINDD_DOMAIN_INFO, &request, &response) !=
832 NSS_STATUS_SUCCESS) {
833 d_printf("Could not get domain sid for %s\n", request.domain_name);
834 return false;
837 if (!string_to_sid(&sid, response.data.domain_info.sid)) {
838 d_printf("Could not convert %s to sid\n", response.data.domain_info.sid);
839 return false;
842 mem_ctx = talloc_new(NULL);
843 if (mem_ctx == NULL) {
844 d_printf("talloc_new failed\n");
845 return false;
848 num_rids = 0;
849 rids = NULL;
850 p = arg;
852 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
853 uint32 rid = strtoul(ridstr, NULL, 10);
854 ADD_TO_ARRAY(mem_ctx, uint32, rid, &rids, &num_rids);
857 if (rids == NULL) {
858 TALLOC_FREE(mem_ctx);
859 return false;
862 if (!winbind_lookup_rids(mem_ctx, &sid, num_rids, rids,
863 &domain_name, &names, &types)) {
864 d_printf("winbind_lookup_rids failed\n");
865 TALLOC_FREE(mem_ctx);
866 return false;
869 d_printf("Domain: %s\n", domain_name);
871 for (i=0; i<num_rids; i++) {
872 d_printf("%8d: %s (%s)\n", rids[i], names[i],
873 sid_type_lookup(types[i]));
876 TALLOC_FREE(mem_ctx);
877 return true;
880 /* Convert string to sid */
882 static bool wbinfo_lookupname(char *name)
884 struct winbindd_request request;
885 struct winbindd_response response;
887 /* Send off request */
889 ZERO_STRUCT(request);
890 ZERO_STRUCT(response);
892 parse_wbinfo_domain_user(name, request.data.name.dom_name,
893 request.data.name.name);
895 if (winbindd_request_response(WINBINDD_LOOKUPNAME, &request, &response) !=
896 NSS_STATUS_SUCCESS)
897 return false;
899 /* Display response */
901 d_printf("%s %s (%d)\n", response.data.sid.sid, sid_type_lookup(response.data.sid.type), response.data.sid.type);
903 return true;
906 /* Authenticate a user with a plaintext password */
908 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
910 struct winbindd_request request;
911 struct winbindd_response response;
912 NSS_STATUS result;
913 char *p;
915 /* Send off request */
917 ZERO_STRUCT(request);
918 ZERO_STRUCT(response);
920 p = strchr(username, '%');
922 if (p) {
923 *p = 0;
924 fstrcpy(request.data.auth.user, username);
925 fstrcpy(request.data.auth.pass, p + 1);
926 *p = '%';
927 } else
928 fstrcpy(request.data.auth.user, username);
930 request.flags = flags;
932 fstrcpy(request.data.auth.krb5_cc_type, cctype);
934 request.data.auth.uid = geteuid();
936 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
938 /* Display response */
940 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
941 username, (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", cctype);
943 if (response.data.auth.nt_status)
944 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
945 response.data.auth.nt_status_string,
946 response.data.auth.nt_status,
947 response.data.auth.error_string);
949 if (result == NSS_STATUS_SUCCESS) {
951 if (request.flags & WBFLAG_PAM_INFO3_TEXT) {
952 if (response.data.auth.info3.user_flgs & NETLOGON_CACHED_ACCOUNT) {
953 d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
957 if (response.data.auth.krb5ccname[0] != '\0') {
958 d_printf("credentials were put in: %s\n", response.data.auth.krb5ccname);
959 } else {
960 d_printf("no credentials cached\n");
964 return result == NSS_STATUS_SUCCESS;
967 /* Authenticate a user with a plaintext password */
969 static bool wbinfo_auth(char *username)
971 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
972 char *s = NULL;
973 char *p = NULL;
974 const char *password = NULL;
975 char *name = NULL;
977 if ((s = SMB_STRDUP(username)) == NULL) {
978 return false;
981 if ((p = strchr(s, '%')) != NULL) {
982 *p = 0;
983 p++;
984 password = p;
985 } else {
986 password = "";
989 name = s;
991 wbc_status = wbcAuthenticateUser(name, password);
993 d_printf("plaintext password authentication %s\n",
994 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
996 #if 0
997 if (response.data.auth.nt_status)
998 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
999 response.data.auth.nt_status_string,
1000 response.data.auth.nt_status,
1001 response.data.auth.error_string);
1002 #endif
1004 SAFE_FREE(s);
1006 return WBC_ERROR_IS_OK(wbc_status);
1009 /* Authenticate a user with a challenge/response */
1011 static bool wbinfo_auth_crap(char *username)
1013 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1014 struct wbcAuthUserParams params;
1015 struct wbcAuthUserInfo *info = NULL;
1016 struct wbcAuthErrorInfo *err = NULL;
1017 DATA_BLOB lm = data_blob_null;
1018 DATA_BLOB nt = data_blob_null;
1019 fstring name_user;
1020 fstring name_domain;
1021 fstring pass;
1022 char *p;
1024 p = strchr(username, '%');
1026 if (p) {
1027 *p = 0;
1028 fstrcpy(pass, p + 1);
1031 parse_wbinfo_domain_user(username, name_domain, name_user);
1033 params.account_name = name_user;
1034 params.domain_name = name_domain;
1035 params.workstation_name = NULL;
1037 params.flags = 0;
1038 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1039 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1041 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1043 generate_random_buffer(params.password.response.challenge, 8);
1045 if (lp_client_ntlmv2_auth()) {
1046 DATA_BLOB server_chal;
1047 DATA_BLOB names_blob;
1049 server_chal = data_blob(params.password.response.challenge, 8);
1051 /* Pretend this is a login to 'us', for blob purposes */
1052 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
1054 if (!SMBNTLMv2encrypt(name_user, name_domain, pass, &server_chal,
1055 &names_blob,
1056 &lm, &nt, NULL)) {
1057 data_blob_free(&names_blob);
1058 data_blob_free(&server_chal);
1059 return false;
1061 data_blob_free(&names_blob);
1062 data_blob_free(&server_chal);
1064 } else {
1065 if (lp_client_lanman_auth()) {
1066 bool ok;
1067 lm = data_blob(NULL, 24);
1068 ok = SMBencrypt(pass, params.password.response.challenge,
1069 lm.data);
1070 if (!ok) {
1071 data_blob_free(&lm);
1074 nt = data_blob(NULL, 24);
1075 SMBNTencrypt(pass, params.password.response.challenge,
1076 nt.data);
1079 params.password.response.nt_length = nt.length;
1080 params.password.response.nt_data = nt.data;
1081 params.password.response.lm_length = lm.length;
1082 params.password.response.lm_data = lm.data;
1084 wbc_status = wbcAuthenticateUserEx(&params, &info, &err);
1086 /* Display response */
1088 d_printf("challenge/response password authentication %s\n",
1089 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1091 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1092 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
1093 err->nt_string,
1094 err->nt_status,
1095 err->display_string);
1096 wbcFreeMemory(err);
1097 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1098 wbcFreeMemory(info);
1101 data_blob_free(&nt);
1102 data_blob_free(&lm);
1104 return WBC_ERROR_IS_OK(wbc_status);
1107 /* Authenticate a user with a plaintext password and set a token */
1109 static bool wbinfo_klog(char *username)
1111 struct winbindd_request request;
1112 struct winbindd_response response;
1113 NSS_STATUS result;
1114 char *p;
1116 /* Send off request */
1118 ZERO_STRUCT(request);
1119 ZERO_STRUCT(response);
1121 p = strchr(username, '%');
1123 if (p) {
1124 *p = 0;
1125 fstrcpy(request.data.auth.user, username);
1126 fstrcpy(request.data.auth.pass, p + 1);
1127 *p = '%';
1128 } else {
1129 fstrcpy(request.data.auth.user, username);
1130 fstrcpy(request.data.auth.pass, getpass("Password: "));
1133 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1135 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
1137 /* Display response */
1139 d_printf("plaintext password authentication %s\n",
1140 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1142 if (response.data.auth.nt_status)
1143 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
1144 response.data.auth.nt_status_string,
1145 response.data.auth.nt_status,
1146 response.data.auth.error_string);
1148 if (result != NSS_STATUS_SUCCESS)
1149 return false;
1151 if (response.extra_data.data == NULL) {
1152 d_fprintf(stderr, "Did not get token data\n");
1153 return false;
1156 if (!afs_settoken_str((char *)response.extra_data.data)) {
1157 d_fprintf(stderr, "Could not set token\n");
1158 return false;
1161 d_printf("Successfully created AFS token\n");
1162 return true;
1165 /* Print domain users */
1167 static bool print_domain_users(const char *domain)
1169 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1170 uint32_t i;
1171 uint32_t num_users = 0;
1172 const char **users = NULL;
1174 /* Send request to winbind daemon */
1176 /* '.' is the special sign for our own domain */
1177 if (domain && strcmp(domain, ".") == 0) {
1178 domain = get_winbind_domain();
1181 wbc_status = wbcListUsers(domain, &num_users, &users);
1182 if (!WBC_ERROR_IS_OK(wbc_status)) {
1183 return false;
1186 for (i=0; i < num_users; i++) {
1187 d_printf("%s\n", users[i]);
1190 wbcFreeMemory(users);
1192 return true;
1195 /* Print domain groups */
1197 static bool print_domain_groups(const char *domain)
1199 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1200 uint32_t i;
1201 uint32_t num_groups = 0;
1202 const char **groups = NULL;
1204 /* Send request to winbind daemon */
1206 /* '.' is the special sign for our own domain */
1207 if (domain && strcmp(domain, ".") == 0) {
1208 domain = get_winbind_domain();
1211 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1212 if (!WBC_ERROR_IS_OK(wbc_status)) {
1213 return false;
1216 for (i=0; i < num_groups; i++) {
1217 d_printf("%s\n", groups[i]);
1220 wbcFreeMemory(groups);
1222 return true;
1225 /* Set the authorised user for winbindd access in secrets.tdb */
1227 static bool wbinfo_set_auth_user(char *username)
1229 const char *password;
1230 char *p;
1231 fstring user, domain;
1233 /* Separate into user and password */
1235 parse_wbinfo_domain_user(username, domain, user);
1237 p = strchr(user, '%');
1239 if (p != NULL) {
1240 *p = 0;
1241 password = p+1;
1242 } else {
1243 char *thepass = getpass("Password: ");
1244 if (thepass) {
1245 password = thepass;
1246 } else
1247 password = "";
1250 /* Store or remove DOMAIN\username%password in secrets.tdb */
1252 secrets_init();
1254 if (user[0]) {
1256 if (!secrets_store(SECRETS_AUTH_USER, user,
1257 strlen(user) + 1)) {
1258 d_fprintf(stderr, "error storing username\n");
1259 return false;
1262 /* We always have a domain name added by the
1263 parse_wbinfo_domain_user() function. */
1265 if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
1266 strlen(domain) + 1)) {
1267 d_fprintf(stderr, "error storing domain name\n");
1268 return false;
1271 } else {
1272 secrets_delete(SECRETS_AUTH_USER);
1273 secrets_delete(SECRETS_AUTH_DOMAIN);
1276 if (password[0]) {
1278 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
1279 strlen(password) + 1)) {
1280 d_fprintf(stderr, "error storing password\n");
1281 return false;
1284 } else
1285 secrets_delete(SECRETS_AUTH_PASSWORD);
1287 return true;
1290 static void wbinfo_get_auth_user(void)
1292 char *user, *domain, *password;
1294 /* Lift data from secrets file */
1296 secrets_fetch_ipc_userpass(&user, &domain, &password);
1298 if ((!user || !*user) && (!domain || !*domain ) && (!password || !*password)){
1300 SAFE_FREE(user);
1301 SAFE_FREE(domain);
1302 SAFE_FREE(password);
1303 d_printf("No authorised user configured\n");
1304 return;
1307 /* Pretty print authorised user info */
1309 d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? lp_winbind_separator(): "",
1310 user, password ? "%" : "", password ? password : "");
1312 SAFE_FREE(user);
1313 SAFE_FREE(domain);
1314 SAFE_FREE(password);
1317 static bool wbinfo_ping(void)
1319 wbcErr wbc_status;
1321 wbc_status = wbcPing();
1323 /* Display response */
1325 d_printf("Ping to winbindd %s\n",
1326 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1328 return WBC_ERROR_IS_OK(wbc_status);
1331 /* Main program */
1333 enum {
1334 OPT_SET_AUTH_USER = 1000,
1335 OPT_GET_AUTH_USER,
1336 OPT_DOMAIN_NAME,
1337 OPT_SEQUENCE,
1338 OPT_GETDCNAME,
1339 OPT_DSGETDCNAME,
1340 OPT_USERDOMGROUPS,
1341 OPT_USERSIDS,
1342 OPT_ALLOCATE_UID,
1343 OPT_ALLOCATE_GID,
1344 OPT_SEPARATOR,
1345 OPT_LIST_ALL_DOMAINS,
1346 OPT_LIST_OWN_DOMAIN,
1347 OPT_UID_INFO,
1348 OPT_GROUP_INFO,
1349 OPT_VERBOSE
1352 int main(int argc, char **argv, char **envp)
1354 int opt;
1355 TALLOC_CTX *frame = talloc_stackframe();
1356 poptContext pc;
1357 static char *string_arg;
1358 static char *opt_domain_name;
1359 static int int_arg;
1360 int result = 1;
1361 bool verbose = false;
1363 struct poptOption long_options[] = {
1364 POPT_AUTOHELP
1366 /* longName, shortName, argInfo, argPtr, value, descrip,
1367 argDesc */
1369 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1370 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1371 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1372 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1373 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1374 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1375 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1376 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1377 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1378 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1379 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1380 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1381 "Get a new UID out of idmap" },
1382 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1383 "Get a new GID out of idmap" },
1384 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1385 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1386 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1387 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1388 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1389 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1390 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1391 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1392 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1393 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1394 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1395 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1396 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1397 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1398 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1399 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1400 "Get a DC name for a foreign domain", "domainname" },
1401 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1402 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1403 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1404 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1405 #ifdef WITH_FAKE_KASERVER
1406 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1407 #endif
1408 #ifdef HAVE_KRB5
1409 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1410 /* destroys wbinfo --help output */
1411 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1412 #endif
1413 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1414 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1415 POPT_COMMON_CONFIGFILE
1416 POPT_COMMON_VERSION
1417 POPT_TABLEEND
1420 /* Samba client initialisation */
1421 load_case_tables();
1424 /* Parse options */
1426 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
1428 /* Parse command line options */
1430 if (argc == 1) {
1431 poptPrintHelp(pc, stderr, 0);
1432 return 1;
1435 while((opt = poptGetNextOpt(pc)) != -1) {
1436 /* get the generic configuration parameters like --domain */
1437 switch (opt) {
1438 case OPT_VERBOSE:
1439 verbose = True;
1440 break;
1444 poptFreeContext(pc);
1446 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) {
1447 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
1448 get_dyn_CONFIGFILE(), strerror(errno));
1449 exit(1);
1452 if (!init_names())
1453 return 1;
1455 load_interfaces();
1457 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1458 POPT_CONTEXT_KEEP_FIRST);
1460 while((opt = poptGetNextOpt(pc)) != -1) {
1461 switch (opt) {
1462 case 'u':
1463 if (!print_domain_users(opt_domain_name)) {
1464 d_fprintf(stderr, "Error looking up domain users\n");
1465 goto done;
1467 break;
1468 case 'g':
1469 if (!print_domain_groups(opt_domain_name)) {
1470 d_fprintf(stderr, "Error looking up domain groups\n");
1471 goto done;
1473 break;
1474 case 's':
1475 if (!wbinfo_lookupsid(string_arg)) {
1476 d_fprintf(stderr, "Could not lookup sid %s\n", string_arg);
1477 goto done;
1479 break;
1480 case 'R':
1481 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
1482 d_fprintf(stderr, "Could not lookup RIDs %s\n", string_arg);
1483 goto done;
1485 break;
1486 case 'n':
1487 if (!wbinfo_lookupname(string_arg)) {
1488 d_fprintf(stderr, "Could not lookup name %s\n", string_arg);
1489 goto done;
1491 break;
1492 case 'N':
1493 if (!wbinfo_wins_byname(string_arg)) {
1494 d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg);
1495 goto done;
1497 break;
1498 case 'I':
1499 if (!wbinfo_wins_byip(string_arg)) {
1500 d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg);
1501 goto done;
1503 break;
1504 case 'U':
1505 if (!wbinfo_uid_to_sid(int_arg)) {
1506 d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg);
1507 goto done;
1509 break;
1510 case 'G':
1511 if (!wbinfo_gid_to_sid(int_arg)) {
1512 d_fprintf(stderr, "Could not convert gid %d to sid\n",
1513 int_arg);
1514 goto done;
1516 break;
1517 case 'S':
1518 if (!wbinfo_sid_to_uid(string_arg)) {
1519 d_fprintf(stderr, "Could not convert sid %s to uid\n",
1520 string_arg);
1521 goto done;
1523 break;
1524 case 'Y':
1525 if (!wbinfo_sid_to_gid(string_arg)) {
1526 d_fprintf(stderr, "Could not convert sid %s to gid\n",
1527 string_arg);
1528 goto done;
1530 break;
1531 case OPT_ALLOCATE_UID:
1532 if (!wbinfo_allocate_uid()) {
1533 d_fprintf(stderr, "Could not allocate a uid\n");
1534 goto done;
1536 break;
1537 case OPT_ALLOCATE_GID:
1538 if (!wbinfo_allocate_gid()) {
1539 d_fprintf(stderr, "Could not allocate a gid\n");
1540 goto done;
1542 break;
1543 case 't':
1544 if (!wbinfo_check_secret()) {
1545 d_fprintf(stderr, "Could not check secret\n");
1546 goto done;
1548 break;
1549 case 'm':
1550 if (!wbinfo_list_domains(false, verbose)) {
1551 d_fprintf(stderr, "Could not list trusted domains\n");
1552 goto done;
1554 break;
1555 case OPT_SEQUENCE:
1556 if (!wbinfo_show_sequence(opt_domain_name)) {
1557 d_fprintf(stderr, "Could not show sequence numbers\n");
1558 goto done;
1560 break;
1561 case 'D':
1562 if (!wbinfo_domain_info(string_arg)) {
1563 d_fprintf(stderr, "Could not get domain info\n");
1564 goto done;
1566 break;
1567 case 'i':
1568 if (!wbinfo_get_userinfo(string_arg)) {
1569 d_fprintf(stderr, "Could not get info for user %s\n",
1570 string_arg);
1571 goto done;
1573 break;
1574 case OPT_UID_INFO:
1575 if ( !wbinfo_get_uidinfo(int_arg)) {
1576 d_fprintf(stderr, "Could not get info for uid "
1577 "%d\n", int_arg);
1578 goto done;
1580 break;
1581 case OPT_GROUP_INFO:
1582 if ( !wbinfo_get_groupinfo(string_arg)) {
1583 d_fprintf(stderr, "Could not get info for "
1584 "group %s\n", string_arg);
1585 goto done;
1587 break;
1588 case 'r':
1589 if (!wbinfo_get_usergroups(string_arg)) {
1590 d_fprintf(stderr, "Could not get groups for user %s\n",
1591 string_arg);
1592 goto done;
1594 break;
1595 case OPT_USERSIDS:
1596 if (!wbinfo_get_usersids(string_arg)) {
1597 d_fprintf(stderr, "Could not get group SIDs for user SID %s\n",
1598 string_arg);
1599 goto done;
1601 break;
1602 case OPT_USERDOMGROUPS:
1603 if (!wbinfo_get_userdomgroups(string_arg)) {
1604 d_fprintf(stderr, "Could not get user's domain groups "
1605 "for user SID %s\n", string_arg);
1606 goto done;
1608 break;
1609 case 'a': {
1610 bool got_error = false;
1612 if (!wbinfo_auth(string_arg)) {
1613 d_fprintf(stderr, "Could not authenticate user %s with "
1614 "plaintext password\n", string_arg);
1615 got_error = true;
1618 if (!wbinfo_auth_crap(string_arg)) {
1619 d_fprintf(stderr, "Could not authenticate user %s with "
1620 "challenge/response\n", string_arg);
1621 got_error = true;
1624 if (got_error)
1625 goto done;
1626 break;
1628 case 'K': {
1629 uint32 flags = WBFLAG_PAM_KRB5 |
1630 WBFLAG_PAM_CACHED_LOGIN |
1631 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
1632 WBFLAG_PAM_INFO3_TEXT;
1634 if (!wbinfo_auth_krb5(string_arg, "FILE", flags)) {
1635 d_fprintf(stderr, "Could not authenticate user [%s] with "
1636 "Kerberos (ccache: %s)\n", string_arg, "FILE");
1637 goto done;
1639 break;
1641 case 'k':
1642 if (!wbinfo_klog(string_arg)) {
1643 d_fprintf(stderr, "Could not klog user\n");
1644 goto done;
1646 break;
1647 case 'p':
1648 if (!wbinfo_ping()) {
1649 d_fprintf(stderr, "could not ping winbindd!\n");
1650 goto done;
1652 break;
1653 case OPT_SET_AUTH_USER:
1654 if (!wbinfo_set_auth_user(string_arg)) {
1655 goto done;
1657 break;
1658 case OPT_GET_AUTH_USER:
1659 wbinfo_get_auth_user();
1660 break;
1661 case OPT_GETDCNAME:
1662 if (!wbinfo_getdcname(string_arg)) {
1663 goto done;
1665 break;
1666 case OPT_DSGETDCNAME:
1667 if (!wbinfo_dsgetdcname(string_arg, 0)) {
1668 goto done;
1670 break;
1671 case OPT_SEPARATOR: {
1672 const char sep = winbind_separator_int(true);
1673 if ( !sep ) {
1674 goto done;
1676 d_printf("%c\n", sep);
1677 break;
1679 case OPT_LIST_ALL_DOMAINS:
1680 if (!wbinfo_list_domains(true, verbose)) {
1681 goto done;
1683 break;
1684 case OPT_LIST_OWN_DOMAIN:
1685 if (!wbinfo_list_own_domain()) {
1686 goto done;
1688 break;
1689 /* generic configuration options */
1690 case OPT_DOMAIN_NAME:
1691 break;
1692 case OPT_VERBOSE:
1693 break;
1694 default:
1695 d_fprintf(stderr, "Invalid option\n");
1696 poptPrintHelp(pc, stderr, 0);
1697 goto done;
1701 result = 0;
1703 /* Exit code */
1705 done:
1706 talloc_destroy(frame);
1708 poptFreeContext(pc);
1709 return result;