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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #define DBGC_CLASS DBGC_WINBIND
31 extern int winbindd_fd
;
33 static char winbind_separator_int(BOOL strict
)
35 struct winbindd_response response
;
42 ZERO_STRUCT(response
);
44 /* Send off request */
46 if (winbindd_request_response(WINBINDD_INFO
, NULL
, &response
) !=
48 d_fprintf(stderr
, "could not obtain winbind separator!\n");
52 /* HACK: (this module should not call lp_ funtions) */
53 return *lp_winbind_separator();
56 sep
= response
.data
.info
.winbind_separator
;
60 d_fprintf(stderr
, "winbind separator was NULL!\n");
64 /* HACK: (this module should not call lp_ funtions) */
65 sep
= *lp_winbind_separator();
71 static char winbind_separator(void)
73 return winbind_separator_int(False
);
76 static const char *get_winbind_domain(void)
78 struct winbindd_response response
;
79 static fstring winbind_domain
;
81 ZERO_STRUCT(response
);
83 /* Send off request */
85 if (winbindd_request_response(WINBINDD_DOMAIN_NAME
, NULL
, &response
) !=
87 d_fprintf(stderr
, "could not obtain winbind domain name!\n");
89 /* HACK: (this module should not call lp_ funtions) */
90 return lp_workgroup();
93 fstrcpy(winbind_domain
, response
.data
.domain_name
);
95 return winbind_domain
;
99 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
100 form DOMAIN/user into a domain and a user */
102 static BOOL
parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
106 char *p
= strchr(domuser
,winbind_separator());
109 fstrcpy(user
, domuser
);
110 fstrcpy(domain
, get_winbind_domain());
115 fstrcpy(domain
, domuser
);
116 domain
[PTR_DIFF(p
, domuser
)] = 0;
122 /* List groups a user is a member of */
124 static BOOL
wbinfo_get_usergroups(char *user
)
126 struct winbindd_request request
;
127 struct winbindd_response response
;
131 ZERO_STRUCT(request
);
132 ZERO_STRUCT(response
);
136 fstrcpy(request
.data
.username
, user
);
138 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
140 if (result
!= NSS_STATUS_SUCCESS
)
143 for (i
= 0; i
< response
.data
.num_entries
; i
++)
144 d_printf("%d\n", (int)((gid_t
*)response
.extra_data
.data
)[i
]);
146 SAFE_FREE(response
.extra_data
.data
);
152 /* List group SIDs a user SID is a member of */
153 static BOOL
wbinfo_get_usersids(char *user_sid
)
155 struct winbindd_request request
;
156 struct winbindd_response response
;
161 ZERO_STRUCT(request
);
162 ZERO_STRUCT(response
);
165 fstrcpy(request
.data
.sid
, user_sid
);
167 result
= winbindd_request_response(WINBINDD_GETUSERSIDS
, &request
, &response
);
169 if (result
!= NSS_STATUS_SUCCESS
)
172 s
= response
.extra_data
.data
;
173 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
178 SAFE_FREE(response
.extra_data
.data
);
183 static BOOL
wbinfo_get_userdomgroups(const char *user_sid
)
185 struct winbindd_request request
;
186 struct winbindd_response response
;
189 ZERO_STRUCT(request
);
190 ZERO_STRUCT(response
);
193 fstrcpy(request
.data
.sid
, user_sid
);
195 result
= winbindd_request_response(WINBINDD_GETUSERDOMGROUPS
, &request
,
198 if (result
!= NSS_STATUS_SUCCESS
)
201 if (response
.data
.num_entries
!= 0)
202 printf("%s", (char *)response
.extra_data
.data
);
204 SAFE_FREE(response
.extra_data
.data
);
209 /* Convert NetBIOS name to IP */
211 static BOOL
wbinfo_wins_byname(char *name
)
213 struct winbindd_request request
;
214 struct winbindd_response response
;
216 ZERO_STRUCT(request
);
217 ZERO_STRUCT(response
);
221 fstrcpy(request
.data
.winsreq
, name
);
223 if (winbindd_request_response(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
224 NSS_STATUS_SUCCESS
) {
228 /* Display response */
230 d_printf("%s\n", response
.data
.winsresp
);
235 /* Convert IP to NetBIOS name */
237 static BOOL
wbinfo_wins_byip(char *ip
)
239 struct winbindd_request request
;
240 struct winbindd_response response
;
242 ZERO_STRUCT(request
);
243 ZERO_STRUCT(response
);
247 fstrcpy(request
.data
.winsreq
, ip
);
249 if (winbindd_request_response(WINBINDD_WINS_BYIP
, &request
, &response
) !=
250 NSS_STATUS_SUCCESS
) {
254 /* Display response */
256 d_printf("%s\n", response
.data
.winsresp
);
261 /* List trusted domains */
263 static BOOL
wbinfo_list_domains(BOOL list_all_domains
)
265 struct winbindd_request request
;
266 struct winbindd_response response
;
268 ZERO_STRUCT(request
);
269 ZERO_STRUCT(response
);
273 request
.data
.list_all_domains
= list_all_domains
;
275 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM
, &request
, &response
) !=
279 /* Display response */
281 if (response
.extra_data
.data
) {
282 const char *extra_data
= (char *)response
.extra_data
.data
;
286 while(next_token(&extra_data
, name
, "\n", sizeof(fstring
))) {
287 p
= strchr(name
, '\\');
289 d_fprintf(stderr
, "Got invalid response: %s\n",
294 d_printf("%s\n", name
);
297 SAFE_FREE(response
.extra_data
.data
);
304 /* show sequence numbers */
305 static BOOL
wbinfo_show_sequence(const char *domain
)
307 struct winbindd_request request
;
308 struct winbindd_response response
;
310 ZERO_STRUCT(response
);
311 ZERO_STRUCT(request
);
314 fstrcpy( request
.domain_name
, domain
);
318 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
322 /* Display response */
324 if (response
.extra_data
.data
) {
325 char *extra_data
= (char *)response
.extra_data
.data
;
326 d_printf("%s", extra_data
);
327 SAFE_FREE(response
.extra_data
.data
);
333 /* Show domain info */
335 static BOOL
wbinfo_domain_info(const char *domain_name
)
337 struct winbindd_request request
;
338 struct winbindd_response response
;
340 ZERO_STRUCT(request
);
341 ZERO_STRUCT(response
);
343 fstrcpy(request
.domain_name
, domain_name
);
347 if (winbindd_request_response(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
351 /* Display response */
353 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
354 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
356 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
358 d_printf("Active Directory : %s\n",
359 response
.data
.domain_info
.active_directory
? "Yes" : "No");
360 d_printf("Native : %s\n",
361 response
.data
.domain_info
.native_mode
? "Yes" : "No");
363 d_printf("Primary : %s\n",
364 response
.data
.domain_info
.primary
? "Yes" : "No");
366 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
371 /* Get a foreign DC's name */
372 static BOOL
wbinfo_getdcname(const char *domain_name
)
374 struct winbindd_request request
;
375 struct winbindd_response response
;
377 ZERO_STRUCT(request
);
378 ZERO_STRUCT(response
);
380 fstrcpy(request
.domain_name
, domain_name
);
384 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
, &response
) !=
385 NSS_STATUS_SUCCESS
) {
386 d_fprintf(stderr
, "Could not get dc name for %s\n", domain_name
);
390 /* Display response */
392 d_printf("%s\n", response
.data
.dc_name
);
397 /* Check trust account password */
399 static BOOL
wbinfo_check_secret(void)
401 struct winbindd_response response
;
404 ZERO_STRUCT(response
);
406 result
= winbindd_request_response(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
408 d_printf("checking the trust secret via RPC calls %s\n",
409 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
411 if (result
!= NSS_STATUS_SUCCESS
)
412 d_fprintf(stderr
, "error code was %s (0x%x)\n",
413 response
.data
.auth
.nt_status_string
,
414 response
.data
.auth
.nt_status
);
416 return result
== NSS_STATUS_SUCCESS
;
419 /* Convert uid to sid */
421 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
423 struct winbindd_request request
;
424 struct winbindd_response response
;
426 ZERO_STRUCT(request
);
427 ZERO_STRUCT(response
);
431 request
.data
.uid
= uid
;
433 if (winbindd_request_response(WINBINDD_UID_TO_SID
, &request
, &response
) !=
437 /* Display response */
439 d_printf("%s\n", response
.data
.sid
.sid
);
444 /* Convert gid to sid */
446 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
448 struct winbindd_request request
;
449 struct winbindd_response response
;
451 ZERO_STRUCT(request
);
452 ZERO_STRUCT(response
);
456 request
.data
.gid
= gid
;
458 if (winbindd_request_response(WINBINDD_GID_TO_SID
, &request
, &response
) !=
462 /* Display response */
464 d_printf("%s\n", response
.data
.sid
.sid
);
469 /* Convert sid to uid */
471 static BOOL
wbinfo_sid_to_uid(char *sid
)
473 struct winbindd_request request
;
474 struct winbindd_response response
;
476 ZERO_STRUCT(request
);
477 ZERO_STRUCT(response
);
481 fstrcpy(request
.data
.sid
, sid
);
483 if (winbindd_request_response(WINBINDD_SID_TO_UID
, &request
, &response
) !=
487 /* Display response */
489 d_printf("%d\n", (int)response
.data
.uid
);
494 static BOOL
wbinfo_sid_to_gid(char *sid
)
496 struct winbindd_request request
;
497 struct winbindd_response response
;
499 ZERO_STRUCT(request
);
500 ZERO_STRUCT(response
);
504 fstrcpy(request
.data
.sid
, sid
);
506 if (winbindd_request_response(WINBINDD_SID_TO_GID
, &request
, &response
) !=
510 /* Display response */
512 d_printf("%d\n", (int)response
.data
.gid
);
517 static BOOL
wbinfo_allocate_uid(void)
521 if (!winbind_allocate_uid(&uid
))
524 d_printf("New uid: %d\n", uid
);
529 static BOOL
wbinfo_allocate_gid(void)
533 if (!winbind_allocate_gid(&gid
))
536 d_printf("New gid: %d\n", gid
);
541 /* Convert sid to string */
543 static BOOL
wbinfo_lookupsid(char *sid
)
545 struct winbindd_request request
;
546 struct winbindd_response response
;
548 ZERO_STRUCT(request
);
549 ZERO_STRUCT(response
);
551 /* Send off request */
553 fstrcpy(request
.data
.sid
, sid
);
555 if (winbindd_request_response(WINBINDD_LOOKUPSID
, &request
, &response
) !=
559 /* Display response */
561 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
562 winbind_separator(), response
.data
.name
.name
,
563 response
.data
.name
.type
);
568 /* Convert string to sid */
570 static BOOL
wbinfo_lookupname(char *name
)
572 struct winbindd_request request
;
573 struct winbindd_response response
;
575 /* Send off request */
577 ZERO_STRUCT(request
);
578 ZERO_STRUCT(response
);
580 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
581 request
.data
.name
.name
);
583 if (winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
587 /* Display response */
589 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
594 /* Authenticate a user with a plaintext password */
596 static BOOL
wbinfo_auth_krb5(char *username
, const char *cctype
, uint32 flags
)
598 struct winbindd_request request
;
599 struct winbindd_response response
;
603 /* Send off request */
605 ZERO_STRUCT(request
);
606 ZERO_STRUCT(response
);
608 p
= strchr(username
, '%');
612 fstrcpy(request
.data
.auth
.user
, username
);
613 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
616 fstrcpy(request
.data
.auth
.user
, username
);
618 request
.flags
= flags
;
620 fstrcpy(request
.data
.auth
.krb5_cc_type
, cctype
);
622 request
.data
.auth
.uid
= geteuid();
624 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
626 /* Display response */
628 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
629 username
, (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", cctype
);
631 if (response
.data
.auth
.nt_status
)
632 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
633 response
.data
.auth
.nt_status_string
,
634 response
.data
.auth
.nt_status
,
635 response
.data
.auth
.error_string
);
637 if (result
== NSS_STATUS_SUCCESS
) {
639 if (request
.flags
& WBFLAG_PAM_INFO3_TEXT
) {
640 if (response
.data
.auth
.info3
.user_flgs
& LOGON_CACHED_ACCOUNT
) {
641 d_printf("user_flgs: LOGON_CACHED_ACCOUNT\n");
645 if (response
.data
.auth
.krb5ccname
[0] != '\0') {
646 d_printf("credentials were put in: %s\n", response
.data
.auth
.krb5ccname
);
648 d_printf("no credentials cached\n");
652 return result
== NSS_STATUS_SUCCESS
;
655 /* Authenticate a user with a plaintext password */
657 static BOOL
wbinfo_auth(char *username
)
659 struct winbindd_request request
;
660 struct winbindd_response response
;
664 /* Send off request */
666 ZERO_STRUCT(request
);
667 ZERO_STRUCT(response
);
669 p
= strchr(username
, '%');
673 fstrcpy(request
.data
.auth
.user
, username
);
674 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
677 fstrcpy(request
.data
.auth
.user
, username
);
679 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
681 /* Display response */
683 d_printf("plaintext password authentication %s\n",
684 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
686 if (response
.data
.auth
.nt_status
)
687 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
688 response
.data
.auth
.nt_status_string
,
689 response
.data
.auth
.nt_status
,
690 response
.data
.auth
.error_string
);
692 return result
== NSS_STATUS_SUCCESS
;
695 /* Authenticate a user with a challenge/response */
697 static BOOL
wbinfo_auth_crap(char *username
)
699 struct winbindd_request request
;
700 struct winbindd_response response
;
707 /* Send off request */
709 ZERO_STRUCT(request
);
710 ZERO_STRUCT(response
);
712 p
= strchr(username
, '%');
716 fstrcpy(pass
, p
+ 1);
719 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
721 request
.data
.auth_crap
.logon_parameters
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
| MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
723 fstrcpy(request
.data
.auth_crap
.user
, name_user
);
725 fstrcpy(request
.data
.auth_crap
.domain
,
728 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
730 if (lp_client_ntlmv2_auth()) {
731 DATA_BLOB server_chal
;
732 DATA_BLOB names_blob
;
734 DATA_BLOB lm_response
;
735 DATA_BLOB nt_response
;
737 server_chal
= data_blob(request
.data
.auth_crap
.chal
, 8);
739 /* Pretend this is a login to 'us', for blob purposes */
740 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
742 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
744 &lm_response
, &nt_response
, NULL
)) {
745 data_blob_free(&names_blob
);
746 data_blob_free(&server_chal
);
749 data_blob_free(&names_blob
);
750 data_blob_free(&server_chal
);
752 memcpy(request
.data
.auth_crap
.nt_resp
, nt_response
.data
,
753 MIN(nt_response
.length
,
754 sizeof(request
.data
.auth_crap
.nt_resp
)));
755 request
.data
.auth_crap
.nt_resp_len
= nt_response
.length
;
757 memcpy(request
.data
.auth_crap
.lm_resp
, lm_response
.data
,
758 MIN(lm_response
.length
,
759 sizeof(request
.data
.auth_crap
.lm_resp
)));
760 request
.data
.auth_crap
.lm_resp_len
= lm_response
.length
;
762 data_blob_free(&nt_response
);
763 data_blob_free(&lm_response
);
766 if (lp_client_lanman_auth()
767 && SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
768 (uchar
*)request
.data
.auth_crap
.lm_resp
)) {
769 request
.data
.auth_crap
.lm_resp_len
= 24;
771 request
.data
.auth_crap
.lm_resp_len
= 0;
773 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
774 (uchar
*)request
.data
.auth_crap
.nt_resp
);
776 request
.data
.auth_crap
.nt_resp_len
= 24;
779 result
= winbindd_request_response(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
781 /* Display response */
783 d_printf("challenge/response password authentication %s\n",
784 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
786 if (response
.data
.auth
.nt_status
)
787 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
788 response
.data
.auth
.nt_status_string
,
789 response
.data
.auth
.nt_status
,
790 response
.data
.auth
.error_string
);
792 return result
== NSS_STATUS_SUCCESS
;
795 /* Authenticate a user with a plaintext password and set a token */
797 static BOOL
wbinfo_klog(char *username
)
799 struct winbindd_request request
;
800 struct winbindd_response response
;
804 /* Send off request */
806 ZERO_STRUCT(request
);
807 ZERO_STRUCT(response
);
809 p
= strchr(username
, '%');
813 fstrcpy(request
.data
.auth
.user
, username
);
814 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
817 fstrcpy(request
.data
.auth
.user
, username
);
818 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
821 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
823 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
825 /* Display response */
827 d_printf("plaintext password authentication %s\n",
828 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
830 if (response
.data
.auth
.nt_status
)
831 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
832 response
.data
.auth
.nt_status_string
,
833 response
.data
.auth
.nt_status
,
834 response
.data
.auth
.error_string
);
836 if (result
!= NSS_STATUS_SUCCESS
)
839 if (response
.extra_data
.data
== NULL
) {
840 d_fprintf(stderr
, "Did not get token data\n");
844 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
845 d_fprintf(stderr
, "Could not set token\n");
849 d_printf("Successfully created AFS token\n");
853 /* Print domain users */
855 static BOOL
print_domain_users(const char *domain
)
857 struct winbindd_request request
;
858 struct winbindd_response response
;
859 const char *extra_data
;
862 /* Send request to winbind daemon */
864 ZERO_STRUCT(request
);
865 ZERO_STRUCT(response
);
868 /* '.' is the special sign for our own domwin */
869 if ( strequal(domain
, ".") )
870 fstrcpy( request
.domain_name
, lp_workgroup() );
872 fstrcpy( request
.domain_name
, domain
);
875 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
879 /* Look through extra data */
881 if (!response
.extra_data
.data
)
884 extra_data
= (const char *)response
.extra_data
.data
;
886 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
887 d_printf("%s\n", name
);
889 SAFE_FREE(response
.extra_data
.data
);
894 /* Print domain groups */
896 static BOOL
print_domain_groups(const char *domain
)
898 struct winbindd_request request
;
899 struct winbindd_response response
;
900 const char *extra_data
;
903 ZERO_STRUCT(request
);
904 ZERO_STRUCT(response
);
907 if ( strequal(domain
, ".") )
908 fstrcpy( request
.domain_name
, lp_workgroup() );
910 fstrcpy( request
.domain_name
, domain
);
913 if (winbindd_request_response(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
917 /* Look through extra data */
919 if (!response
.extra_data
.data
)
922 extra_data
= (const char *)response
.extra_data
.data
;
924 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
925 d_printf("%s\n", name
);
927 SAFE_FREE(response
.extra_data
.data
);
932 /* Set the authorised user for winbindd access in secrets.tdb */
934 static BOOL
wbinfo_set_auth_user(char *username
)
936 const char *password
;
938 fstring user
, domain
;
940 /* Separate into user and password */
942 parse_wbinfo_domain_user(username
, domain
, user
);
944 p
= strchr(user
, '%');
950 char *thepass
= getpass("Password: ");
957 /* Store or remove DOMAIN\username%password in secrets.tdb */
963 if (!secrets_store(SECRETS_AUTH_USER
, user
,
965 d_fprintf(stderr
, "error storing username\n");
969 /* We always have a domain name added by the
970 parse_wbinfo_domain_user() function. */
972 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
973 strlen(domain
) + 1)) {
974 d_fprintf(stderr
, "error storing domain name\n");
979 secrets_delete(SECRETS_AUTH_USER
);
980 secrets_delete(SECRETS_AUTH_DOMAIN
);
985 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
986 strlen(password
) + 1)) {
987 d_fprintf(stderr
, "error storing password\n");
992 secrets_delete(SECRETS_AUTH_PASSWORD
);
997 static void wbinfo_get_auth_user(void)
999 char *user
, *domain
, *password
;
1001 /* Lift data from secrets file */
1003 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1005 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1009 SAFE_FREE(password
);
1010 d_printf("No authorised user configured\n");
1014 /* Pretty print authorised user info */
1016 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1017 user
, password
? "%" : "", password
? password
: "");
1021 SAFE_FREE(password
);
1024 static BOOL
wbinfo_ping(void)
1028 result
= winbindd_request_response(WINBINDD_PING
, NULL
, NULL
);
1030 /* Display response */
1032 d_printf("Ping to winbindd %s on fd %d\n",
1033 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
1035 return result
== NSS_STATUS_SUCCESS
;
1041 OPT_SET_AUTH_USER
= 1000,
1051 OPT_LIST_ALL_DOMAINS
1054 int main(int argc
, char **argv
)
1059 static char *string_arg
;
1060 static char *opt_domain_name
;
1064 struct poptOption long_options
[] = {
1067 /* longName, shortName, argInfo, argPtr, value, descrip,
1070 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1071 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1072 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1073 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1074 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1075 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1076 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1077 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1078 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1079 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1080 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1081 "Get a new UID out of idmap" },
1082 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1083 "Get a new GID out of idmap" },
1084 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1085 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1086 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1087 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1088 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1089 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1090 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1091 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1092 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1093 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1094 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1095 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1096 "Get a DC name for a foreign domain", "domainname" },
1097 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1098 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1099 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1100 #ifdef WITH_FAKE_KASERVER
1101 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1104 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1105 /* destroys wbinfo --help output */
1106 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1108 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1113 /* Samba client initialisation */
1116 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
, True
)) {
1117 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1118 dyn_CONFIGFILE
, strerror(errno
));
1129 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1131 /* Parse command line options */
1134 poptPrintHelp(pc
, stderr
, 0);
1138 while((opt
= poptGetNextOpt(pc
)) != -1) {
1139 /* get the generic configuration parameters like --domain */
1142 poptFreeContext(pc
);
1144 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1145 POPT_CONTEXT_KEEP_FIRST
);
1147 while((opt
= poptGetNextOpt(pc
)) != -1) {
1150 if (!print_domain_users(opt_domain_name
)) {
1151 d_fprintf(stderr
, "Error looking up domain users\n");
1156 if (!print_domain_groups(opt_domain_name
)) {
1157 d_fprintf(stderr
, "Error looking up domain groups\n");
1162 if (!wbinfo_lookupsid(string_arg
)) {
1163 d_fprintf(stderr
, "Could not lookup sid %s\n", string_arg
);
1168 if (!wbinfo_lookupname(string_arg
)) {
1169 d_fprintf(stderr
, "Could not lookup name %s\n", string_arg
);
1174 if (!wbinfo_wins_byname(string_arg
)) {
1175 d_fprintf(stderr
, "Could not lookup WINS by name %s\n", string_arg
);
1180 if (!wbinfo_wins_byip(string_arg
)) {
1181 d_fprintf(stderr
, "Could not lookup WINS by IP %s\n", string_arg
);
1186 if (!wbinfo_uid_to_sid(int_arg
)) {
1187 d_fprintf(stderr
, "Could not convert uid %d to sid\n", int_arg
);
1192 if (!wbinfo_gid_to_sid(int_arg
)) {
1193 d_fprintf(stderr
, "Could not convert gid %d to sid\n",
1199 if (!wbinfo_sid_to_uid(string_arg
)) {
1200 d_fprintf(stderr
, "Could not convert sid %s to uid\n",
1206 if (!wbinfo_sid_to_gid(string_arg
)) {
1207 d_fprintf(stderr
, "Could not convert sid %s to gid\n",
1212 case OPT_ALLOCATE_UID
:
1213 if (!wbinfo_allocate_uid()) {
1214 d_fprintf(stderr
, "Could not allocate a uid\n");
1218 case OPT_ALLOCATE_GID
:
1219 if (!wbinfo_allocate_gid()) {
1220 d_fprintf(stderr
, "Could not allocate a gid\n");
1225 if (!wbinfo_check_secret()) {
1226 d_fprintf(stderr
, "Could not check secret\n");
1231 if (!wbinfo_list_domains(False
)) {
1232 d_fprintf(stderr
, "Could not list trusted domains\n");
1237 if (!wbinfo_show_sequence(opt_domain_name
)) {
1238 d_fprintf(stderr
, "Could not show sequence numbers\n");
1243 if (!wbinfo_domain_info(string_arg
)) {
1244 d_fprintf(stderr
, "Could not get domain info\n");
1249 if (!wbinfo_get_usergroups(string_arg
)) {
1250 d_fprintf(stderr
, "Could not get groups for user %s\n",
1256 if (!wbinfo_get_usersids(string_arg
)) {
1257 d_fprintf(stderr
, "Could not get group SIDs for user SID %s\n",
1262 case OPT_USERDOMGROUPS
:
1263 if (!wbinfo_get_userdomgroups(string_arg
)) {
1264 d_fprintf(stderr
, "Could not get user's domain groups "
1265 "for user SID %s\n", string_arg
);
1270 BOOL got_error
= False
;
1272 if (!wbinfo_auth(string_arg
)) {
1273 d_fprintf(stderr
, "Could not authenticate user %s with "
1274 "plaintext password\n", string_arg
);
1278 if (!wbinfo_auth_crap(string_arg
)) {
1279 d_fprintf(stderr
, "Could not authenticate user %s with "
1280 "challenge/response\n", string_arg
);
1289 BOOL got_error
= False
;
1290 uint32 flags
= WBFLAG_PAM_KRB5
|
1291 WBFLAG_PAM_CACHED_LOGIN
|
1292 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
1293 WBFLAG_PAM_INFO3_TEXT
;
1296 const char *arg
[] = { NULL
, NULL
};
1297 const char *cctypes
[] = { "FILE",
1304 arg
[0] = string_arg
;
1306 while (next_token(arg
, tok
, LIST_SEP
, sizeof(tok
))) {
1308 for (i
=0; i
< ARRAY_SIZE(cctypes
); i
++) {
1309 if (!wbinfo_auth_krb5(tok
, cctypes
[i
], flags
)) {
1310 d_fprintf(stderr
, "Could not authenticate user [%s] with "
1311 "Kerberos (ccache: %s)\n", tok
, cctypes
[i
]);
1323 if (!wbinfo_klog(string_arg
)) {
1324 d_fprintf(stderr
, "Could not klog user\n");
1329 if (!wbinfo_ping()) {
1330 d_fprintf(stderr
, "could not ping winbindd!\n");
1334 case OPT_SET_AUTH_USER
:
1335 if (!wbinfo_set_auth_user(string_arg
)) {
1339 case OPT_GET_AUTH_USER
:
1340 wbinfo_get_auth_user();
1343 if (!wbinfo_getdcname(string_arg
)) {
1347 case OPT_SEPARATOR
: {
1348 const char sep
= winbind_separator_int(True
);
1352 d_printf("%c\n", sep
);
1355 case OPT_LIST_ALL_DOMAINS
:
1356 if (!wbinfo_list_domains(True
)) {
1359 /* generic configuration options */
1360 case OPT_DOMAIN_NAME
:
1363 d_fprintf(stderr
, "Invalid option\n");
1364 poptPrintHelp(pc
, stderr
, 0);
1374 poptFreeContext(pc
);