Fix an uninitialized variable
[Samba.git] / source / nsswitch / wbinfo.c
blobba358bd1dd7493a7b0dd4b6bf1941c8447b8edb9
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(const char *user)
205 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
206 uint32_t num_groups;
207 uint32_t i;
208 gid_t *groups = NULL;
210 /* Send request */
212 wbc_status = wbcGetGroups(user, &num_groups, &groups);
213 if (!WBC_ERROR_IS_OK(wbc_status)) {
214 return false;
217 for (i = 0; i < num_groups; i++) {
218 d_printf("%d\n", (int)groups[i]);
221 wbcFreeMemory(groups);
223 return true;
227 /* List group SIDs a user SID is a member of */
228 static bool wbinfo_get_usersids(const char *user_sid_str)
230 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
231 uint32_t num_sids;
232 uint32_t i;
233 struct wbcDomainSid user_sid, *sids = NULL;
235 /* Send request */
237 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
238 if (!WBC_ERROR_IS_OK(wbc_status)) {
239 return false;
242 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
243 if (!WBC_ERROR_IS_OK(wbc_status)) {
244 return false;
247 for (i = 0; i < num_sids; i++) {
248 char *str = NULL;
249 wbc_status = wbcSidToString(&sids[i], &str);
250 if (!WBC_ERROR_IS_OK(wbc_status)) {
251 wbcFreeMemory(sids);
252 return false;
254 d_printf("%s\n", str);
255 wbcFreeMemory(str);
258 wbcFreeMemory(sids);
260 return true;
263 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
265 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
266 uint32_t num_sids;
267 uint32_t i;
268 struct wbcDomainSid user_sid, *sids = NULL;
270 /* Send request */
272 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
273 if (!WBC_ERROR_IS_OK(wbc_status)) {
274 return false;
277 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
278 if (!WBC_ERROR_IS_OK(wbc_status)) {
279 return false;
282 for (i = 0; i < num_sids; i++) {
283 char *str = NULL;
284 wbc_status = wbcSidToString(&sids[i], &str);
285 if (!WBC_ERROR_IS_OK(wbc_status)) {
286 wbcFreeMemory(sids);
287 return false;
289 d_printf("%s\n", str);
290 wbcFreeMemory(str);
293 wbcFreeMemory(sids);
295 return true;
298 /* Convert NetBIOS name to IP */
300 static bool wbinfo_wins_byname(char *name)
302 struct winbindd_request request;
303 struct winbindd_response response;
305 ZERO_STRUCT(request);
306 ZERO_STRUCT(response);
308 /* Send request */
310 fstrcpy(request.data.winsreq, name);
312 if (winbindd_request_response(WINBINDD_WINS_BYNAME, &request, &response) !=
313 NSS_STATUS_SUCCESS) {
314 return false;
317 /* Display response */
319 d_printf("%s\n", response.data.winsresp);
321 return true;
324 /* Convert IP to NetBIOS name */
326 static bool wbinfo_wins_byip(char *ip)
328 struct winbindd_request request;
329 struct winbindd_response response;
331 ZERO_STRUCT(request);
332 ZERO_STRUCT(response);
334 /* Send request */
336 fstrcpy(request.data.winsreq, ip);
338 if (winbindd_request_response(WINBINDD_WINS_BYIP, &request, &response) !=
339 NSS_STATUS_SUCCESS) {
340 return false;
343 /* Display response */
345 d_printf("%s\n", response.data.winsresp);
347 return true;
350 /* List all/trusted domains */
352 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
354 struct winbindd_request request;
355 struct winbindd_response response;
357 bool print_all = !list_all_domains && verbose;
359 ZERO_STRUCT(request);
360 ZERO_STRUCT(response);
362 /* Send request */
364 request.data.list_all_domains = list_all_domains;
366 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM, &request, &response) !=
367 NSS_STATUS_SUCCESS)
368 return false;
370 /* Display response */
372 if (response.extra_data.data) {
373 const char *extra_data = (char *)response.extra_data.data;
374 char *name;
375 char *beg, *end;
376 TALLOC_CTX *frame = talloc_stackframe();
378 if (print_all) {
379 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
380 "Domain Name", "DNS Domain", "Trust Type",
381 "Transitive", "In", "Out");
384 while(next_token_talloc(frame,&extra_data,&name,"\n")) {
385 /* Print Domain Name */
386 if ((beg = strchr(name, '\\')) == NULL)
387 goto error;
388 *beg = 0;
389 beg++;
390 if ((end = strchr(beg, '\\')) == NULL)
391 goto error;
392 *end = 0;
394 /* Print short name */
396 d_printf("%-16s", name);
398 if (!print_all) {
399 d_printf("\n");
400 continue;
403 /* Print DNS domain */
405 if (beg) {
406 d_printf("%-24s", beg);
409 /* Skip SID */
410 beg = ++end;
411 if ((end = strchr(beg, '\\')) == NULL)
412 goto error;
414 /* Print Trust Type */
415 beg = ++end;
416 if ((end = strchr(beg, '\\')) == NULL)
417 goto error;
418 *end = 0;
419 d_printf("%-12s", beg);
421 /* Print Transitive */
422 beg = ++end;
423 if ((end = strchr(beg, '\\')) == NULL)
424 goto error;
425 *end = 0;
426 d_printf("%-12s", beg);
428 /* Print Incoming */
429 beg = ++end;
430 if ((end = strchr(beg, '\\')) == NULL)
431 goto error;
432 *end = 0;
433 d_printf("%-5s", beg);
435 /* Print Outgoing */
436 beg = ++end;
437 d_printf("%-5s\n", beg);
439 goto out;
441 error:
442 d_fprintf(stderr, "Got invalid response: %s\n", extra_data);
443 TALLOC_FREE(frame);
444 SAFE_FREE(response.extra_data.data);
445 return false;
446 out:
447 TALLOC_FREE(frame);
448 SAFE_FREE(response.extra_data.data);
451 return true;
454 /* List own domain */
456 static bool wbinfo_list_own_domain(void)
458 d_printf("%s\n", get_winbind_domain());
460 return true;
463 /* show sequence numbers */
464 static bool wbinfo_show_sequence(const char *domain)
466 struct winbindd_request request;
467 struct winbindd_response response;
469 ZERO_STRUCT(response);
470 ZERO_STRUCT(request);
472 if ( domain )
473 fstrcpy( request.domain_name, domain );
475 /* Send request */
477 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE, &request, &response) !=
478 NSS_STATUS_SUCCESS)
479 return false;
481 /* Display response */
483 if (domain) {
484 d_printf("%s : ", domain);
485 if (response.data.sequence_number == (uint32_t)-1) {
486 d_printf("DISCONNECTED\n");
487 } else {
488 d_printf("%d\n", response.data.sequence_number);
490 } else if (response.extra_data.data) {
491 char *extra_data = (char *)response.extra_data.data;
492 d_printf("%s", extra_data);
493 SAFE_FREE(response.extra_data.data);
496 return true;
499 /* Show domain info */
501 static bool wbinfo_domain_info(const char *domain)
503 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
504 struct wbcDomainInfo *dinfo = NULL;
505 char *sid_str = NULL;
507 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')) {
508 domain = get_winbind_domain();
511 /* Send request */
513 wbc_status = wbcDomainInfo(domain, &dinfo);
514 if (!WBC_ERROR_IS_OK(wbc_status)) {
515 return false;
518 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
519 if (!WBC_ERROR_IS_OK(wbc_status)) {
520 wbcFreeMemory(dinfo);
521 return false;
524 /* Display response */
526 d_printf("Name : %s\n", dinfo->short_name);
527 d_printf("Alt_Name : %s\n", dinfo->dns_name);
529 d_printf("SID : %s\n", sid_str);
531 d_printf("Active Directory : %s\n",
532 (dinfo->flags & WBC_DOMINFO_AD) ? "Yes" : "No");
533 d_printf("Native : %s\n",
534 (dinfo->flags & WBC_DOMINFO_NATIVE) ? "Yes" : "No");
536 d_printf("Primary : %s\n",
537 (dinfo->flags & WBC_DOMINFO_PRIMARY) ? "Yes" : "No");
539 wbcFreeMemory(sid_str);
540 wbcFreeMemory(dinfo);
542 return true;
545 /* Get a foreign DC's name */
546 static bool wbinfo_getdcname(const char *domain_name)
548 struct winbindd_request request;
549 struct winbindd_response response;
551 ZERO_STRUCT(request);
552 ZERO_STRUCT(response);
554 fstrcpy(request.domain_name, domain_name);
556 /* Send request */
558 if (winbindd_request_response(WINBINDD_GETDCNAME, &request, &response) !=
559 NSS_STATUS_SUCCESS) {
560 d_fprintf(stderr, "Could not get dc name for %s\n", domain_name);
561 return false;
564 /* Display response */
566 d_printf("%s\n", response.data.dc_name);
568 return true;
571 /* Find a DC */
572 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
574 struct winbindd_request request;
575 struct winbindd_response response;
577 ZERO_STRUCT(request);
578 ZERO_STRUCT(response);
580 fstrcpy(request.domain_name, domain_name);
581 request.flags = flags;
583 request.flags |= DS_DIRECTORY_SERVICE_REQUIRED;
585 /* Send request */
587 if (winbindd_request_response(WINBINDD_DSGETDCNAME, &request, &response) !=
588 NSS_STATUS_SUCCESS) {
589 d_fprintf(stderr, "Could not find dc for %s\n", domain_name);
590 return false;
593 /* Display response */
595 d_printf("%s\n", response.data.dc_name);
597 return true;
600 /* Check trust account password */
602 static bool wbinfo_check_secret(void)
604 struct winbindd_response response;
605 NSS_STATUS result;
607 ZERO_STRUCT(response);
609 result = winbindd_request_response(WINBINDD_CHECK_MACHACC, NULL, &response);
611 d_printf("checking the trust secret via RPC calls %s\n",
612 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
614 if (result != NSS_STATUS_SUCCESS)
615 d_fprintf(stderr, "error code was %s (0x%x)\n",
616 response.data.auth.nt_status_string,
617 response.data.auth.nt_status);
619 return result == NSS_STATUS_SUCCESS;
622 /* Convert uid to sid */
624 static bool wbinfo_uid_to_sid(uid_t uid)
626 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
627 struct wbcDomainSid sid;
628 char *sid_str = NULL;
630 /* Send request */
632 wbc_status = wbcUidToSid(uid, &sid);
633 if (!WBC_ERROR_IS_OK(wbc_status)) {
634 return false;
637 wbc_status = wbcSidToString(&sid, &sid_str);
638 if (!WBC_ERROR_IS_OK(wbc_status)) {
639 return false;
642 /* Display response */
644 d_printf("%s\n", sid_str);
646 wbcFreeMemory(sid_str);
648 return true;
651 /* Convert gid to sid */
653 static bool wbinfo_gid_to_sid(gid_t gid)
655 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
656 struct wbcDomainSid sid;
657 char *sid_str = NULL;
659 /* Send request */
661 wbc_status = wbcGidToSid(gid, &sid);
662 if (!WBC_ERROR_IS_OK(wbc_status)) {
663 return false;
666 wbc_status = wbcSidToString(&sid, &sid_str);
667 if (!WBC_ERROR_IS_OK(wbc_status)) {
668 return false;
671 /* Display response */
673 d_printf("%s\n", sid_str);
675 wbcFreeMemory(sid_str);
677 return true;
680 /* Convert sid to uid */
682 static bool wbinfo_sid_to_uid(const char *sid_str)
684 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
685 struct wbcDomainSid sid;
686 uid_t uid;
688 /* Send request */
690 wbc_status = wbcStringToSid(sid_str, &sid);
691 if (!WBC_ERROR_IS_OK(wbc_status)) {
692 return false;
695 wbc_status = wbcSidToUid(&sid, &uid);
696 if (!WBC_ERROR_IS_OK(wbc_status)) {
697 return false;
700 /* Display response */
702 d_printf("%d\n", (int)uid);
704 return true;
707 static bool wbinfo_sid_to_gid(const char *sid_str)
709 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
710 struct wbcDomainSid sid;
711 gid_t gid;
713 /* Send request */
715 wbc_status = wbcStringToSid(sid_str, &sid);
716 if (!WBC_ERROR_IS_OK(wbc_status)) {
717 return false;
720 wbc_status = wbcSidToGid(&sid, &gid);
721 if (!WBC_ERROR_IS_OK(wbc_status)) {
722 return false;
725 /* Display response */
727 d_printf("%d\n", (int)gid);
729 return true;
732 static bool wbinfo_allocate_uid(void)
734 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
735 uid_t uid;
737 /* Send request */
739 wbc_status = wbcAllocateUid(&uid);
740 if (!WBC_ERROR_IS_OK(wbc_status)) {
741 return false;
744 /* Display response */
746 d_printf("New uid: %d\n", uid);
748 return true;
751 static bool wbinfo_allocate_gid(void)
753 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
754 gid_t gid;
756 /* Send request */
758 wbc_status = wbcAllocateGid(&gid);
759 if (!WBC_ERROR_IS_OK(wbc_status)) {
760 return false;
763 /* Display response */
765 d_printf("New gid: %d\n", gid);
767 return true;
770 /* Convert sid to string */
772 static bool wbinfo_lookupsid(const char *sid_str)
774 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
775 struct wbcDomainSid sid;
776 char *domain;
777 char *name;
778 enum wbcSidType type;
780 /* Send off request */
782 wbc_status = wbcStringToSid(sid_str, &sid);
783 if (!WBC_ERROR_IS_OK(wbc_status)) {
784 return false;
787 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
788 if (!WBC_ERROR_IS_OK(wbc_status)) {
789 return false;
792 /* Display response */
794 d_printf("%s%c%s %d\n",
795 domain, winbind_separator(), name, type);
797 return true;
800 /* Lookup a list of RIDs */
802 static bool wbinfo_lookuprids(const char *domain, const char *arg)
804 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
805 struct wbcDomainInfo *dinfo = NULL;
806 char *domain_name = NULL;
807 const char **names = NULL;
808 enum wbcSidType *types = NULL;
809 size_t i;
810 int num_rids;
811 uint32 *rids = NULL;
812 const char *p;
813 char *ridstr;
814 TALLOC_CTX *mem_ctx = NULL;
815 bool ret = false;
817 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')) {
818 domain = get_winbind_domain();
821 /* Send request */
823 wbc_status = wbcDomainInfo(domain, &dinfo);
824 if (!WBC_ERROR_IS_OK(wbc_status)) {
825 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
826 wbcErrorString(wbc_status));
827 goto done;
830 mem_ctx = talloc_new(NULL);
831 if (mem_ctx == NULL) {
832 d_printf("talloc_new failed\n");
833 goto done;
836 num_rids = 0;
837 rids = NULL;
838 p = arg;
840 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
841 uint32 rid = strtoul(ridstr, NULL, 10);
842 ADD_TO_ARRAY(mem_ctx, uint32, rid, &rids, &num_rids);
845 if (rids == NULL) {
846 d_printf("no rids\n");
847 goto done;
850 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
851 (const char **)&domain_name, &names, &types);
852 if (!WBC_ERROR_IS_OK(wbc_status)) {
853 d_printf("winbind_lookup_rids failed: %s\n",
854 wbcErrorString(wbc_status));
855 goto done;
858 d_printf("Domain: %s\n", domain_name);
860 for (i=0; i<num_rids; i++) {
861 d_printf("%8d: %s (%s)\n", rids[i], names[i],
862 sid_type_lookup(types[i]));
865 ret = true;
866 done:
867 if (dinfo) {
868 wbcFreeMemory(dinfo);
870 if (domain_name) {
871 wbcFreeMemory(domain_name);
873 if (names) {
874 wbcFreeMemory(names);
876 if (types) {
877 wbcFreeMemory(types);
879 TALLOC_FREE(mem_ctx);
880 return ret;
883 /* Convert string to sid */
885 static bool wbinfo_lookupname(const char *full_name)
887 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
888 struct wbcDomainSid sid;
889 char *sid_str;
890 enum wbcSidType type;
891 fstring domain_name;
892 fstring account_name;
894 /* Send off request */
896 parse_wbinfo_domain_user(full_name, domain_name,
897 account_name);
899 wbc_status = wbcLookupName(domain_name, account_name,
900 &sid, &type);
901 if (!WBC_ERROR_IS_OK(wbc_status)) {
902 return false;
905 wbc_status = wbcSidToString(&sid, &sid_str);
906 if (!WBC_ERROR_IS_OK(wbc_status)) {
907 return false;
910 /* Display response */
912 d_printf("%s %s (%d)\n", sid_str, sid_type_lookup(type), type);
914 wbcFreeMemory(sid_str);
916 return true;
919 /* Authenticate a user with a plaintext password */
921 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32 flags)
923 struct winbindd_request request;
924 struct winbindd_response response;
925 NSS_STATUS result;
926 char *p;
928 /* Send off request */
930 ZERO_STRUCT(request);
931 ZERO_STRUCT(response);
933 p = strchr(username, '%');
935 if (p) {
936 *p = 0;
937 fstrcpy(request.data.auth.user, username);
938 fstrcpy(request.data.auth.pass, p + 1);
939 *p = '%';
940 } else
941 fstrcpy(request.data.auth.user, username);
943 request.flags = flags;
945 fstrcpy(request.data.auth.krb5_cc_type, cctype);
947 request.data.auth.uid = geteuid();
949 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
951 /* Display response */
953 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
954 username, (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", cctype);
956 if (response.data.auth.nt_status)
957 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
958 response.data.auth.nt_status_string,
959 response.data.auth.nt_status,
960 response.data.auth.error_string);
962 if (result == NSS_STATUS_SUCCESS) {
964 if (request.flags & WBFLAG_PAM_INFO3_TEXT) {
965 if (response.data.auth.info3.user_flgs & NETLOGON_CACHED_ACCOUNT) {
966 d_printf("user_flgs: NETLOGON_CACHED_ACCOUNT\n");
970 if (response.data.auth.krb5ccname[0] != '\0') {
971 d_printf("credentials were put in: %s\n", response.data.auth.krb5ccname);
972 } else {
973 d_printf("no credentials cached\n");
977 return result == NSS_STATUS_SUCCESS;
980 /* Authenticate a user with a plaintext password */
982 static bool wbinfo_auth(char *username)
984 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
985 char *s = NULL;
986 char *p = NULL;
987 const char *password = NULL;
988 char *name = NULL;
990 if ((s = SMB_STRDUP(username)) == NULL) {
991 return false;
994 if ((p = strchr(s, '%')) != NULL) {
995 *p = 0;
996 p++;
997 password = p;
998 } else {
999 password = "";
1002 name = s;
1004 wbc_status = wbcAuthenticateUser(name, password);
1006 d_printf("plaintext password authentication %s\n",
1007 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1009 #if 0
1010 if (response.data.auth.nt_status)
1011 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
1012 response.data.auth.nt_status_string,
1013 response.data.auth.nt_status,
1014 response.data.auth.error_string);
1015 #endif
1017 SAFE_FREE(s);
1019 return WBC_ERROR_IS_OK(wbc_status);
1022 /* Authenticate a user with a challenge/response */
1024 static bool wbinfo_auth_crap(char *username)
1026 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1027 struct wbcAuthUserParams params;
1028 struct wbcAuthUserInfo *info = NULL;
1029 struct wbcAuthErrorInfo *err = NULL;
1030 DATA_BLOB lm = data_blob_null;
1031 DATA_BLOB nt = data_blob_null;
1032 fstring name_user;
1033 fstring name_domain;
1034 fstring pass;
1035 char *p;
1037 p = strchr(username, '%');
1039 if (p) {
1040 *p = 0;
1041 fstrcpy(pass, p + 1);
1044 parse_wbinfo_domain_user(username, name_domain, name_user);
1046 params.account_name = name_user;
1047 params.domain_name = name_domain;
1048 params.workstation_name = NULL;
1050 params.flags = 0;
1051 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1052 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1054 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1056 generate_random_buffer(params.password.response.challenge, 8);
1058 if (lp_client_ntlmv2_auth()) {
1059 DATA_BLOB server_chal;
1060 DATA_BLOB names_blob;
1062 server_chal = data_blob(params.password.response.challenge, 8);
1064 /* Pretend this is a login to 'us', for blob purposes */
1065 names_blob = NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
1067 if (!SMBNTLMv2encrypt(name_user, name_domain, pass, &server_chal,
1068 &names_blob,
1069 &lm, &nt, NULL)) {
1070 data_blob_free(&names_blob);
1071 data_blob_free(&server_chal);
1072 return false;
1074 data_blob_free(&names_blob);
1075 data_blob_free(&server_chal);
1077 } else {
1078 if (lp_client_lanman_auth()) {
1079 bool ok;
1080 lm = data_blob(NULL, 24);
1081 ok = SMBencrypt(pass, params.password.response.challenge,
1082 lm.data);
1083 if (!ok) {
1084 data_blob_free(&lm);
1087 nt = data_blob(NULL, 24);
1088 SMBNTencrypt(pass, params.password.response.challenge,
1089 nt.data);
1092 params.password.response.nt_length = nt.length;
1093 params.password.response.nt_data = nt.data;
1094 params.password.response.lm_length = lm.length;
1095 params.password.response.lm_data = lm.data;
1097 wbc_status = wbcAuthenticateUserEx(&params, &info, &err);
1099 /* Display response */
1101 d_printf("challenge/response password authentication %s\n",
1102 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1104 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1105 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
1106 err->nt_string,
1107 err->nt_status,
1108 err->display_string);
1109 wbcFreeMemory(err);
1110 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1111 wbcFreeMemory(info);
1114 data_blob_free(&nt);
1115 data_blob_free(&lm);
1117 return WBC_ERROR_IS_OK(wbc_status);
1120 /* Authenticate a user with a plaintext password and set a token */
1122 static bool wbinfo_klog(char *username)
1124 struct winbindd_request request;
1125 struct winbindd_response response;
1126 NSS_STATUS result;
1127 char *p;
1129 /* Send off request */
1131 ZERO_STRUCT(request);
1132 ZERO_STRUCT(response);
1134 p = strchr(username, '%');
1136 if (p) {
1137 *p = 0;
1138 fstrcpy(request.data.auth.user, username);
1139 fstrcpy(request.data.auth.pass, p + 1);
1140 *p = '%';
1141 } else {
1142 fstrcpy(request.data.auth.user, username);
1143 fstrcpy(request.data.auth.pass, getpass("Password: "));
1146 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1148 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request, &response);
1150 /* Display response */
1152 d_printf("plaintext password authentication %s\n",
1153 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1155 if (response.data.auth.nt_status)
1156 d_fprintf(stderr, "error code was %s (0x%x)\nerror messsage was: %s\n",
1157 response.data.auth.nt_status_string,
1158 response.data.auth.nt_status,
1159 response.data.auth.error_string);
1161 if (result != NSS_STATUS_SUCCESS)
1162 return false;
1164 if (response.extra_data.data == NULL) {
1165 d_fprintf(stderr, "Did not get token data\n");
1166 return false;
1169 if (!afs_settoken_str((char *)response.extra_data.data)) {
1170 d_fprintf(stderr, "Could not set token\n");
1171 return false;
1174 d_printf("Successfully created AFS token\n");
1175 return true;
1178 /* Print domain users */
1180 static bool print_domain_users(const char *domain)
1182 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1183 uint32_t i;
1184 uint32_t num_users = 0;
1185 const char **users = NULL;
1187 /* Send request to winbind daemon */
1189 /* '.' is the special sign for our own domain */
1190 if (domain && strcmp(domain, ".") == 0) {
1191 domain = get_winbind_domain();
1194 wbc_status = wbcListUsers(domain, &num_users, &users);
1195 if (!WBC_ERROR_IS_OK(wbc_status)) {
1196 return false;
1199 for (i=0; i < num_users; i++) {
1200 d_printf("%s\n", users[i]);
1203 wbcFreeMemory(users);
1205 return true;
1208 /* Print domain groups */
1210 static bool print_domain_groups(const char *domain)
1212 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1213 uint32_t i;
1214 uint32_t num_groups = 0;
1215 const char **groups = NULL;
1217 /* Send request to winbind daemon */
1219 /* '.' is the special sign for our own domain */
1220 if (domain && strcmp(domain, ".") == 0) {
1221 domain = get_winbind_domain();
1224 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1225 if (!WBC_ERROR_IS_OK(wbc_status)) {
1226 return false;
1229 for (i=0; i < num_groups; i++) {
1230 d_printf("%s\n", groups[i]);
1233 wbcFreeMemory(groups);
1235 return true;
1238 /* Set the authorised user for winbindd access in secrets.tdb */
1240 static bool wbinfo_set_auth_user(char *username)
1242 const char *password;
1243 char *p;
1244 fstring user, domain;
1246 /* Separate into user and password */
1248 parse_wbinfo_domain_user(username, domain, user);
1250 p = strchr(user, '%');
1252 if (p != NULL) {
1253 *p = 0;
1254 password = p+1;
1255 } else {
1256 char *thepass = getpass("Password: ");
1257 if (thepass) {
1258 password = thepass;
1259 } else
1260 password = "";
1263 /* Store or remove DOMAIN\username%password in secrets.tdb */
1265 secrets_init();
1267 if (user[0]) {
1269 if (!secrets_store(SECRETS_AUTH_USER, user,
1270 strlen(user) + 1)) {
1271 d_fprintf(stderr, "error storing username\n");
1272 return false;
1275 /* We always have a domain name added by the
1276 parse_wbinfo_domain_user() function. */
1278 if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
1279 strlen(domain) + 1)) {
1280 d_fprintf(stderr, "error storing domain name\n");
1281 return false;
1284 } else {
1285 secrets_delete(SECRETS_AUTH_USER);
1286 secrets_delete(SECRETS_AUTH_DOMAIN);
1289 if (password[0]) {
1291 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
1292 strlen(password) + 1)) {
1293 d_fprintf(stderr, "error storing password\n");
1294 return false;
1297 } else
1298 secrets_delete(SECRETS_AUTH_PASSWORD);
1300 return true;
1303 static void wbinfo_get_auth_user(void)
1305 char *user, *domain, *password;
1307 /* Lift data from secrets file */
1309 secrets_fetch_ipc_userpass(&user, &domain, &password);
1311 if ((!user || !*user) && (!domain || !*domain ) && (!password || !*password)){
1313 SAFE_FREE(user);
1314 SAFE_FREE(domain);
1315 SAFE_FREE(password);
1316 d_printf("No authorised user configured\n");
1317 return;
1320 /* Pretty print authorised user info */
1322 d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? lp_winbind_separator(): "",
1323 user, password ? "%" : "", password ? password : "");
1325 SAFE_FREE(user);
1326 SAFE_FREE(domain);
1327 SAFE_FREE(password);
1330 static bool wbinfo_ping(void)
1332 wbcErr wbc_status;
1334 wbc_status = wbcPing();
1336 /* Display response */
1338 d_printf("Ping to winbindd %s\n",
1339 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1341 return WBC_ERROR_IS_OK(wbc_status);
1344 /* Main program */
1346 enum {
1347 OPT_SET_AUTH_USER = 1000,
1348 OPT_GET_AUTH_USER,
1349 OPT_DOMAIN_NAME,
1350 OPT_SEQUENCE,
1351 OPT_GETDCNAME,
1352 OPT_DSGETDCNAME,
1353 OPT_USERDOMGROUPS,
1354 OPT_USERSIDS,
1355 OPT_ALLOCATE_UID,
1356 OPT_ALLOCATE_GID,
1357 OPT_SEPARATOR,
1358 OPT_LIST_ALL_DOMAINS,
1359 OPT_LIST_OWN_DOMAIN,
1360 OPT_UID_INFO,
1361 OPT_GROUP_INFO,
1362 OPT_VERBOSE
1365 int main(int argc, char **argv, char **envp)
1367 int opt;
1368 TALLOC_CTX *frame = talloc_stackframe();
1369 poptContext pc;
1370 static char *string_arg;
1371 static char *opt_domain_name;
1372 static int int_arg;
1373 int result = 1;
1374 bool verbose = false;
1376 struct poptOption long_options[] = {
1377 POPT_AUTOHELP
1379 /* longName, shortName, argInfo, argPtr, value, descrip,
1380 argDesc */
1382 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1383 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1384 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1385 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1386 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1387 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1388 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1389 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1390 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1391 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1392 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1393 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1394 "Get a new UID out of idmap" },
1395 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1396 "Get a new GID out of idmap" },
1397 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1398 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1399 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1400 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1401 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1402 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1403 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1404 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1405 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1406 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1407 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1408 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1409 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1410 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1411 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1412 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1413 "Get a DC name for a foreign domain", "domainname" },
1414 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1415 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1416 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1417 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1418 #ifdef WITH_FAKE_KASERVER
1419 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1420 #endif
1421 #ifdef HAVE_KRB5
1422 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1423 /* destroys wbinfo --help output */
1424 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1425 #endif
1426 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1427 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1428 POPT_COMMON_CONFIGFILE
1429 POPT_COMMON_VERSION
1430 POPT_TABLEEND
1433 /* Samba client initialisation */
1434 load_case_tables();
1437 /* Parse options */
1439 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
1441 /* Parse command line options */
1443 if (argc == 1) {
1444 poptPrintHelp(pc, stderr, 0);
1445 return 1;
1448 while((opt = poptGetNextOpt(pc)) != -1) {
1449 /* get the generic configuration parameters like --domain */
1450 switch (opt) {
1451 case OPT_VERBOSE:
1452 verbose = True;
1453 break;
1457 poptFreeContext(pc);
1459 if (!lp_load(get_dyn_CONFIGFILE(), true, false, false, true)) {
1460 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
1461 get_dyn_CONFIGFILE(), strerror(errno));
1462 exit(1);
1465 if (!init_names())
1466 return 1;
1468 load_interfaces();
1470 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1471 POPT_CONTEXT_KEEP_FIRST);
1473 while((opt = poptGetNextOpt(pc)) != -1) {
1474 switch (opt) {
1475 case 'u':
1476 if (!print_domain_users(opt_domain_name)) {
1477 d_fprintf(stderr, "Error looking up domain users\n");
1478 goto done;
1480 break;
1481 case 'g':
1482 if (!print_domain_groups(opt_domain_name)) {
1483 d_fprintf(stderr, "Error looking up domain groups\n");
1484 goto done;
1486 break;
1487 case 's':
1488 if (!wbinfo_lookupsid(string_arg)) {
1489 d_fprintf(stderr, "Could not lookup sid %s\n", string_arg);
1490 goto done;
1492 break;
1493 case 'R':
1494 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
1495 d_fprintf(stderr, "Could not lookup RIDs %s\n", string_arg);
1496 goto done;
1498 break;
1499 case 'n':
1500 if (!wbinfo_lookupname(string_arg)) {
1501 d_fprintf(stderr, "Could not lookup name %s\n", string_arg);
1502 goto done;
1504 break;
1505 case 'N':
1506 if (!wbinfo_wins_byname(string_arg)) {
1507 d_fprintf(stderr, "Could not lookup WINS by name %s\n", string_arg);
1508 goto done;
1510 break;
1511 case 'I':
1512 if (!wbinfo_wins_byip(string_arg)) {
1513 d_fprintf(stderr, "Could not lookup WINS by IP %s\n", string_arg);
1514 goto done;
1516 break;
1517 case 'U':
1518 if (!wbinfo_uid_to_sid(int_arg)) {
1519 d_fprintf(stderr, "Could not convert uid %d to sid\n", int_arg);
1520 goto done;
1522 break;
1523 case 'G':
1524 if (!wbinfo_gid_to_sid(int_arg)) {
1525 d_fprintf(stderr, "Could not convert gid %d to sid\n",
1526 int_arg);
1527 goto done;
1529 break;
1530 case 'S':
1531 if (!wbinfo_sid_to_uid(string_arg)) {
1532 d_fprintf(stderr, "Could not convert sid %s to uid\n",
1533 string_arg);
1534 goto done;
1536 break;
1537 case 'Y':
1538 if (!wbinfo_sid_to_gid(string_arg)) {
1539 d_fprintf(stderr, "Could not convert sid %s to gid\n",
1540 string_arg);
1541 goto done;
1543 break;
1544 case OPT_ALLOCATE_UID:
1545 if (!wbinfo_allocate_uid()) {
1546 d_fprintf(stderr, "Could not allocate a uid\n");
1547 goto done;
1549 break;
1550 case OPT_ALLOCATE_GID:
1551 if (!wbinfo_allocate_gid()) {
1552 d_fprintf(stderr, "Could not allocate a gid\n");
1553 goto done;
1555 break;
1556 case 't':
1557 if (!wbinfo_check_secret()) {
1558 d_fprintf(stderr, "Could not check secret\n");
1559 goto done;
1561 break;
1562 case 'm':
1563 if (!wbinfo_list_domains(false, verbose)) {
1564 d_fprintf(stderr, "Could not list trusted domains\n");
1565 goto done;
1567 break;
1568 case OPT_SEQUENCE:
1569 if (!wbinfo_show_sequence(opt_domain_name)) {
1570 d_fprintf(stderr, "Could not show sequence numbers\n");
1571 goto done;
1573 break;
1574 case 'D':
1575 if (!wbinfo_domain_info(string_arg)) {
1576 d_fprintf(stderr, "Could not get domain info\n");
1577 goto done;
1579 break;
1580 case 'i':
1581 if (!wbinfo_get_userinfo(string_arg)) {
1582 d_fprintf(stderr, "Could not get info for user %s\n",
1583 string_arg);
1584 goto done;
1586 break;
1587 case OPT_UID_INFO:
1588 if ( !wbinfo_get_uidinfo(int_arg)) {
1589 d_fprintf(stderr, "Could not get info for uid "
1590 "%d\n", int_arg);
1591 goto done;
1593 break;
1594 case OPT_GROUP_INFO:
1595 if ( !wbinfo_get_groupinfo(string_arg)) {
1596 d_fprintf(stderr, "Could not get info for "
1597 "group %s\n", string_arg);
1598 goto done;
1600 break;
1601 case 'r':
1602 if (!wbinfo_get_usergroups(string_arg)) {
1603 d_fprintf(stderr, "Could not get groups for user %s\n",
1604 string_arg);
1605 goto done;
1607 break;
1608 case OPT_USERSIDS:
1609 if (!wbinfo_get_usersids(string_arg)) {
1610 d_fprintf(stderr, "Could not get group SIDs for user SID %s\n",
1611 string_arg);
1612 goto done;
1614 break;
1615 case OPT_USERDOMGROUPS:
1616 if (!wbinfo_get_userdomgroups(string_arg)) {
1617 d_fprintf(stderr, "Could not get user's domain groups "
1618 "for user SID %s\n", string_arg);
1619 goto done;
1621 break;
1622 case 'a': {
1623 bool got_error = false;
1625 if (!wbinfo_auth(string_arg)) {
1626 d_fprintf(stderr, "Could not authenticate user %s with "
1627 "plaintext password\n", string_arg);
1628 got_error = true;
1631 if (!wbinfo_auth_crap(string_arg)) {
1632 d_fprintf(stderr, "Could not authenticate user %s with "
1633 "challenge/response\n", string_arg);
1634 got_error = true;
1637 if (got_error)
1638 goto done;
1639 break;
1641 case 'K': {
1642 uint32 flags = WBFLAG_PAM_KRB5 |
1643 WBFLAG_PAM_CACHED_LOGIN |
1644 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
1645 WBFLAG_PAM_INFO3_TEXT;
1647 if (!wbinfo_auth_krb5(string_arg, "FILE", flags)) {
1648 d_fprintf(stderr, "Could not authenticate user [%s] with "
1649 "Kerberos (ccache: %s)\n", string_arg, "FILE");
1650 goto done;
1652 break;
1654 case 'k':
1655 if (!wbinfo_klog(string_arg)) {
1656 d_fprintf(stderr, "Could not klog user\n");
1657 goto done;
1659 break;
1660 case 'p':
1661 if (!wbinfo_ping()) {
1662 d_fprintf(stderr, "could not ping winbindd!\n");
1663 goto done;
1665 break;
1666 case OPT_SET_AUTH_USER:
1667 if (!wbinfo_set_auth_user(string_arg)) {
1668 goto done;
1670 break;
1671 case OPT_GET_AUTH_USER:
1672 wbinfo_get_auth_user();
1673 break;
1674 case OPT_GETDCNAME:
1675 if (!wbinfo_getdcname(string_arg)) {
1676 goto done;
1678 break;
1679 case OPT_DSGETDCNAME:
1680 if (!wbinfo_dsgetdcname(string_arg, 0)) {
1681 goto done;
1683 break;
1684 case OPT_SEPARATOR: {
1685 const char sep = winbind_separator_int(true);
1686 if ( !sep ) {
1687 goto done;
1689 d_printf("%c\n", sep);
1690 break;
1692 case OPT_LIST_ALL_DOMAINS:
1693 if (!wbinfo_list_domains(true, verbose)) {
1694 goto done;
1696 break;
1697 case OPT_LIST_OWN_DOMAIN:
1698 if (!wbinfo_list_own_domain()) {
1699 goto done;
1701 break;
1702 /* generic configuration options */
1703 case OPT_DOMAIN_NAME:
1704 break;
1705 case OPT_VERBOSE:
1706 break;
1707 default:
1708 d_fprintf(stderr, "Invalid option\n");
1709 poptPrintHelp(pc, stderr, 0);
1710 goto done;
1714 result = 0;
1716 /* Exit code */
1718 done:
1719 talloc_destroy(frame);
1721 poptFreeContext(pc);
1722 return result;