s4-smbtorture: add RPC-SPOOLSS-DRIVER test.
[Samba/ekacnet.git] / nsswitch / wbinfo.c
blobca1fefb606d168d5290a141f9c179fadf8fc1f30
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2003
7 Copyright (C) Andrew Bartlett 2002-2007
8 Copyright (C) Volker Lendecke 2009
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "includes.h"
25 #include "winbind_client.h"
26 #include "libwbclient/wbclient.h"
27 #include "lib/popt/popt.h"
28 #include "../libcli/auth/libcli_auth.h"
29 #if (_SAMBA_BUILD_) >= 4
30 #include "lib/cmdline/popt_common.h"
31 #endif
33 #ifdef DBGC_CLASS
34 #undef DBGC_CLASS
35 #define DBGC_CLASS DBGC_WINBIND
36 #endif
38 static struct wbcInterfaceDetails *init_interface_details(void)
40 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
41 static struct wbcInterfaceDetails *details;
43 if (details) {
44 return details;
47 wbc_status = wbcInterfaceDetails(&details);
48 if (!WBC_ERROR_IS_OK(wbc_status)) {
49 d_fprintf(stderr, "could not obtain winbind interface "
50 "details!\n");
53 return details;
56 static char winbind_separator(void)
58 struct wbcInterfaceDetails *details;
59 static bool got_sep;
60 static char sep;
62 if (got_sep)
63 return sep;
65 details = init_interface_details();
67 if (!details) {
68 d_fprintf(stderr, "could not obtain winbind separator!\n");
69 return 0;
72 sep = details->winbind_separator;
73 got_sep = true;
75 wbcFreeMemory(details);
77 if (!sep) {
78 d_fprintf(stderr, "winbind separator was NULL!\n");
79 return 0;
82 return sep;
85 static const char *get_winbind_domain(void)
87 static struct wbcInterfaceDetails *details;
89 details = init_interface_details();
91 if (!details) {
92 d_fprintf(stderr, "could not obtain winbind domain name!\n");
93 return 0;
96 return details->netbios_domain;
99 static const char *get_winbind_netbios_name(void)
101 static struct wbcInterfaceDetails *details;
103 details = init_interface_details();
105 if (!details) {
106 d_fprintf(stderr, "could not obtain winbind netbios name!\n");
107 return 0;
110 return details->netbios_name;
113 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
114 form DOMAIN/user into a domain and a user */
116 static bool parse_wbinfo_domain_user(const char *domuser, fstring domain,
117 fstring user)
120 char *p = strchr(domuser,winbind_separator());
122 if (!p) {
123 /* Maybe it was a UPN? */
124 if ((p = strchr(domuser, '@')) != NULL) {
125 fstrcpy(domain, "");
126 fstrcpy(user, domuser);
127 return true;
130 fstrcpy(user, domuser);
131 fstrcpy(domain, get_winbind_domain());
132 return true;
135 fstrcpy(user, p+1);
136 fstrcpy(domain, domuser);
137 domain[PTR_DIFF(p, domuser)] = 0;
138 strupper_m(domain);
140 return true;
143 /* Parse string of "uid,sid" or "gid,sid" into separate int and string values.
144 * Return true if input was valid, false otherwise. */
145 static bool parse_mapping_arg(char *arg, int *id, char **sid)
147 char *tmp, *endptr;
149 if (!arg || !*arg)
150 return false;
152 tmp = strtok(arg, ",");
153 *sid = strtok(NULL, ",");
155 if (!tmp || !*tmp || !*sid || !**sid)
156 return false;
158 /* Because atoi() can return 0 on invalid input, which would be a valid
159 * UID/GID we must use strtoul() and do error checking */
160 *id = strtoul(tmp, &endptr, 10);
162 if (endptr[0] != '\0')
163 return false;
165 return true;
168 /* pull pwent info for a given user */
170 static bool wbinfo_get_userinfo(char *user)
172 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
173 struct passwd *pwd = NULL;
175 wbc_status = wbcGetpwnam(user, &pwd);
176 if (!WBC_ERROR_IS_OK(wbc_status)) {
177 return false;
180 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
181 pwd->pw_name,
182 pwd->pw_passwd,
183 (unsigned int)pwd->pw_uid,
184 (unsigned int)pwd->pw_gid,
185 pwd->pw_gecos,
186 pwd->pw_dir,
187 pwd->pw_shell);
189 return true;
192 /* pull pwent info for a given uid */
193 static bool wbinfo_get_uidinfo(int uid)
195 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
196 struct passwd *pwd = NULL;
198 wbc_status = wbcGetpwuid(uid, &pwd);
199 if (!WBC_ERROR_IS_OK(wbc_status)) {
200 return false;
203 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
204 pwd->pw_name,
205 pwd->pw_passwd,
206 (unsigned int)pwd->pw_uid,
207 (unsigned int)pwd->pw_gid,
208 pwd->pw_gecos,
209 pwd->pw_dir,
210 pwd->pw_shell);
212 return true;
215 static bool wbinfo_get_user_sidinfo(const char *sid_str)
217 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
218 struct passwd *pwd = NULL;
219 struct wbcDomainSid sid;
221 wbc_status = wbcStringToSid(sid_str, &sid);
222 wbc_status = wbcGetpwsid(&sid, &pwd);
223 if (!WBC_ERROR_IS_OK(wbc_status)) {
224 return false;
227 d_printf("%s:%s:%u:%u:%s:%s:%s\n",
228 pwd->pw_name,
229 pwd->pw_passwd,
230 (unsigned int)pwd->pw_uid,
231 (unsigned int)pwd->pw_gid,
232 pwd->pw_gecos,
233 pwd->pw_dir,
234 pwd->pw_shell);
236 return true;
240 /* pull grent for a given group */
241 static bool wbinfo_get_groupinfo(const char *group)
243 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
244 struct group *grp;
245 char **mem;
247 wbc_status = wbcGetgrnam(group, &grp);
248 if (!WBC_ERROR_IS_OK(wbc_status)) {
249 return false;
252 d_printf("%s:%s:%u:",
253 grp->gr_name,
254 grp->gr_passwd,
255 (unsigned int)grp->gr_gid);
257 mem = grp->gr_mem;
258 while (*mem != NULL) {
259 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
260 mem += 1;
262 d_printf("\n");
264 wbcFreeMemory(grp);
266 return true;
269 /* pull grent for a given gid */
270 static bool wbinfo_get_gidinfo(int gid)
272 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
273 struct group *grp;
274 char **mem;
276 wbc_status = wbcGetgrgid(gid, &grp);
277 if (!WBC_ERROR_IS_OK(wbc_status)) {
278 return false;
281 d_printf("%s:%s:%u:",
282 grp->gr_name,
283 grp->gr_passwd,
284 (unsigned int)grp->gr_gid);
286 mem = grp->gr_mem;
287 while (*mem != NULL) {
288 d_printf("%s%s", *mem, *(mem+1) != NULL ? "," : "");
289 mem += 1;
291 d_printf("\n");
293 wbcFreeMemory(grp);
295 return true;
298 /* List groups a user is a member of */
300 static bool wbinfo_get_usergroups(const char *user)
302 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
303 uint32_t num_groups;
304 uint32_t i;
305 gid_t *groups = NULL;
307 /* Send request */
309 wbc_status = wbcGetGroups(user, &num_groups, &groups);
310 if (!WBC_ERROR_IS_OK(wbc_status)) {
311 return false;
314 for (i = 0; i < num_groups; i++) {
315 d_printf("%d\n", (int)groups[i]);
318 wbcFreeMemory(groups);
320 return true;
324 /* List group SIDs a user SID is a member of */
325 static bool wbinfo_get_usersids(const char *user_sid_str)
327 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
328 uint32_t num_sids;
329 uint32_t i;
330 struct wbcDomainSid user_sid, *sids = NULL;
332 /* Send request */
334 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
335 if (!WBC_ERROR_IS_OK(wbc_status)) {
336 return false;
339 wbc_status = wbcLookupUserSids(&user_sid, false, &num_sids, &sids);
340 if (!WBC_ERROR_IS_OK(wbc_status)) {
341 return false;
344 for (i = 0; i < num_sids; i++) {
345 char *str = NULL;
346 wbc_status = wbcSidToString(&sids[i], &str);
347 if (!WBC_ERROR_IS_OK(wbc_status)) {
348 wbcFreeMemory(sids);
349 return false;
351 d_printf("%s\n", str);
352 wbcFreeMemory(str);
355 wbcFreeMemory(sids);
357 return true;
360 static bool wbinfo_get_userdomgroups(const char *user_sid_str)
362 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
363 uint32_t num_sids;
364 uint32_t i;
365 struct wbcDomainSid user_sid, *sids = NULL;
367 /* Send request */
369 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
370 if (!WBC_ERROR_IS_OK(wbc_status)) {
371 return false;
374 wbc_status = wbcLookupUserSids(&user_sid, true, &num_sids, &sids);
375 if (!WBC_ERROR_IS_OK(wbc_status)) {
376 return false;
379 for (i = 0; i < num_sids; i++) {
380 char *str = NULL;
381 wbc_status = wbcSidToString(&sids[i], &str);
382 if (!WBC_ERROR_IS_OK(wbc_status)) {
383 wbcFreeMemory(sids);
384 return false;
386 d_printf("%s\n", str);
387 wbcFreeMemory(str);
390 wbcFreeMemory(sids);
392 return true;
395 static bool wbinfo_get_sidaliases(const char *domain,
396 const char *user_sid_str)
398 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
399 struct wbcDomainInfo *dinfo = NULL;
400 uint32_t i;
401 struct wbcDomainSid user_sid;
402 uint32_t *alias_rids = NULL;
403 uint32_t num_alias_rids;
404 char *domain_sid_str = NULL;
406 /* Send request */
407 if ((domain == NULL) || (strequal(domain, ".")) ||
408 (domain[0] == '\0')) {
409 domain = get_winbind_domain();
412 /* Send request */
414 wbc_status = wbcDomainInfo(domain, &dinfo);
415 if (!WBC_ERROR_IS_OK(wbc_status)) {
416 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
417 wbcErrorString(wbc_status));
418 goto done;
420 wbc_status = wbcStringToSid(user_sid_str, &user_sid);
421 if (!WBC_ERROR_IS_OK(wbc_status)) {
422 goto done;
425 wbc_status = wbcGetSidAliases(&dinfo->sid, &user_sid, 1,
426 &alias_rids, &num_alias_rids);
427 if (!WBC_ERROR_IS_OK(wbc_status)) {
428 goto done;
431 wbc_status = wbcSidToString(&dinfo->sid, &domain_sid_str);
432 if (!WBC_ERROR_IS_OK(wbc_status)) {
433 goto done;
436 for (i = 0; i < num_alias_rids; i++) {
437 d_printf("%s-%d\n", domain_sid_str, alias_rids[i]);
440 wbcFreeMemory(alias_rids);
442 done:
443 if (domain_sid_str) {
444 wbcFreeMemory(domain_sid_str);
446 if (dinfo) {
447 wbcFreeMemory(dinfo);
449 return (WBC_ERR_SUCCESS == wbc_status);
453 /* Convert NetBIOS name to IP */
455 static bool wbinfo_wins_byname(const char *name)
457 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
458 char *ip = NULL;
460 wbc_status = wbcResolveWinsByName(name, &ip);
461 if (!WBC_ERROR_IS_OK(wbc_status)) {
462 return false;
465 /* Display response */
467 d_printf("%s\n", ip);
469 wbcFreeMemory(ip);
471 return true;
474 /* Convert IP to NetBIOS name */
476 static bool wbinfo_wins_byip(const char *ip)
478 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
479 char *name = NULL;
481 wbc_status = wbcResolveWinsByIP(ip, &name);
482 if (!WBC_ERROR_IS_OK(wbc_status)) {
483 return false;
486 /* Display response */
488 d_printf("%s\n", name);
490 wbcFreeMemory(name);
492 return true;
495 /* List all/trusted domains */
497 static bool wbinfo_list_domains(bool list_all_domains, bool verbose)
499 struct wbcDomainInfo *domain_list = NULL;
500 size_t num_domains;
501 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
502 bool print_all = !list_all_domains && verbose;
503 int i;
505 wbc_status = wbcListTrusts(&domain_list, &num_domains);
506 if (!WBC_ERROR_IS_OK(wbc_status)) {
507 return false;
510 if (print_all) {
511 d_printf("%-16s%-24s%-12s%-12s%-5s%-5s\n",
512 "Domain Name", "DNS Domain", "Trust Type",
513 "Transitive", "In", "Out");
516 for (i=0; i<num_domains; i++) {
517 if (print_all) {
518 d_printf("%-16s", domain_list[i].short_name);
519 } else {
520 d_printf("%s", domain_list[i].short_name);
521 d_printf("\n");
522 continue;
525 d_printf("%-24s", domain_list[i].dns_name);
527 switch(domain_list[i].trust_type) {
528 case WBC_DOMINFO_TRUSTTYPE_NONE:
529 d_printf("None ");
530 break;
531 case WBC_DOMINFO_TRUSTTYPE_FOREST:
532 d_printf("Forest ");
533 break;
534 case WBC_DOMINFO_TRUSTTYPE_EXTERNAL:
535 d_printf("External ");
536 break;
537 case WBC_DOMINFO_TRUSTTYPE_IN_FOREST:
538 d_printf("In-Forest ");
539 break;
542 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_TRANSITIVE) {
543 d_printf("Yes ");
544 } else {
545 d_printf("No ");
548 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_INCOMING) {
549 d_printf("Yes ");
550 } else {
551 d_printf("No ");
554 if (domain_list[i].trust_flags & WBC_DOMINFO_TRUST_OUTGOING) {
555 d_printf("Yes ");
556 } else {
557 d_printf("No ");
560 d_printf("\n");
563 return true;
566 /* List own domain */
568 static bool wbinfo_list_own_domain(void)
570 d_printf("%s\n", get_winbind_domain());
572 return true;
575 /* show sequence numbers */
576 static bool wbinfo_show_sequence(const char *domain)
578 d_printf("This command has been deprecated. Please use the "
579 "--online-status option instead.\n");
580 return false;
583 /* show sequence numbers */
584 static bool wbinfo_show_onlinestatus(const char *domain)
586 struct wbcDomainInfo *domain_list = NULL;
587 size_t num_domains;
588 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
589 int i;
591 wbc_status = wbcListTrusts(&domain_list, &num_domains);
592 if (!WBC_ERROR_IS_OK(wbc_status)) {
593 return false;
596 for (i=0; i<num_domains; i++) {
597 bool is_offline;
599 if (domain) {
600 if (!strequal(domain_list[i].short_name, domain)) {
601 continue;
605 is_offline = (domain_list[i].domain_flags &
606 WBC_DOMINFO_DOMAIN_OFFLINE);
608 d_printf("%s : %s\n",
609 domain_list[i].short_name,
610 is_offline ? "offline" : "online" );
613 return true;
617 /* Show domain info */
619 static bool wbinfo_domain_info(const char *domain)
621 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
622 struct wbcDomainInfo *dinfo = NULL;
623 char *sid_str = NULL;
625 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
626 domain = get_winbind_domain();
629 /* Send request */
631 wbc_status = wbcDomainInfo(domain, &dinfo);
632 if (!WBC_ERROR_IS_OK(wbc_status)) {
633 return false;
636 wbc_status = wbcSidToString(&dinfo->sid, &sid_str);
637 if (!WBC_ERROR_IS_OK(wbc_status)) {
638 wbcFreeMemory(dinfo);
639 return false;
642 /* Display response */
644 d_printf("Name : %s\n", dinfo->short_name);
645 d_printf("Alt_Name : %s\n", dinfo->dns_name);
647 d_printf("SID : %s\n", sid_str);
649 d_printf("Active Directory : %s\n",
650 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_AD) ? "Yes" : "No");
651 d_printf("Native : %s\n",
652 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_NATIVE) ?
653 "Yes" : "No");
655 d_printf("Primary : %s\n",
656 (dinfo->domain_flags & WBC_DOMINFO_DOMAIN_PRIMARY) ?
657 "Yes" : "No");
659 wbcFreeMemory(sid_str);
660 wbcFreeMemory(dinfo);
662 return true;
665 /* Get a foreign DC's name */
666 static bool wbinfo_getdcname(const char *domain_name)
668 struct winbindd_request request;
669 struct winbindd_response response;
671 ZERO_STRUCT(request);
672 ZERO_STRUCT(response);
674 fstrcpy(request.domain_name, domain_name);
676 /* Send request */
678 if (winbindd_request_response(WINBINDD_GETDCNAME, &request,
679 &response) != NSS_STATUS_SUCCESS) {
680 d_fprintf(stderr, "Could not get dc name for %s\n",domain_name);
681 return false;
684 /* Display response */
686 d_printf("%s\n", response.data.dc_name);
688 return true;
691 /* Find a DC */
692 static bool wbinfo_dsgetdcname(const char *domain_name, uint32_t flags)
694 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
695 struct wbcDomainControllerInfoEx *dc_info;
696 char *str = NULL;
698 wbc_status = wbcLookupDomainControllerEx(domain_name, NULL, NULL,
699 flags | DS_DIRECTORY_SERVICE_REQUIRED,
700 &dc_info);
701 if (!WBC_ERROR_IS_OK(wbc_status)) {
702 printf("Could not find dc for %s\n", domain_name);
703 return false;
706 wbcGuidToString(dc_info->domain_guid, &str);
708 d_printf("%s\n", dc_info->dc_unc);
709 d_printf("%s\n", dc_info->dc_address);
710 d_printf("%d\n", dc_info->dc_address_type);
711 d_printf("%s\n", str);
712 d_printf("%s\n", dc_info->domain_name);
713 d_printf("%s\n", dc_info->forest_name);
714 d_printf("0x%08x\n", dc_info->dc_flags);
715 d_printf("%s\n", dc_info->dc_site_name);
716 d_printf("%s\n", dc_info->client_site_name);
718 return true;
721 /* Check trust account password */
723 static bool wbinfo_check_secret(const char *domain)
725 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
726 struct wbcAuthErrorInfo *error = NULL;
727 const char *domain_name;
729 if (domain) {
730 domain_name = domain;
731 } else {
732 domain_name = get_winbind_domain();
735 wbc_status = wbcCheckTrustCredentials(domain_name, &error);
737 d_printf("checking the trust secret for domain %s via RPC calls %s\n",
738 domain_name,
739 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
741 if (wbc_status == WBC_ERR_AUTH_ERROR) {
742 d_fprintf(stderr, "error code was %s (0x%x)\n",
743 error->nt_string, error->nt_status);
744 wbcFreeMemory(error);
746 if (!WBC_ERROR_IS_OK(wbc_status)) {
747 return false;
750 return true;
753 /* Change trust account password */
755 static bool wbinfo_change_secret(const char *domain)
757 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
758 struct wbcAuthErrorInfo *error = NULL;
759 const char *domain_name;
761 if (domain) {
762 domain_name = domain;
763 } else {
764 domain_name = get_winbind_domain();
767 wbc_status = wbcChangeTrustCredentials(domain_name, &error);
769 d_printf("changing the trust secret for domain %s via RPC calls %s\n",
770 domain_name,
771 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
773 if (wbc_status == WBC_ERR_AUTH_ERROR) {
774 d_fprintf(stderr, "error code was %s (0x%x)\n",
775 error->nt_string, error->nt_status);
776 wbcFreeMemory(error);
778 if (!WBC_ERROR_IS_OK(wbc_status)) {
779 return false;
782 return true;
785 /* Check DC connection */
787 static bool wbinfo_ping_dc(void)
789 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
790 struct wbcAuthErrorInfo *error = NULL;
792 wbc_status = wbcPingDc(NULL, &error);
794 d_printf("checking the NETLOGON dc connection %s\n",
795 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
797 if (wbc_status == WBC_ERR_AUTH_ERROR) {
798 d_fprintf(stderr, "error code was %s (0x%x)\n",
799 error->nt_string, error->nt_status);
800 wbcFreeMemory(error);
802 if (!WBC_ERROR_IS_OK(wbc_status)) {
803 return false;
806 return true;
809 /* Convert uid to sid */
811 static bool wbinfo_uid_to_sid(uid_t uid)
813 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
814 struct wbcDomainSid sid;
815 char *sid_str = NULL;
817 /* Send request */
819 wbc_status = wbcUidToSid(uid, &sid);
820 if (!WBC_ERROR_IS_OK(wbc_status)) {
821 return false;
824 wbc_status = wbcSidToString(&sid, &sid_str);
825 if (!WBC_ERROR_IS_OK(wbc_status)) {
826 return false;
829 /* Display response */
831 d_printf("%s\n", sid_str);
833 wbcFreeMemory(sid_str);
835 return true;
838 /* Convert gid to sid */
840 static bool wbinfo_gid_to_sid(gid_t gid)
842 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
843 struct wbcDomainSid sid;
844 char *sid_str = NULL;
846 /* Send request */
848 wbc_status = wbcGidToSid(gid, &sid);
849 if (!WBC_ERROR_IS_OK(wbc_status)) {
850 return false;
853 wbc_status = wbcSidToString(&sid, &sid_str);
854 if (!WBC_ERROR_IS_OK(wbc_status)) {
855 return false;
858 /* Display response */
860 d_printf("%s\n", sid_str);
862 wbcFreeMemory(sid_str);
864 return true;
867 /* Convert sid to uid */
869 static bool wbinfo_sid_to_uid(const char *sid_str)
871 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
872 struct wbcDomainSid sid;
873 uid_t uid;
875 /* Send request */
877 wbc_status = wbcStringToSid(sid_str, &sid);
878 if (!WBC_ERROR_IS_OK(wbc_status)) {
879 return false;
882 wbc_status = wbcSidToUid(&sid, &uid);
883 if (!WBC_ERROR_IS_OK(wbc_status)) {
884 return false;
887 /* Display response */
889 d_printf("%d\n", (int)uid);
891 return true;
894 static bool wbinfo_sid_to_gid(const char *sid_str)
896 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
897 struct wbcDomainSid sid;
898 gid_t gid;
900 /* Send request */
902 wbc_status = wbcStringToSid(sid_str, &sid);
903 if (!WBC_ERROR_IS_OK(wbc_status)) {
904 return false;
907 wbc_status = wbcSidToGid(&sid, &gid);
908 if (!WBC_ERROR_IS_OK(wbc_status)) {
909 return false;
912 /* Display response */
914 d_printf("%d\n", (int)gid);
916 return true;
919 static bool wbinfo_allocate_uid(void)
921 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
922 uid_t uid;
924 /* Send request */
926 wbc_status = wbcAllocateUid(&uid);
927 if (!WBC_ERROR_IS_OK(wbc_status)) {
928 return false;
931 /* Display response */
933 d_printf("New uid: %u\n", (unsigned int)uid);
935 return true;
938 static bool wbinfo_allocate_gid(void)
940 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
941 gid_t gid;
943 /* Send request */
945 wbc_status = wbcAllocateGid(&gid);
946 if (!WBC_ERROR_IS_OK(wbc_status)) {
947 return false;
950 /* Display response */
952 d_printf("New gid: %u\n", (unsigned int)gid);
954 return true;
957 static bool wbinfo_set_uid_mapping(uid_t uid, const char *sid_str)
959 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
960 struct wbcDomainSid sid;
962 /* Send request */
964 wbc_status = wbcStringToSid(sid_str, &sid);
965 if (!WBC_ERROR_IS_OK(wbc_status)) {
966 return false;
969 wbc_status = wbcSetUidMapping(uid, &sid);
970 if (!WBC_ERROR_IS_OK(wbc_status)) {
971 return false;
974 /* Display response */
976 d_printf("uid %u now mapped to sid %s\n",
977 (unsigned int)uid, sid_str);
979 return true;
982 static bool wbinfo_set_gid_mapping(gid_t gid, const char *sid_str)
984 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
985 struct wbcDomainSid sid;
987 /* Send request */
989 wbc_status = wbcStringToSid(sid_str, &sid);
990 if (!WBC_ERROR_IS_OK(wbc_status)) {
991 return false;
994 wbc_status = wbcSetGidMapping(gid, &sid);
995 if (!WBC_ERROR_IS_OK(wbc_status)) {
996 return false;
999 /* Display response */
1001 d_printf("gid %u now mapped to sid %s\n",
1002 (unsigned int)gid, sid_str);
1004 return true;
1007 static bool wbinfo_remove_uid_mapping(uid_t uid, const char *sid_str)
1009 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1010 struct wbcDomainSid sid;
1012 /* Send request */
1014 wbc_status = wbcStringToSid(sid_str, &sid);
1015 if (!WBC_ERROR_IS_OK(wbc_status)) {
1016 return false;
1019 wbc_status = wbcRemoveUidMapping(uid, &sid);
1020 if (!WBC_ERROR_IS_OK(wbc_status)) {
1021 return false;
1024 /* Display response */
1026 d_printf("Removed uid %u to sid %s mapping\n",
1027 (unsigned int)uid, sid_str);
1029 return true;
1032 static bool wbinfo_remove_gid_mapping(gid_t gid, const char *sid_str)
1034 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1035 struct wbcDomainSid sid;
1037 /* Send request */
1039 wbc_status = wbcStringToSid(sid_str, &sid);
1040 if (!WBC_ERROR_IS_OK(wbc_status)) {
1041 return false;
1044 wbc_status = wbcRemoveGidMapping(gid, &sid);
1045 if (!WBC_ERROR_IS_OK(wbc_status)) {
1046 return false;
1049 /* Display response */
1051 d_printf("Removed gid %u to sid %s mapping\n",
1052 (unsigned int)gid, sid_str);
1054 return true;
1057 /* Convert sid to string */
1059 static bool wbinfo_lookupsid(const char *sid_str)
1061 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1062 struct wbcDomainSid sid;
1063 char *domain;
1064 char *name;
1065 enum wbcSidType type;
1067 /* Send off request */
1069 wbc_status = wbcStringToSid(sid_str, &sid);
1070 if (!WBC_ERROR_IS_OK(wbc_status)) {
1071 return false;
1074 wbc_status = wbcLookupSid(&sid, &domain, &name, &type);
1075 if (!WBC_ERROR_IS_OK(wbc_status)) {
1076 return false;
1079 /* Display response */
1081 d_printf("%s%c%s %d\n",
1082 domain, winbind_separator(), name, type);
1084 return true;
1087 /* Convert sid to fullname */
1089 static bool wbinfo_lookupsid_fullname(const char *sid_str)
1091 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1092 struct wbcDomainSid sid;
1093 char *domain;
1094 char *name;
1095 enum wbcSidType type;
1097 /* Send off request */
1099 wbc_status = wbcStringToSid(sid_str, &sid);
1100 if (!WBC_ERROR_IS_OK(wbc_status)) {
1101 return false;
1104 wbc_status = wbcGetDisplayName(&sid, &domain, &name, &type);
1105 if (!WBC_ERROR_IS_OK(wbc_status)) {
1106 return false;
1109 /* Display response */
1111 d_printf("%s%c%s %d\n",
1112 domain, winbind_separator(), name, type);
1114 return true;
1117 /* Lookup a list of RIDs */
1119 static bool wbinfo_lookuprids(const char *domain, const char *arg)
1121 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1122 struct wbcDomainInfo *dinfo = NULL;
1123 char *domain_name = NULL;
1124 const char **names = NULL;
1125 enum wbcSidType *types = NULL;
1126 size_t i;
1127 int num_rids;
1128 uint32_t *rids = NULL;
1129 const char *p;
1130 char *ridstr;
1131 TALLOC_CTX *mem_ctx = NULL;
1132 bool ret = false;
1134 if ((domain == NULL) || (strequal(domain, ".")) || (domain[0] == '\0')){
1135 domain = get_winbind_domain();
1138 /* Send request */
1140 wbc_status = wbcDomainInfo(domain, &dinfo);
1141 if (!WBC_ERROR_IS_OK(wbc_status)) {
1142 d_printf("wbcDomainInfo(%s) failed: %s\n", domain,
1143 wbcErrorString(wbc_status));
1144 goto done;
1147 mem_ctx = talloc_new(NULL);
1148 if (mem_ctx == NULL) {
1149 d_printf("talloc_new failed\n");
1150 goto done;
1153 num_rids = 0;
1154 rids = NULL;
1155 p = arg;
1157 while (next_token_talloc(mem_ctx, &p, &ridstr, " ,\n")) {
1158 uint32_t rid = strtoul(ridstr, NULL, 10);
1159 rids = talloc_realloc(mem_ctx, rids, uint32_t, num_rids + 1);
1160 if (rids == NULL) {
1161 d_printf("talloc_realloc failed\n");
1163 rids[num_rids] = rid;
1164 num_rids += 1;
1167 if (rids == NULL) {
1168 d_printf("no rids\n");
1169 goto done;
1172 wbc_status = wbcLookupRids(&dinfo->sid, num_rids, rids,
1173 (const char **)&domain_name, &names, &types);
1174 if (!WBC_ERROR_IS_OK(wbc_status)) {
1175 d_printf("winbind_lookup_rids failed: %s\n",
1176 wbcErrorString(wbc_status));
1177 goto done;
1180 d_printf("Domain: %s\n", domain_name);
1182 for (i=0; i<num_rids; i++) {
1183 d_printf("%8d: %s (%s)\n", rids[i], names[i],
1184 wbcSidTypeString(types[i]));
1187 ret = true;
1188 done:
1189 if (dinfo) {
1190 wbcFreeMemory(dinfo);
1192 if (domain_name) {
1193 wbcFreeMemory(domain_name);
1195 if (names) {
1196 wbcFreeMemory(names);
1198 if (types) {
1199 wbcFreeMemory(types);
1201 TALLOC_FREE(mem_ctx);
1202 return ret;
1205 /* Convert string to sid */
1207 static bool wbinfo_lookupname(const char *full_name)
1209 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1210 struct wbcDomainSid sid;
1211 char *sid_str;
1212 enum wbcSidType type;
1213 fstring domain_name;
1214 fstring account_name;
1216 /* Send off request */
1218 parse_wbinfo_domain_user(full_name, domain_name,
1219 account_name);
1221 wbc_status = wbcLookupName(domain_name, account_name,
1222 &sid, &type);
1223 if (!WBC_ERROR_IS_OK(wbc_status)) {
1224 return false;
1227 wbc_status = wbcSidToString(&sid, &sid_str);
1228 if (!WBC_ERROR_IS_OK(wbc_status)) {
1229 return false;
1232 /* Display response */
1234 d_printf("%s %s (%d)\n", sid_str, wbcSidTypeString(type), type);
1236 wbcFreeMemory(sid_str);
1238 return true;
1241 static char *wbinfo_prompt_pass(TALLOC_CTX *mem_ctx,
1242 const char *prefix,
1243 const char *username)
1245 char *prompt;
1246 const char *ret = NULL;
1248 prompt = talloc_asprintf(mem_ctx, "Enter %s's ", username);
1249 if (!prompt) {
1250 return NULL;
1252 if (prefix) {
1253 prompt = talloc_asprintf_append(prompt, "%s ", prefix);
1254 if (!prompt) {
1255 return NULL;
1258 prompt = talloc_asprintf_append(prompt, "password: ");
1259 if (!prompt) {
1260 return NULL;
1263 ret = getpass(prompt);
1264 TALLOC_FREE(prompt);
1266 return talloc_strdup(mem_ctx, ret);
1269 /* Authenticate a user with a plaintext password */
1271 static bool wbinfo_auth_krb5(char *username, const char *cctype, uint32_t flags)
1273 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1274 char *s = NULL;
1275 char *p = NULL;
1276 char *password = NULL;
1277 char *name = NULL;
1278 char *local_cctype = NULL;
1279 uid_t uid;
1280 struct wbcLogonUserParams params;
1281 struct wbcLogonUserInfo *info;
1282 struct wbcAuthErrorInfo *error;
1283 struct wbcUserPasswordPolicyInfo *policy;
1284 TALLOC_CTX *frame = talloc_tos();
1286 if ((s = talloc_strdup(frame, username)) == NULL) {
1287 return false;
1290 if ((p = strchr(s, '%')) != NULL) {
1291 *p = 0;
1292 p++;
1293 password = talloc_strdup(frame, p);
1294 } else {
1295 password = wbinfo_prompt_pass(frame, NULL, username);
1298 local_cctype = talloc_strdup(frame, cctype);
1300 name = s;
1302 uid = geteuid();
1304 params.username = name;
1305 params.password = password;
1306 params.num_blobs = 0;
1307 params.blobs = NULL;
1309 wbc_status = wbcAddNamedBlob(&params.num_blobs,
1310 &params.blobs,
1311 "flags",
1313 (uint8_t *)&flags,
1314 sizeof(flags));
1315 if (!WBC_ERROR_IS_OK(wbc_status)) {
1316 goto done;
1319 wbc_status = wbcAddNamedBlob(&params.num_blobs,
1320 &params.blobs,
1321 "user_uid",
1323 (uint8_t *)&uid,
1324 sizeof(uid));
1325 if (!WBC_ERROR_IS_OK(wbc_status)) {
1326 goto done;
1329 wbc_status = wbcAddNamedBlob(&params.num_blobs,
1330 &params.blobs,
1331 "krb5_cc_type",
1333 (uint8_t *)local_cctype,
1334 strlen(cctype)+1);
1335 if (!WBC_ERROR_IS_OK(wbc_status)) {
1336 goto done;
1339 wbc_status = wbcLogonUser(&params, &info, &error, &policy);
1341 d_printf("plaintext kerberos password authentication for [%s] %s "
1342 "(requesting cctype: %s)\n",
1343 username, WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed",
1344 cctype);
1346 if (error) {
1347 d_fprintf(stderr,
1348 "error code was %s (0x%x)\nerror messsage was: %s\n",
1349 error->nt_string,
1350 error->nt_status,
1351 error->display_string);
1354 if (WBC_ERROR_IS_OK(wbc_status)) {
1355 if (flags & WBFLAG_PAM_INFO3_TEXT) {
1356 if (info && info->info && info->info->user_flags &
1357 NETLOGON_CACHED_ACCOUNT) {
1358 d_printf("user_flgs: "
1359 "NETLOGON_CACHED_ACCOUNT\n");
1363 if (info) {
1364 int i;
1365 for (i=0; i < info->num_blobs; i++) {
1366 if (strequal(info->blobs[i].name,
1367 "krb5ccname")) {
1368 d_printf("credentials were put "
1369 "in: %s\n",
1370 (const char *)
1371 info->blobs[i].blob.data);
1372 break;
1375 } else {
1376 d_printf("no credentials cached\n");
1379 done:
1381 wbcFreeMemory(params.blobs);
1383 return WBC_ERROR_IS_OK(wbc_status);
1386 /* Authenticate a user with a plaintext password */
1388 static bool wbinfo_auth(char *username)
1390 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1391 char *s = NULL;
1392 char *p = NULL;
1393 char *password = NULL;
1394 char *name = NULL;
1395 TALLOC_CTX *frame = talloc_tos();
1397 if ((s = talloc_strdup(frame, username)) == NULL) {
1398 return false;
1401 if ((p = strchr(s, '%')) != NULL) {
1402 *p = 0;
1403 p++;
1404 password = talloc_strdup(frame, p);
1405 } else {
1406 password = wbinfo_prompt_pass(frame, NULL, username);
1409 name = s;
1411 wbc_status = wbcAuthenticateUser(name, password);
1413 d_printf("plaintext password authentication %s\n",
1414 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1416 #if 0
1417 if (response.data.auth.nt_status)
1418 d_fprintf(stderr,
1419 "error code was %s (0x%x)\nerror messsage was: %s\n",
1420 response.data.auth.nt_status_string,
1421 response.data.auth.nt_status,
1422 response.data.auth.error_string);
1423 #endif
1425 return WBC_ERROR_IS_OK(wbc_status);
1428 /* Authenticate a user with a challenge/response */
1430 static bool wbinfo_auth_crap(char *username, bool use_ntlmv2, bool use_lanman)
1432 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1433 struct wbcAuthUserParams params;
1434 struct wbcAuthUserInfo *info = NULL;
1435 struct wbcAuthErrorInfo *err = NULL;
1436 DATA_BLOB lm = data_blob_null;
1437 DATA_BLOB nt = data_blob_null;
1438 fstring name_user;
1439 fstring name_domain;
1440 char *pass;
1441 char *p;
1442 TALLOC_CTX *frame = talloc_tos();
1444 p = strchr(username, '%');
1446 if (p) {
1447 *p = 0;
1448 pass = talloc_strdup(frame, p + 1);
1449 } else {
1450 pass = wbinfo_prompt_pass(frame, NULL, username);
1453 parse_wbinfo_domain_user(username, name_domain, name_user);
1455 params.account_name = name_user;
1456 params.domain_name = name_domain;
1457 params.workstation_name = NULL;
1459 params.flags = 0;
1460 params.parameter_control= WBC_MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT |
1461 WBC_MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT;
1463 params.level = WBC_AUTH_USER_LEVEL_RESPONSE;
1465 generate_random_buffer(params.password.response.challenge, 8);
1467 if (use_ntlmv2) {
1468 DATA_BLOB server_chal;
1469 DATA_BLOB names_blob;
1471 server_chal = data_blob(params.password.response.challenge, 8);
1473 /* Pretend this is a login to 'us', for blob purposes */
1474 names_blob = NTLMv2_generate_names_blob(NULL,
1475 get_winbind_netbios_name(),
1476 get_winbind_domain());
1478 if (!SMBNTLMv2encrypt(NULL, name_user, name_domain, pass,
1479 &server_chal,
1480 &names_blob,
1481 &lm, &nt, NULL, NULL)) {
1482 data_blob_free(&names_blob);
1483 data_blob_free(&server_chal);
1484 TALLOC_FREE(pass);
1485 return false;
1487 data_blob_free(&names_blob);
1488 data_blob_free(&server_chal);
1490 } else {
1491 if (use_lanman) {
1492 bool ok;
1493 lm = data_blob(NULL, 24);
1494 ok = SMBencrypt(pass,
1495 params.password.response.challenge,
1496 lm.data);
1497 if (!ok) {
1498 data_blob_free(&lm);
1501 nt = data_blob(NULL, 24);
1502 SMBNTencrypt(pass, params.password.response.challenge,
1503 nt.data);
1506 params.password.response.nt_length = nt.length;
1507 params.password.response.nt_data = nt.data;
1508 params.password.response.lm_length = lm.length;
1509 params.password.response.lm_data = lm.data;
1511 wbc_status = wbcAuthenticateUserEx(&params, &info, &err);
1513 /* Display response */
1515 d_printf("challenge/response password authentication %s\n",
1516 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1518 if (wbc_status == WBC_ERR_AUTH_ERROR) {
1519 d_fprintf(stderr,
1520 "error code was %s (0x%x)\nerror messsage was: %s\n",
1521 err->nt_string,
1522 err->nt_status,
1523 err->display_string);
1524 wbcFreeMemory(err);
1525 } else if (WBC_ERROR_IS_OK(wbc_status)) {
1526 wbcFreeMemory(info);
1529 data_blob_free(&nt);
1530 data_blob_free(&lm);
1532 return WBC_ERROR_IS_OK(wbc_status);
1535 /* Authenticate a user with a plaintext password */
1537 static bool wbinfo_pam_logon(char *username)
1539 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1540 struct wbcLogonUserParams params;
1541 struct wbcAuthErrorInfo *error;
1542 char *s = NULL;
1543 char *p = NULL;
1544 TALLOC_CTX *frame = talloc_tos();
1545 uint32_t flags;
1546 uint32_t uid;
1548 ZERO_STRUCT(params);
1550 if ((s = talloc_strdup(frame, username)) == NULL) {
1551 return false;
1554 if ((p = strchr(s, '%')) != NULL) {
1555 *p = 0;
1556 p++;
1557 params.password = talloc_strdup(frame, p);
1558 } else {
1559 params.password = wbinfo_prompt_pass(frame, NULL, username);
1561 params.username = s;
1563 flags = WBFLAG_PAM_CACHED_LOGIN;
1565 wbc_status = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
1566 "flags", 0,
1567 (uint8_t *)&flags, sizeof(flags));
1568 if (!WBC_ERROR_IS_OK(wbc_status)) {
1569 d_printf("wbcAddNamedBlob failed: %s\n",
1570 wbcErrorString(wbc_status));
1571 return false;
1574 uid = getuid();
1576 wbc_status = wbcAddNamedBlob(&params.num_blobs, &params.blobs,
1577 "user_uid", 0,
1578 (uint8_t *)&uid, sizeof(uid));
1579 if (!WBC_ERROR_IS_OK(wbc_status)) {
1580 d_printf("wbcAddNamedBlob failed: %s\n",
1581 wbcErrorString(wbc_status));
1582 return false;
1585 wbc_status = wbcLogonUser(&params, NULL, &error, NULL);
1587 wbcFreeMemory(params.blobs);
1589 d_printf("plaintext password authentication %s\n",
1590 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1592 if (!WBC_ERROR_IS_OK(wbc_status)) {
1593 d_fprintf(stderr,
1594 "error code was %s (0x%x)\nerror messsage was: %s\n",
1595 error->nt_string,
1596 (int)error->nt_status,
1597 error->display_string);
1598 wbcFreeMemory(error);
1599 return false;
1601 return true;
1604 /* Save creds with winbind */
1606 static bool wbinfo_ccache_save(char *username)
1608 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1609 char *s = NULL;
1610 char *p = NULL;
1611 char *password = NULL;
1612 char *name = NULL;
1613 TALLOC_CTX *frame = talloc_stackframe();
1615 s = talloc_strdup(frame, username);
1616 if (s == NULL) {
1617 return false;
1620 p = strchr(s, '%');
1621 if (p != NULL) {
1622 *p = 0;
1623 p++;
1624 password = talloc_strdup(frame, p);
1625 } else {
1626 password = wbinfo_prompt_pass(frame, NULL, username);
1629 name = s;
1631 wbc_status = wbcCredentialSave(name, password);
1633 d_printf("saving creds %s\n",
1634 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1636 TALLOC_FREE(frame);
1638 return WBC_ERROR_IS_OK(wbc_status);
1641 #ifdef WITH_FAKE_KASERVER
1642 /* Authenticate a user with a plaintext password and set a token */
1644 static bool wbinfo_klog(char *username)
1646 struct winbindd_request request;
1647 struct winbindd_response response;
1648 NSS_STATUS result;
1649 char *p;
1651 /* Send off request */
1653 ZERO_STRUCT(request);
1654 ZERO_STRUCT(response);
1656 p = strchr(username, '%');
1658 if (p) {
1659 *p = 0;
1660 fstrcpy(request.data.auth.user, username);
1661 fstrcpy(request.data.auth.pass, p + 1);
1662 *p = '%';
1663 } else {
1664 fstrcpy(request.data.auth.user, username);
1665 fstrcpy(request.data.auth.pass, getpass("Password: "));
1668 request.flags |= WBFLAG_PAM_AFS_TOKEN;
1670 result = winbindd_request_response(WINBINDD_PAM_AUTH, &request,
1671 &response);
1673 /* Display response */
1675 d_printf("plaintext password authentication %s\n",
1676 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
1678 if (response.data.auth.nt_status)
1679 d_fprintf(stderr,
1680 "error code was %s (0x%x)\nerror messsage was: %s\n",
1681 response.data.auth.nt_status_string,
1682 response.data.auth.nt_status,
1683 response.data.auth.error_string);
1685 if (result != NSS_STATUS_SUCCESS)
1686 return false;
1688 if (response.extra_data.data == NULL) {
1689 d_fprintf(stderr, "Did not get token data\n");
1690 return false;
1693 if (!afs_settoken_str((char *)response.extra_data.data)) {
1694 d_fprintf(stderr, "Could not set token\n");
1695 return false;
1698 d_printf("Successfully created AFS token\n");
1699 return true;
1701 #else
1702 static bool wbinfo_klog(char *username)
1704 d_fprintf(stderr, "No AFS support compiled in.\n");
1705 return false;
1707 #endif
1709 /* Print domain users */
1711 static bool print_domain_users(const char *domain)
1713 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1714 uint32_t i;
1715 uint32_t num_users = 0;
1716 const char **users = NULL;
1718 /* Send request to winbind daemon */
1720 /* '.' is the special sign for our own domain */
1721 if (domain && strcmp(domain, ".") == 0) {
1722 domain = get_winbind_domain();
1725 wbc_status = wbcListUsers(domain, &num_users, &users);
1726 if (!WBC_ERROR_IS_OK(wbc_status)) {
1727 return false;
1730 for (i=0; i < num_users; i++) {
1731 d_printf("%s\n", users[i]);
1734 wbcFreeMemory(users);
1736 return true;
1739 /* Print domain groups */
1741 static bool print_domain_groups(const char *domain)
1743 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
1744 uint32_t i;
1745 uint32_t num_groups = 0;
1746 const char **groups = NULL;
1748 /* Send request to winbind daemon */
1750 /* '.' is the special sign for our own domain */
1751 if (domain && strcmp(domain, ".") == 0) {
1752 domain = get_winbind_domain();
1755 wbc_status = wbcListGroups(domain, &num_groups, &groups);
1756 if (!WBC_ERROR_IS_OK(wbc_status)) {
1757 return false;
1760 for (i=0; i < num_groups; i++) {
1761 d_printf("%s\n", groups[i]);
1764 wbcFreeMemory(groups);
1766 return true;
1769 /* Set the authorised user for winbindd access in secrets.tdb */
1771 static bool wbinfo_set_auth_user(char *username)
1773 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1774 "See 'net help setauthuser' for details.\n");
1775 return false;
1778 static void wbinfo_get_auth_user(void)
1780 d_fprintf(stderr, "This functionality was moved to the 'net' utility.\n"
1781 "See 'net help getauthuser' for details.\n");
1784 static bool wbinfo_ping(void)
1786 wbcErr wbc_status;
1788 wbc_status = wbcPing();
1790 /* Display response */
1792 d_printf("Ping to winbindd %s\n",
1793 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1795 return WBC_ERROR_IS_OK(wbc_status);
1798 static bool wbinfo_change_user_password(const char *username)
1800 wbcErr wbc_status;
1801 char *old_password = NULL;
1802 char *new_password = NULL;
1803 TALLOC_CTX *frame = talloc_tos();
1805 old_password = wbinfo_prompt_pass(frame, "old", username);
1806 new_password = wbinfo_prompt_pass(frame, "new", username);
1808 wbc_status = wbcChangeUserPassword(username, old_password,new_password);
1810 /* Display response */
1812 d_printf("Password change for user %s %s\n", username,
1813 WBC_ERROR_IS_OK(wbc_status) ? "succeeded" : "failed");
1815 return WBC_ERROR_IS_OK(wbc_status);
1818 /* Main program */
1820 enum {
1821 OPT_SET_AUTH_USER = 1000,
1822 OPT_GET_AUTH_USER,
1823 OPT_DOMAIN_NAME,
1824 OPT_SEQUENCE,
1825 OPT_GETDCNAME,
1826 OPT_DSGETDCNAME,
1827 OPT_USERDOMGROUPS,
1828 OPT_SIDALIASES,
1829 OPT_USERSIDS,
1830 OPT_ALLOCATE_UID,
1831 OPT_ALLOCATE_GID,
1832 OPT_SET_UID_MAPPING,
1833 OPT_SET_GID_MAPPING,
1834 OPT_REMOVE_UID_MAPPING,
1835 OPT_REMOVE_GID_MAPPING,
1836 OPT_SEPARATOR,
1837 OPT_LIST_ALL_DOMAINS,
1838 OPT_LIST_OWN_DOMAIN,
1839 OPT_UID_INFO,
1840 OPT_USER_SIDINFO,
1841 OPT_GROUP_INFO,
1842 OPT_GID_INFO,
1843 OPT_VERBOSE,
1844 OPT_ONLINESTATUS,
1845 OPT_CHANGE_USER_PASSWORD,
1846 OPT_PING_DC,
1847 OPT_CCACHE_SAVE,
1848 OPT_SID_TO_FULLNAME,
1849 OPT_NTLMV2,
1850 OPT_PAM_LOGON,
1851 OPT_LOGOFF,
1852 OPT_LOGOFF_USER,
1853 OPT_LOGOFF_UID,
1854 OPT_LANMAN
1857 int main(int argc, char **argv, char **envp)
1859 int opt;
1860 TALLOC_CTX *frame = talloc_stackframe();
1861 poptContext pc;
1862 static char *string_arg;
1863 char *string_subarg = NULL;
1864 static char *opt_domain_name;
1865 static int int_arg;
1866 int int_subarg = -1;
1867 int result = 1;
1868 bool verbose = false;
1869 bool use_ntlmv2 = false;
1870 bool use_lanman = false;
1871 char *logoff_user = getenv("USER");
1872 int logoff_uid = geteuid();
1874 struct poptOption long_options[] = {
1875 POPT_AUTOHELP
1877 /* longName, shortName, argInfo, argPtr, value, descrip,
1878 argDesc */
1880 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users", "domain"},
1881 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups", "domain" },
1882 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1883 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
1884 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
1885 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
1886 { "sid-to-fullname", 0, POPT_ARG_STRING, &string_arg,
1887 OPT_SID_TO_FULLNAME, "Converts sid to fullname", "SID" },
1888 { "lookup-rids", 'R', POPT_ARG_STRING, &string_arg, 'R', "Converts RIDs to names", "RIDs" },
1889 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
1890 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
1891 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
1892 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
1893 { "allocate-uid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_UID,
1894 "Get a new UID out of idmap" },
1895 { "allocate-gid", 0, POPT_ARG_NONE, 0, OPT_ALLOCATE_GID,
1896 "Get a new GID out of idmap" },
1897 { "set-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_UID_MAPPING, "Create or modify uid to sid mapping in idmap", "UID,SID" },
1898 { "set-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_SET_GID_MAPPING, "Create or modify gid to sid mapping in idmap", "GID,SID" },
1899 { "remove-uid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_UID_MAPPING, "Remove uid to sid mapping in idmap", "UID,SID" },
1900 { "remove-gid-mapping", 0, POPT_ARG_STRING, &string_arg, OPT_REMOVE_GID_MAPPING, "Remove gid to sid mapping in idmap", "GID,SID" },
1901 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
1902 { "change-secret", 'c', POPT_ARG_NONE, 0, 'c', "Change shared secret" },
1903 { "ping-dc", 0, POPT_ARG_NONE, 0, OPT_PING_DC,
1904 "Check the NETLOGON connection" },
1905 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
1906 { "all-domains", 0, POPT_ARG_NONE, 0, OPT_LIST_ALL_DOMAINS, "List all domains (trusted and own domain)" },
1907 { "own-domain", 0, POPT_ARG_NONE, 0, OPT_LIST_OWN_DOMAIN, "List own domain" },
1908 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
1909 { "online-status", 0, POPT_ARG_NONE, 0, OPT_ONLINESTATUS, "Show whether domains are marked as online or offline"},
1910 { "domain-info", 'D', POPT_ARG_STRING, &string_arg, 'D', "Show most of the info we have about the domain" },
1911 { "user-info", 'i', POPT_ARG_STRING, &string_arg, 'i', "Get user info", "USER" },
1912 { "uid-info", 0, POPT_ARG_INT, &int_arg, OPT_UID_INFO, "Get user info from uid", "UID" },
1913 { "group-info", 0, POPT_ARG_STRING, &string_arg, OPT_GROUP_INFO, "Get group info", "GROUP" },
1914 { "user-sidinfo", 0, POPT_ARG_STRING, &string_arg, OPT_USER_SIDINFO, "Get user info from sid", "SID" },
1915 { "gid-info", 0, POPT_ARG_INT, &int_arg, OPT_GID_INFO, "Get group info from gid", "GID" },
1916 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
1917 { "user-domgroups", 0, POPT_ARG_STRING, &string_arg,
1918 OPT_USERDOMGROUPS, "Get user domain groups", "SID" },
1919 { "sid-aliases", 0, POPT_ARG_STRING, &string_arg, OPT_SIDALIASES, "Get sid aliases", "SID" },
1920 { "user-sids", 0, POPT_ARG_STRING, &string_arg, OPT_USERSIDS, "Get user group sids for user SID", "SID" },
1921 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
1922 { "pam-logon", 0, POPT_ARG_STRING, string_arg, OPT_PAM_LOGON,
1923 "do a pam logon equivalent", "user%password" },
1924 { "logoff", 0, POPT_ARG_NONE, NULL, OPT_LOGOFF,
1925 "log off user", "uid" },
1926 { "logoff-user", 0, POPT_ARG_STRING, &logoff_user,
1927 OPT_LOGOFF_USER, "username to log off" },
1928 { "logoff-uid", 0, POPT_ARG_INT, &logoff_uid,
1929 OPT_LOGOFF_UID, "uid to log off" },
1930 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
1931 { "ccache-save", 0, POPT_ARG_STRING, &string_arg,
1932 OPT_CCACHE_SAVE, "Store user and password for ccache "
1933 "operation", "user%password" },
1934 { "getdcname", 0, POPT_ARG_STRING, &string_arg, OPT_GETDCNAME,
1935 "Get a DC name for a foreign domain", "domainname" },
1936 { "dsgetdcname", 0, POPT_ARG_STRING, &string_arg, OPT_DSGETDCNAME, "Find a DC for a domain", "domainname" },
1937 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
1938 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
1939 { "domain", 0, POPT_ARG_STRING, &opt_domain_name, OPT_DOMAIN_NAME, "Define to the domain to restrict operation", "domain" },
1940 #ifdef WITH_FAKE_KASERVER
1941 { "klog", 'k', POPT_ARG_STRING, &string_arg, 'k', "set an AFS token from winbind", "user%password" },
1942 #endif
1943 #ifdef HAVE_KRB5
1944 { "krb5auth", 'K', POPT_ARG_STRING, &string_arg, 'K', "authenticate user using Kerberos", "user%password" },
1945 /* destroys wbinfo --help output */
1946 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1947 #endif
1948 { "separator", 0, POPT_ARG_NONE, 0, OPT_SEPARATOR, "Get the active winbind separator", NULL },
1949 { "verbose", 0, POPT_ARG_NONE, 0, OPT_VERBOSE, "Print additional information per command", NULL },
1950 { "change-user-password", 0, POPT_ARG_STRING, &string_arg, OPT_CHANGE_USER_PASSWORD, "Change the password for a user", NULL },
1951 { "ntlmv2", 0, POPT_ARG_NONE, 0, OPT_NTLMV2, "Use NTLMv2 cryptography for user authentication", NULL},
1952 { "lanman", 0, POPT_ARG_NONE, 0, OPT_LANMAN, "Use lanman cryptography for user authentication", NULL},
1953 POPT_COMMON_VERSION
1954 POPT_TABLEEND
1957 /* Samba client initialisation */
1958 load_case_tables();
1961 /* Parse options */
1963 pc = poptGetContext("wbinfo", argc, (const char **)argv,
1964 long_options, 0);
1966 /* Parse command line options */
1968 if (argc == 1) {
1969 poptPrintHelp(pc, stderr, 0);
1970 return 1;
1973 while((opt = poptGetNextOpt(pc)) != -1) {
1974 /* get the generic configuration parameters like --domain */
1975 switch (opt) {
1976 case OPT_VERBOSE:
1977 verbose = true;
1978 break;
1979 case OPT_NTLMV2:
1980 use_ntlmv2 = true;
1981 break;
1982 case OPT_LANMAN:
1983 use_lanman = true;
1984 break;
1988 poptFreeContext(pc);
1990 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
1991 POPT_CONTEXT_KEEP_FIRST);
1993 while((opt = poptGetNextOpt(pc)) != -1) {
1994 switch (opt) {
1995 case 'u':
1996 if (!print_domain_users(opt_domain_name)) {
1997 d_fprintf(stderr,
1998 "Error looking up domain users\n");
1999 goto done;
2001 break;
2002 case 'g':
2003 if (!print_domain_groups(opt_domain_name)) {
2004 d_fprintf(stderr,
2005 "Error looking up domain groups\n");
2006 goto done;
2008 break;
2009 case 's':
2010 if (!wbinfo_lookupsid(string_arg)) {
2011 d_fprintf(stderr,
2012 "Could not lookup sid %s\n",
2013 string_arg);
2014 goto done;
2016 break;
2017 case OPT_SID_TO_FULLNAME:
2018 if (!wbinfo_lookupsid_fullname(string_arg)) {
2019 d_fprintf(stderr, "Could not lookup sid %s\n",
2020 string_arg);
2021 goto done;
2023 break;
2024 case 'R':
2025 if (!wbinfo_lookuprids(opt_domain_name, string_arg)) {
2026 d_fprintf(stderr, "Could not lookup RIDs %s\n",
2027 string_arg);
2028 goto done;
2030 break;
2031 case 'n':
2032 if (!wbinfo_lookupname(string_arg)) {
2033 d_fprintf(stderr, "Could not lookup name %s\n",
2034 string_arg);
2035 goto done;
2037 break;
2038 case 'N':
2039 if (!wbinfo_wins_byname(string_arg)) {
2040 d_fprintf(stderr,
2041 "Could not lookup WINS by name %s\n",
2042 string_arg);
2043 goto done;
2045 break;
2046 case 'I':
2047 if (!wbinfo_wins_byip(string_arg)) {
2048 d_fprintf(stderr,
2049 "Could not lookup WINS by IP %s\n",
2050 string_arg);
2051 goto done;
2053 break;
2054 case 'U':
2055 if (!wbinfo_uid_to_sid(int_arg)) {
2056 d_fprintf(stderr,
2057 "Could not convert uid %d to sid\n",
2058 int_arg);
2059 goto done;
2061 break;
2062 case 'G':
2063 if (!wbinfo_gid_to_sid(int_arg)) {
2064 d_fprintf(stderr,
2065 "Could not convert gid %d to sid\n",
2066 int_arg);
2067 goto done;
2069 break;
2070 case 'S':
2071 if (!wbinfo_sid_to_uid(string_arg)) {
2072 d_fprintf(stderr,
2073 "Could not convert sid %s to uid\n",
2074 string_arg);
2075 goto done;
2077 break;
2078 case 'Y':
2079 if (!wbinfo_sid_to_gid(string_arg)) {
2080 d_fprintf(stderr,
2081 "Could not convert sid %s to gid\n",
2082 string_arg);
2083 goto done;
2085 break;
2086 case OPT_ALLOCATE_UID:
2087 if (!wbinfo_allocate_uid()) {
2088 d_fprintf(stderr, "Could not allocate a uid\n");
2089 goto done;
2091 break;
2092 case OPT_ALLOCATE_GID:
2093 if (!wbinfo_allocate_gid()) {
2094 d_fprintf(stderr, "Could not allocate a gid\n");
2095 goto done;
2097 break;
2098 case OPT_SET_UID_MAPPING:
2099 if (!parse_mapping_arg(string_arg, &int_subarg,
2100 &string_subarg) ||
2101 !wbinfo_set_uid_mapping(int_subarg, string_subarg))
2103 d_fprintf(stderr, "Could not create or modify "
2104 "uid to sid mapping\n");
2105 goto done;
2107 break;
2108 case OPT_SET_GID_MAPPING:
2109 if (!parse_mapping_arg(string_arg, &int_subarg,
2110 &string_subarg) ||
2111 !wbinfo_set_gid_mapping(int_subarg, string_subarg))
2113 d_fprintf(stderr, "Could not create or modify "
2114 "gid to sid mapping\n");
2115 goto done;
2117 break;
2118 case OPT_REMOVE_UID_MAPPING:
2119 if (!parse_mapping_arg(string_arg, &int_subarg,
2120 &string_subarg) ||
2121 !wbinfo_remove_uid_mapping(int_subarg,
2122 string_subarg))
2124 d_fprintf(stderr, "Could not remove uid to sid "
2125 "mapping\n");
2126 goto done;
2128 break;
2129 case OPT_REMOVE_GID_MAPPING:
2130 if (!parse_mapping_arg(string_arg, &int_subarg,
2131 &string_subarg) ||
2132 !wbinfo_remove_gid_mapping(int_subarg,
2133 string_subarg))
2135 d_fprintf(stderr, "Could not remove gid to sid "
2136 "mapping\n");
2137 goto done;
2139 break;
2140 case 't':
2141 if (!wbinfo_check_secret(opt_domain_name)) {
2142 d_fprintf(stderr, "Could not check secret\n");
2143 goto done;
2145 break;
2146 case 'c':
2147 if (!wbinfo_change_secret(opt_domain_name)) {
2148 d_fprintf(stderr, "Could not change secret\n");
2149 goto done;
2151 break;
2152 case OPT_PING_DC:
2153 if (!wbinfo_ping_dc()) {
2154 d_fprintf(stderr, "Could not ping our DC\n");
2155 goto done;
2157 break;
2158 case 'm':
2159 if (!wbinfo_list_domains(false, verbose)) {
2160 d_fprintf(stderr,
2161 "Could not list trusted domains\n");
2162 goto done;
2164 break;
2165 case OPT_SEQUENCE:
2166 if (!wbinfo_show_sequence(opt_domain_name)) {
2167 d_fprintf(stderr,
2168 "Could not show sequence numbers\n");
2169 goto done;
2171 break;
2172 case OPT_ONLINESTATUS:
2173 if (!wbinfo_show_onlinestatus(opt_domain_name)) {
2174 d_fprintf(stderr,
2175 "Could not show online-status\n");
2176 goto done;
2178 break;
2179 case 'D':
2180 if (!wbinfo_domain_info(string_arg)) {
2181 d_fprintf(stderr,
2182 "Could not get domain info\n");
2183 goto done;
2185 break;
2186 case 'i':
2187 if (!wbinfo_get_userinfo(string_arg)) {
2188 d_fprintf(stderr,
2189 "Could not get info for user %s\n",
2190 string_arg);
2191 goto done;
2193 break;
2194 case OPT_USER_SIDINFO:
2195 if ( !wbinfo_get_user_sidinfo(string_arg)) {
2196 d_fprintf(stderr,
2197 "Could not get info for user "
2198 "sid %s\n", string_arg);
2199 goto done;
2201 break;
2202 case OPT_UID_INFO:
2203 if ( !wbinfo_get_uidinfo(int_arg)) {
2204 d_fprintf(stderr, "Could not get info for uid "
2205 "%d\n", int_arg);
2206 goto done;
2208 break;
2209 case OPT_GROUP_INFO:
2210 if ( !wbinfo_get_groupinfo(string_arg)) {
2211 d_fprintf(stderr, "Could not get info for "
2212 "group %s\n", string_arg);
2213 goto done;
2215 break;
2216 case OPT_GID_INFO:
2217 if ( !wbinfo_get_gidinfo(int_arg)) {
2218 d_fprintf(stderr, "Could not get info for gid "
2219 "%d\n", int_arg);
2220 goto done;
2222 break;
2223 case 'r':
2224 if (!wbinfo_get_usergroups(string_arg)) {
2225 d_fprintf(stderr,
2226 "Could not get groups for user %s\n",
2227 string_arg);
2228 goto done;
2230 break;
2231 case OPT_USERSIDS:
2232 if (!wbinfo_get_usersids(string_arg)) {
2233 d_fprintf(stderr, "Could not get group SIDs "
2234 "for user SID %s\n",
2235 string_arg);
2236 goto done;
2238 break;
2239 case OPT_USERDOMGROUPS:
2240 if (!wbinfo_get_userdomgroups(string_arg)) {
2241 d_fprintf(stderr, "Could not get user's domain "
2242 "groups for user SID %s\n",
2243 string_arg);
2244 goto done;
2246 break;
2247 case OPT_SIDALIASES:
2248 if (!wbinfo_get_sidaliases(opt_domain_name,
2249 string_arg)) {
2250 d_fprintf(stderr, "Could not get sid aliases "
2251 "for user SID %s\n", string_arg);
2252 goto done;
2254 break;
2255 case 'a': {
2256 bool got_error = false;
2258 if (!wbinfo_auth(string_arg)) {
2259 d_fprintf(stderr,
2260 "Could not authenticate user "
2261 "%s with plaintext "
2262 "password\n", string_arg);
2263 got_error = true;
2266 if (!wbinfo_auth_crap(string_arg, use_ntlmv2,
2267 use_lanman)) {
2268 d_fprintf(stderr,
2269 "Could not authenticate user "
2270 "%s with challenge/response\n",
2271 string_arg);
2272 got_error = true;
2275 if (got_error)
2276 goto done;
2277 break;
2279 case OPT_PAM_LOGON:
2280 if (!wbinfo_pam_logon(string_arg)) {
2281 d_fprintf(stderr, "pam_logon failed for %s\n",
2282 string_arg);
2283 goto done;
2285 case OPT_LOGOFF:
2287 wbcErr wbc_status;
2289 wbc_status = wbcLogoffUser(logoff_user, logoff_uid,
2290 "");
2291 d_printf("Logoff %s (%d): %s\n", logoff_user,
2292 logoff_uid, wbcErrorString(wbc_status));
2293 break;
2295 case 'K': {
2296 uint32_t flags = WBFLAG_PAM_KRB5 |
2297 WBFLAG_PAM_CACHED_LOGIN |
2298 WBFLAG_PAM_FALLBACK_AFTER_KRB5 |
2299 WBFLAG_PAM_INFO3_TEXT |
2300 WBFLAG_PAM_CONTACT_TRUSTDOM;
2302 if (!wbinfo_auth_krb5(string_arg, "FILE",
2303 flags)) {
2304 d_fprintf(stderr,
2305 "Could not authenticate user "
2306 "[%s] with Kerberos "
2307 "(ccache: %s)\n", string_arg,
2308 "FILE");
2309 goto done;
2311 break;
2313 case 'k':
2314 if (!wbinfo_klog(string_arg)) {
2315 d_fprintf(stderr, "Could not klog user\n");
2316 goto done;
2318 break;
2319 case 'p':
2320 if (!wbinfo_ping()) {
2321 d_fprintf(stderr, "could not ping winbindd!\n");
2322 goto done;
2324 break;
2325 case OPT_SET_AUTH_USER:
2326 if (!wbinfo_set_auth_user(string_arg)) {
2327 goto done;
2329 break;
2330 case OPT_GET_AUTH_USER:
2331 wbinfo_get_auth_user();
2332 goto done;
2333 break;
2334 case OPT_CCACHE_SAVE:
2335 if (!wbinfo_ccache_save(string_arg)) {
2336 goto done;
2338 break;
2339 case OPT_GETDCNAME:
2340 if (!wbinfo_getdcname(string_arg)) {
2341 goto done;
2343 break;
2344 case OPT_DSGETDCNAME:
2345 if (!wbinfo_dsgetdcname(string_arg, 0)) {
2346 goto done;
2348 break;
2349 case OPT_SEPARATOR: {
2350 const char sep = winbind_separator();
2351 if ( !sep ) {
2352 goto done;
2354 d_printf("%c\n", sep);
2355 break;
2357 case OPT_LIST_ALL_DOMAINS:
2358 if (!wbinfo_list_domains(true, verbose)) {
2359 goto done;
2361 break;
2362 case OPT_LIST_OWN_DOMAIN:
2363 if (!wbinfo_list_own_domain()) {
2364 goto done;
2366 break;
2367 case OPT_CHANGE_USER_PASSWORD:
2368 if (!wbinfo_change_user_password(string_arg)) {
2369 d_fprintf(stderr,
2370 "Could not change user password "
2371 "for user %s\n", string_arg);
2372 goto done;
2374 break;
2376 /* generic configuration options */
2377 case OPT_DOMAIN_NAME:
2378 case OPT_VERBOSE:
2379 case OPT_NTLMV2:
2380 case OPT_LANMAN:
2381 case OPT_LOGOFF_USER:
2382 case OPT_LOGOFF_UID:
2383 break;
2384 default:
2385 d_fprintf(stderr, "Invalid option\n");
2386 poptPrintHelp(pc, stderr, 0);
2387 goto done;
2391 result = 0;
2393 /* Exit code */
2395 done:
2396 talloc_free(frame);
2398 poptFreeContext(pc);
2399 return result;