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 /* pull pwent info for a given user */
124 static BOOL
wbinfo_get_userinfo(char *user
)
126 struct winbindd_request request
;
127 struct winbindd_response response
;
130 ZERO_STRUCT(request
);
131 ZERO_STRUCT(response
);
135 fstrcpy(request
.data
.username
, user
);
137 result
= winbindd_request_response(WINBINDD_GETPWNAM
, &request
, &response
);
139 if (result
!= NSS_STATUS_SUCCESS
)
142 d_printf( "%s:%s:%d:%d:%s:%s:%s\n",
143 response
.data
.pw
.pw_name
,
144 response
.data
.pw
.pw_passwd
,
145 response
.data
.pw
.pw_uid
,
146 response
.data
.pw
.pw_gid
,
147 response
.data
.pw
.pw_gecos
,
148 response
.data
.pw
.pw_dir
,
149 response
.data
.pw
.pw_shell
);
154 /* pull grent for a given group */
155 static BOOL
wbinfo_get_groupinfo(char *group
)
157 struct winbindd_request request
;
158 struct winbindd_response response
;
161 ZERO_STRUCT(request
);
162 ZERO_STRUCT(response
);
166 fstrcpy(request
.data
.groupname
, group
);
168 result
= winbindd_request_response(WINBINDD_GETGRNAM
, &request
,
171 if ( result
!= NSS_STATUS_SUCCESS
)
174 d_printf( "%s:%s:%d\n",
175 response
.data
.gr
.gr_name
,
176 response
.data
.gr
.gr_passwd
,
177 response
.data
.gr
.gr_gid
);
182 /* List groups a user is a member of */
184 static BOOL
wbinfo_get_usergroups(char *user
)
186 struct winbindd_request request
;
187 struct winbindd_response response
;
191 ZERO_STRUCT(request
);
192 ZERO_STRUCT(response
);
196 fstrcpy(request
.data
.username
, user
);
198 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
200 if (result
!= NSS_STATUS_SUCCESS
)
203 for (i
= 0; i
< response
.data
.num_entries
; i
++)
204 d_printf("%d\n", (int)((gid_t
*)response
.extra_data
.data
)[i
]);
206 SAFE_FREE(response
.extra_data
.data
);
212 /* List group SIDs a user SID is a member of */
213 static BOOL
wbinfo_get_usersids(char *user_sid
)
215 struct winbindd_request request
;
216 struct winbindd_response response
;
221 ZERO_STRUCT(request
);
222 ZERO_STRUCT(response
);
225 fstrcpy(request
.data
.sid
, user_sid
);
227 result
= winbindd_request_response(WINBINDD_GETUSERSIDS
, &request
, &response
);
229 if (result
!= NSS_STATUS_SUCCESS
)
232 s
= (const char *)response
.extra_data
.data
;
233 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
238 SAFE_FREE(response
.extra_data
.data
);
243 static BOOL
wbinfo_get_userdomgroups(const char *user_sid
)
245 struct winbindd_request request
;
246 struct winbindd_response response
;
249 ZERO_STRUCT(request
);
250 ZERO_STRUCT(response
);
253 fstrcpy(request
.data
.sid
, user_sid
);
255 result
= winbindd_request_response(WINBINDD_GETUSERDOMGROUPS
, &request
,
258 if (result
!= NSS_STATUS_SUCCESS
)
261 if (response
.data
.num_entries
!= 0)
262 printf("%s", (char *)response
.extra_data
.data
);
264 SAFE_FREE(response
.extra_data
.data
);
269 /* Convert NetBIOS name to IP */
271 static BOOL
wbinfo_wins_byname(char *name
)
273 struct winbindd_request request
;
274 struct winbindd_response response
;
276 ZERO_STRUCT(request
);
277 ZERO_STRUCT(response
);
281 fstrcpy(request
.data
.winsreq
, name
);
283 if (winbindd_request_response(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
284 NSS_STATUS_SUCCESS
) {
288 /* Display response */
290 d_printf("%s\n", response
.data
.winsresp
);
295 /* Convert IP to NetBIOS name */
297 static BOOL
wbinfo_wins_byip(char *ip
)
299 struct winbindd_request request
;
300 struct winbindd_response response
;
302 ZERO_STRUCT(request
);
303 ZERO_STRUCT(response
);
307 fstrcpy(request
.data
.winsreq
, ip
);
309 if (winbindd_request_response(WINBINDD_WINS_BYIP
, &request
, &response
) !=
310 NSS_STATUS_SUCCESS
) {
314 /* Display response */
316 d_printf("%s\n", response
.data
.winsresp
);
321 /* List trusted domains */
323 static BOOL
wbinfo_list_domains(BOOL list_all_domains
)
325 struct winbindd_request request
;
326 struct winbindd_response response
;
328 ZERO_STRUCT(request
);
329 ZERO_STRUCT(response
);
333 request
.data
.list_all_domains
= list_all_domains
;
335 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM
, &request
, &response
) !=
339 /* Display response */
341 if (response
.extra_data
.data
) {
342 const char *extra_data
= (char *)response
.extra_data
.data
;
346 while(next_token(&extra_data
, name
, "\n", sizeof(fstring
))) {
347 p
= strchr(name
, '\\');
349 d_fprintf(stderr
, "Got invalid response: %s\n",
354 d_printf("%s\n", name
);
357 SAFE_FREE(response
.extra_data
.data
);
363 /* List own domain */
365 static BOOL
wbinfo_list_own_domain(void)
367 d_printf("%s\n", get_winbind_domain());
372 /* show sequence numbers */
373 static BOOL
wbinfo_show_sequence(const char *domain
)
375 struct winbindd_request request
;
376 struct winbindd_response response
;
378 ZERO_STRUCT(response
);
379 ZERO_STRUCT(request
);
382 fstrcpy( request
.domain_name
, domain
);
386 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
390 /* Display response */
392 if (response
.extra_data
.data
) {
393 char *extra_data
= (char *)response
.extra_data
.data
;
394 d_printf("%s", extra_data
);
395 SAFE_FREE(response
.extra_data
.data
);
401 /* Show domain info */
403 static BOOL
wbinfo_domain_info(const char *domain_name
)
405 struct winbindd_request request
;
406 struct winbindd_response response
;
408 ZERO_STRUCT(request
);
409 ZERO_STRUCT(response
);
411 if ((strequal(domain_name
, ".")) || (domain_name
[0] == '\0'))
412 fstrcpy(request
.domain_name
, get_winbind_domain());
414 fstrcpy(request
.domain_name
, domain_name
);
418 if (winbindd_request_response(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
422 /* Display response */
424 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
425 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
427 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
429 d_printf("Active Directory : %s\n",
430 response
.data
.domain_info
.active_directory
? "Yes" : "No");
431 d_printf("Native : %s\n",
432 response
.data
.domain_info
.native_mode
? "Yes" : "No");
434 d_printf("Primary : %s\n",
435 response
.data
.domain_info
.primary
? "Yes" : "No");
437 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
442 /* Get a foreign DC's name */
443 static BOOL
wbinfo_getdcname(const char *domain_name
)
445 struct winbindd_request request
;
446 struct winbindd_response response
;
448 ZERO_STRUCT(request
);
449 ZERO_STRUCT(response
);
451 fstrcpy(request
.domain_name
, domain_name
);
455 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
, &response
) !=
456 NSS_STATUS_SUCCESS
) {
457 d_fprintf(stderr
, "Could not get dc name for %s\n", domain_name
);
461 /* Display response */
463 d_printf("%s\n", response
.data
.dc_name
);
468 /* Check trust account password */
470 static BOOL
wbinfo_check_secret(void)
472 struct winbindd_response response
;
475 ZERO_STRUCT(response
);
477 result
= winbindd_request_response(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
479 d_printf("checking the trust secret via RPC calls %s\n",
480 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
482 if (result
!= NSS_STATUS_SUCCESS
)
483 d_fprintf(stderr
, "error code was %s (0x%x)\n",
484 response
.data
.auth
.nt_status_string
,
485 response
.data
.auth
.nt_status
);
487 return result
== NSS_STATUS_SUCCESS
;
490 /* Convert uid to sid */
492 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
494 struct winbindd_request request
;
495 struct winbindd_response response
;
497 ZERO_STRUCT(request
);
498 ZERO_STRUCT(response
);
502 request
.data
.uid
= uid
;
504 if (winbindd_request_response(WINBINDD_UID_TO_SID
, &request
, &response
) !=
508 /* Display response */
510 d_printf("%s\n", response
.data
.sid
.sid
);
515 /* Convert gid to sid */
517 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
519 struct winbindd_request request
;
520 struct winbindd_response response
;
522 ZERO_STRUCT(request
);
523 ZERO_STRUCT(response
);
527 request
.data
.gid
= gid
;
529 if (winbindd_request_response(WINBINDD_GID_TO_SID
, &request
, &response
) !=
533 /* Display response */
535 d_printf("%s\n", response
.data
.sid
.sid
);
540 /* Convert sid to uid */
542 static BOOL
wbinfo_sid_to_uid(char *sid
)
544 struct winbindd_request request
;
545 struct winbindd_response response
;
547 ZERO_STRUCT(request
);
548 ZERO_STRUCT(response
);
552 fstrcpy(request
.data
.sid
, sid
);
554 if (winbindd_request_response(WINBINDD_SID_TO_UID
, &request
, &response
) !=
558 /* Display response */
560 d_printf("%d\n", (int)response
.data
.uid
);
565 static BOOL
wbinfo_sid_to_gid(char *sid
)
567 struct winbindd_request request
;
568 struct winbindd_response response
;
570 ZERO_STRUCT(request
);
571 ZERO_STRUCT(response
);
575 fstrcpy(request
.data
.sid
, sid
);
577 if (winbindd_request_response(WINBINDD_SID_TO_GID
, &request
, &response
) !=
581 /* Display response */
583 d_printf("%d\n", (int)response
.data
.gid
);
588 static BOOL
wbinfo_allocate_uid(void)
592 if (!winbind_allocate_uid(&uid
))
595 d_printf("New uid: %d\n", uid
);
600 static BOOL
wbinfo_allocate_gid(void)
604 if (!winbind_allocate_gid(&gid
))
607 d_printf("New gid: %d\n", gid
);
612 /* Convert sid to string */
614 static BOOL
wbinfo_lookupsid(char *sid
)
616 struct winbindd_request request
;
617 struct winbindd_response response
;
619 ZERO_STRUCT(request
);
620 ZERO_STRUCT(response
);
622 /* Send off request */
624 fstrcpy(request
.data
.sid
, sid
);
626 if (winbindd_request_response(WINBINDD_LOOKUPSID
, &request
, &response
) !=
630 /* Display response */
632 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
633 winbind_separator(), response
.data
.name
.name
,
634 response
.data
.name
.type
);
639 /* Lookup a list of RIDs */
641 static BOOL
wbinfo_lookuprids(char *domain
, char *arg
)
650 enum lsa_SidType
*types
;
651 const char *domain_name
;
653 struct winbindd_request request
;
654 struct winbindd_response response
;
656 ZERO_STRUCT(request
);
657 ZERO_STRUCT(response
);
659 if ((domain
== NULL
) || (strequal(domain
, ".")) || (domain
[0] == '\0'))
660 fstrcpy(request
.domain_name
, get_winbind_domain());
662 fstrcpy(request
.domain_name
, domain
);
666 if (winbindd_request_response(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
667 NSS_STATUS_SUCCESS
) {
668 d_printf("Could not get domain sid for %s\n", request
.domain_name
);
672 if (!string_to_sid(&sid
, response
.data
.domain_info
.sid
)) {
673 d_printf("Could not convert %s to sid\n", response
.data
.domain_info
.sid
);
677 mem_ctx
= talloc_new(NULL
);
678 if (mem_ctx
== NULL
) {
679 d_printf("talloc_new failed\n");
687 while (next_token(&p
, ridstr
, " ,\n", sizeof(ridstr
))) {
688 uint32 rid
= strtoul(ridstr
, NULL
, 10);
689 ADD_TO_ARRAY(mem_ctx
, uint32
, rid
, &rids
, &num_rids
);
693 TALLOC_FREE(mem_ctx
);
697 if (!winbind_lookup_rids(mem_ctx
, &sid
, num_rids
, rids
,
698 &domain_name
, &names
, &types
)) {
699 d_printf("winbind_lookup_rids failed\n");
700 TALLOC_FREE(mem_ctx
);
704 d_printf("Domain: %s\n", domain_name
);
706 for (i
=0; i
<num_rids
; i
++) {
707 d_printf("%8d: %s (%s)\n", rids
[i
], names
[i
],
708 sid_type_lookup(types
[i
]));
711 TALLOC_FREE(mem_ctx
);
715 /* Convert string to sid */
717 static BOOL
wbinfo_lookupname(char *name
)
719 struct winbindd_request request
;
720 struct winbindd_response response
;
722 /* Send off request */
724 ZERO_STRUCT(request
);
725 ZERO_STRUCT(response
);
727 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
728 request
.data
.name
.name
);
730 if (winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
734 /* Display response */
736 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
741 /* Authenticate a user with a plaintext password */
743 static BOOL
wbinfo_auth_krb5(char *username
, const char *cctype
, uint32 flags
)
745 struct winbindd_request request
;
746 struct winbindd_response response
;
750 /* Send off request */
752 ZERO_STRUCT(request
);
753 ZERO_STRUCT(response
);
755 p
= strchr(username
, '%');
759 fstrcpy(request
.data
.auth
.user
, username
);
760 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
763 fstrcpy(request
.data
.auth
.user
, username
);
765 request
.flags
= flags
;
767 fstrcpy(request
.data
.auth
.krb5_cc_type
, cctype
);
769 request
.data
.auth
.uid
= geteuid();
771 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
773 /* Display response */
775 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
776 username
, (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", cctype
);
778 if (response
.data
.auth
.nt_status
)
779 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
780 response
.data
.auth
.nt_status_string
,
781 response
.data
.auth
.nt_status
,
782 response
.data
.auth
.error_string
);
784 if (result
== NSS_STATUS_SUCCESS
) {
786 if (request
.flags
& WBFLAG_PAM_INFO3_TEXT
) {
787 if (response
.data
.auth
.info3
.user_flgs
& LOGON_CACHED_ACCOUNT
) {
788 d_printf("user_flgs: LOGON_CACHED_ACCOUNT\n");
792 if (response
.data
.auth
.krb5ccname
[0] != '\0') {
793 d_printf("credentials were put in: %s\n", response
.data
.auth
.krb5ccname
);
795 d_printf("no credentials cached\n");
799 return result
== NSS_STATUS_SUCCESS
;
802 /* Authenticate a user with a plaintext password */
804 static BOOL
wbinfo_auth(char *username
)
806 struct winbindd_request request
;
807 struct winbindd_response response
;
811 /* Send off request */
813 ZERO_STRUCT(request
);
814 ZERO_STRUCT(response
);
816 p
= strchr(username
, '%');
820 fstrcpy(request
.data
.auth
.user
, username
);
821 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
824 fstrcpy(request
.data
.auth
.user
, username
);
826 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
828 /* Display response */
830 d_printf("plaintext password authentication %s\n",
831 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
833 if (response
.data
.auth
.nt_status
)
834 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
835 response
.data
.auth
.nt_status_string
,
836 response
.data
.auth
.nt_status
,
837 response
.data
.auth
.error_string
);
839 return result
== NSS_STATUS_SUCCESS
;
842 /* Authenticate a user with a challenge/response */
844 static BOOL
wbinfo_auth_crap(char *username
)
846 struct winbindd_request request
;
847 struct winbindd_response response
;
854 /* Send off request */
856 ZERO_STRUCT(request
);
857 ZERO_STRUCT(response
);
859 p
= strchr(username
, '%');
863 fstrcpy(pass
, p
+ 1);
866 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
868 request
.data
.auth_crap
.logon_parameters
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
| MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
870 fstrcpy(request
.data
.auth_crap
.user
, name_user
);
872 fstrcpy(request
.data
.auth_crap
.domain
,
875 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
877 if (lp_client_ntlmv2_auth()) {
878 DATA_BLOB server_chal
;
879 DATA_BLOB names_blob
;
881 DATA_BLOB lm_response
;
882 DATA_BLOB nt_response
;
884 server_chal
= data_blob(request
.data
.auth_crap
.chal
, 8);
886 /* Pretend this is a login to 'us', for blob purposes */
887 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
889 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
891 &lm_response
, &nt_response
, NULL
)) {
892 data_blob_free(&names_blob
);
893 data_blob_free(&server_chal
);
896 data_blob_free(&names_blob
);
897 data_blob_free(&server_chal
);
899 memcpy(request
.data
.auth_crap
.nt_resp
, nt_response
.data
,
900 MIN(nt_response
.length
,
901 sizeof(request
.data
.auth_crap
.nt_resp
)));
902 request
.data
.auth_crap
.nt_resp_len
= nt_response
.length
;
904 memcpy(request
.data
.auth_crap
.lm_resp
, lm_response
.data
,
905 MIN(lm_response
.length
,
906 sizeof(request
.data
.auth_crap
.lm_resp
)));
907 request
.data
.auth_crap
.lm_resp_len
= lm_response
.length
;
909 data_blob_free(&nt_response
);
910 data_blob_free(&lm_response
);
913 if (lp_client_lanman_auth()
914 && SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
915 (uchar
*)request
.data
.auth_crap
.lm_resp
)) {
916 request
.data
.auth_crap
.lm_resp_len
= 24;
918 request
.data
.auth_crap
.lm_resp_len
= 0;
920 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
921 (uchar
*)request
.data
.auth_crap
.nt_resp
);
923 request
.data
.auth_crap
.nt_resp_len
= 24;
926 result
= winbindd_request_response(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
928 /* Display response */
930 d_printf("challenge/response password authentication %s\n",
931 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
933 if (response
.data
.auth
.nt_status
)
934 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
935 response
.data
.auth
.nt_status_string
,
936 response
.data
.auth
.nt_status
,
937 response
.data
.auth
.error_string
);
939 return result
== NSS_STATUS_SUCCESS
;
942 /* Authenticate a user with a plaintext password and set a token */
944 static BOOL
wbinfo_klog(char *username
)
946 struct winbindd_request request
;
947 struct winbindd_response response
;
951 /* Send off request */
953 ZERO_STRUCT(request
);
954 ZERO_STRUCT(response
);
956 p
= strchr(username
, '%');
960 fstrcpy(request
.data
.auth
.user
, username
);
961 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
964 fstrcpy(request
.data
.auth
.user
, username
);
965 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
968 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
970 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
972 /* Display response */
974 d_printf("plaintext password authentication %s\n",
975 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
977 if (response
.data
.auth
.nt_status
)
978 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
979 response
.data
.auth
.nt_status_string
,
980 response
.data
.auth
.nt_status
,
981 response
.data
.auth
.error_string
);
983 if (result
!= NSS_STATUS_SUCCESS
)
986 if (response
.extra_data
.data
== NULL
) {
987 d_fprintf(stderr
, "Did not get token data\n");
991 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
992 d_fprintf(stderr
, "Could not set token\n");
996 d_printf("Successfully created AFS token\n");
1000 /* Print domain users */
1002 static BOOL
print_domain_users(const char *domain
)
1004 struct winbindd_request request
;
1005 struct winbindd_response response
;
1006 const char *extra_data
;
1009 /* Send request to winbind daemon */
1011 ZERO_STRUCT(request
);
1012 ZERO_STRUCT(response
);
1015 /* '.' is the special sign for our own domain */
1016 if ( strequal(domain
, ".") )
1017 fstrcpy( request
.domain_name
, get_winbind_domain() );
1019 fstrcpy( request
.domain_name
, domain
);
1022 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
1026 /* Look through extra data */
1028 if (!response
.extra_data
.data
)
1031 extra_data
= (const char *)response
.extra_data
.data
;
1033 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
1034 d_printf("%s\n", name
);
1036 SAFE_FREE(response
.extra_data
.data
);
1041 /* Print domain groups */
1043 static BOOL
print_domain_groups(const char *domain
)
1045 struct winbindd_request request
;
1046 struct winbindd_response response
;
1047 const char *extra_data
;
1050 ZERO_STRUCT(request
);
1051 ZERO_STRUCT(response
);
1054 if ( strequal(domain
, ".") )
1055 fstrcpy( request
.domain_name
, get_winbind_domain() );
1057 fstrcpy( request
.domain_name
, domain
);
1060 if (winbindd_request_response(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
1064 /* Look through extra data */
1066 if (!response
.extra_data
.data
)
1069 extra_data
= (const char *)response
.extra_data
.data
;
1071 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
1072 d_printf("%s\n", name
);
1074 SAFE_FREE(response
.extra_data
.data
);
1079 /* Set the authorised user for winbindd access in secrets.tdb */
1081 static BOOL
wbinfo_set_auth_user(char *username
)
1083 const char *password
;
1085 fstring user
, domain
;
1087 /* Separate into user and password */
1089 parse_wbinfo_domain_user(username
, domain
, user
);
1091 p
= strchr(user
, '%');
1097 char *thepass
= getpass("Password: ");
1104 /* Store or remove DOMAIN\username%password in secrets.tdb */
1110 if (!secrets_store(SECRETS_AUTH_USER
, user
,
1111 strlen(user
) + 1)) {
1112 d_fprintf(stderr
, "error storing username\n");
1116 /* We always have a domain name added by the
1117 parse_wbinfo_domain_user() function. */
1119 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
1120 strlen(domain
) + 1)) {
1121 d_fprintf(stderr
, "error storing domain name\n");
1126 secrets_delete(SECRETS_AUTH_USER
);
1127 secrets_delete(SECRETS_AUTH_DOMAIN
);
1132 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
1133 strlen(password
) + 1)) {
1134 d_fprintf(stderr
, "error storing password\n");
1139 secrets_delete(SECRETS_AUTH_PASSWORD
);
1144 static void wbinfo_get_auth_user(void)
1146 char *user
, *domain
, *password
;
1148 /* Lift data from secrets file */
1150 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1152 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1156 SAFE_FREE(password
);
1157 d_printf("No authorised user configured\n");
1161 /* Pretty print authorised user info */
1163 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1164 user
, password
? "%" : "", password
? password
: "");
1168 SAFE_FREE(password
);
1171 static BOOL
wbinfo_ping(void)
1175 result
= winbindd_request_response(WINBINDD_PING
, NULL
, NULL
);
1177 /* Display response */
1179 d_printf("Ping to winbindd %s on fd %d\n",
1180 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
1182 return result
== NSS_STATUS_SUCCESS
;
1188 OPT_SET_AUTH_USER
= 1000,
1198 OPT_LIST_ALL_DOMAINS
,
1199 OPT_LIST_OWN_DOMAIN
,
1203 int main(int argc
, char **argv
, char **envp
)
1208 static char *string_arg
;
1209 static char *opt_domain_name
;
1213 struct poptOption long_options
[] = {
1216 /* longName, shortName, argInfo, argPtr, value, descrip,
1219 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1220 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1221 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1222 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1223 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1224 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1225 { "lookup-rids", 'R', POPT_ARG_STRING
, &string_arg
, 'R', "Converts RIDs to names", "RIDs" },
1226 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1227 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1228 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1229 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1230 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1231 "Get a new UID out of idmap" },
1232 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1233 "Get a new GID out of idmap" },
1234 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1235 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1236 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1237 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
1238 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1239 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1240 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1241 { "group-info", 0, POPT_ARG_STRING
, &string_arg
, OPT_GROUP_INFO
, "Get group info", "GROUP" },
1242 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1243 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1244 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1245 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1246 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1247 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1248 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1249 "Get a DC name for a foreign domain", "domainname" },
1250 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1251 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1252 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1253 #ifdef WITH_FAKE_KASERVER
1254 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1257 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1258 /* destroys wbinfo --help output */
1259 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1261 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1266 /* Samba client initialisation */
1269 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
, True
)) {
1270 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1271 dyn_CONFIGFILE
, strerror(errno
));
1282 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1284 /* Parse command line options */
1287 poptPrintHelp(pc
, stderr
, 0);
1291 while((opt
= poptGetNextOpt(pc
)) != -1) {
1292 /* get the generic configuration parameters like --domain */
1295 poptFreeContext(pc
);
1297 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1298 POPT_CONTEXT_KEEP_FIRST
);
1300 while((opt
= poptGetNextOpt(pc
)) != -1) {
1303 if (!print_domain_users(opt_domain_name
)) {
1304 d_fprintf(stderr
, "Error looking up domain users\n");
1309 if (!print_domain_groups(opt_domain_name
)) {
1310 d_fprintf(stderr
, "Error looking up domain groups\n");
1315 if (!wbinfo_lookupsid(string_arg
)) {
1316 d_fprintf(stderr
, "Could not lookup sid %s\n", string_arg
);
1321 if (!wbinfo_lookuprids(opt_domain_name
, string_arg
)) {
1322 d_fprintf(stderr
, "Could not lookup RIDs %s\n", string_arg
);
1327 if (!wbinfo_lookupname(string_arg
)) {
1328 d_fprintf(stderr
, "Could not lookup name %s\n", string_arg
);
1333 if (!wbinfo_wins_byname(string_arg
)) {
1334 d_fprintf(stderr
, "Could not lookup WINS by name %s\n", string_arg
);
1339 if (!wbinfo_wins_byip(string_arg
)) {
1340 d_fprintf(stderr
, "Could not lookup WINS by IP %s\n", string_arg
);
1345 if (!wbinfo_uid_to_sid(int_arg
)) {
1346 d_fprintf(stderr
, "Could not convert uid %d to sid\n", int_arg
);
1351 if (!wbinfo_gid_to_sid(int_arg
)) {
1352 d_fprintf(stderr
, "Could not convert gid %d to sid\n",
1358 if (!wbinfo_sid_to_uid(string_arg
)) {
1359 d_fprintf(stderr
, "Could not convert sid %s to uid\n",
1365 if (!wbinfo_sid_to_gid(string_arg
)) {
1366 d_fprintf(stderr
, "Could not convert sid %s to gid\n",
1371 case OPT_ALLOCATE_UID
:
1372 if (!wbinfo_allocate_uid()) {
1373 d_fprintf(stderr
, "Could not allocate a uid\n");
1377 case OPT_ALLOCATE_GID
:
1378 if (!wbinfo_allocate_gid()) {
1379 d_fprintf(stderr
, "Could not allocate a gid\n");
1384 if (!wbinfo_check_secret()) {
1385 d_fprintf(stderr
, "Could not check secret\n");
1390 if (!wbinfo_list_domains(False
)) {
1391 d_fprintf(stderr
, "Could not list trusted domains\n");
1396 if (!wbinfo_show_sequence(opt_domain_name
)) {
1397 d_fprintf(stderr
, "Could not show sequence numbers\n");
1402 if (!wbinfo_domain_info(string_arg
)) {
1403 d_fprintf(stderr
, "Could not get domain info\n");
1408 if (!wbinfo_get_userinfo(string_arg
)) {
1409 d_fprintf(stderr
, "Could not get info for user %s\n",
1414 case OPT_GROUP_INFO
:
1415 if ( !wbinfo_get_groupinfo(string_arg
)) {
1416 d_fprintf(stderr
, "Could not get info for "
1417 "group %s\n", string_arg
);
1422 if (!wbinfo_get_usergroups(string_arg
)) {
1423 d_fprintf(stderr
, "Could not get groups for user %s\n",
1429 if (!wbinfo_get_usersids(string_arg
)) {
1430 d_fprintf(stderr
, "Could not get group SIDs for user SID %s\n",
1435 case OPT_USERDOMGROUPS
:
1436 if (!wbinfo_get_userdomgroups(string_arg
)) {
1437 d_fprintf(stderr
, "Could not get user's domain groups "
1438 "for user SID %s\n", string_arg
);
1443 BOOL got_error
= False
;
1445 if (!wbinfo_auth(string_arg
)) {
1446 d_fprintf(stderr
, "Could not authenticate user %s with "
1447 "plaintext password\n", string_arg
);
1451 if (!wbinfo_auth_crap(string_arg
)) {
1452 d_fprintf(stderr
, "Could not authenticate user %s with "
1453 "challenge/response\n", string_arg
);
1462 BOOL got_error
= False
;
1463 uint32 flags
= WBFLAG_PAM_KRB5
|
1464 WBFLAG_PAM_CACHED_LOGIN
|
1465 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
1466 WBFLAG_PAM_INFO3_TEXT
;
1469 const char *arg
[] = { NULL
, NULL
};
1470 const char *cctypes
[] = { "FILE",
1477 arg
[0] = string_arg
;
1479 while (next_token(arg
, tok
, LIST_SEP
, sizeof(tok
))) {
1481 for (i
=0; i
< ARRAY_SIZE(cctypes
); i
++) {
1482 if (!wbinfo_auth_krb5(tok
, cctypes
[i
], flags
)) {
1483 d_fprintf(stderr
, "Could not authenticate user [%s] with "
1484 "Kerberos (ccache: %s)\n", tok
, cctypes
[i
]);
1496 if (!wbinfo_klog(string_arg
)) {
1497 d_fprintf(stderr
, "Could not klog user\n");
1502 if (!wbinfo_ping()) {
1503 d_fprintf(stderr
, "could not ping winbindd!\n");
1507 case OPT_SET_AUTH_USER
:
1508 if (!wbinfo_set_auth_user(string_arg
)) {
1512 case OPT_GET_AUTH_USER
:
1513 wbinfo_get_auth_user();
1516 if (!wbinfo_getdcname(string_arg
)) {
1520 case OPT_SEPARATOR
: {
1521 const char sep
= winbind_separator_int(True
);
1525 d_printf("%c\n", sep
);
1528 case OPT_LIST_ALL_DOMAINS
:
1529 if (!wbinfo_list_domains(True
)) {
1533 case OPT_LIST_OWN_DOMAIN
:
1534 if (!wbinfo_list_own_domain()) {
1538 /* generic configuration options */
1539 case OPT_DOMAIN_NAME
:
1542 d_fprintf(stderr
, "Invalid option\n");
1543 poptPrintHelp(pc
, stderr
, 0);
1553 poptFreeContext(pc
);