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 /* List groups a user is a member of */
156 static BOOL
wbinfo_get_usergroups(char *user
)
158 struct winbindd_request request
;
159 struct winbindd_response response
;
163 ZERO_STRUCT(request
);
164 ZERO_STRUCT(response
);
168 fstrcpy(request
.data
.username
, user
);
170 result
= winbindd_request_response(WINBINDD_GETGROUPS
, &request
, &response
);
172 if (result
!= NSS_STATUS_SUCCESS
)
175 for (i
= 0; i
< response
.data
.num_entries
; i
++)
176 d_printf("%d\n", (int)((gid_t
*)response
.extra_data
.data
)[i
]);
178 SAFE_FREE(response
.extra_data
.data
);
184 /* List group SIDs a user SID is a member of */
185 static BOOL
wbinfo_get_usersids(char *user_sid
)
187 struct winbindd_request request
;
188 struct winbindd_response response
;
193 ZERO_STRUCT(request
);
194 ZERO_STRUCT(response
);
197 fstrcpy(request
.data
.sid
, user_sid
);
199 result
= winbindd_request_response(WINBINDD_GETUSERSIDS
, &request
, &response
);
201 if (result
!= NSS_STATUS_SUCCESS
)
204 s
= response
.extra_data
.data
;
205 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
210 SAFE_FREE(response
.extra_data
.data
);
215 static BOOL
wbinfo_get_userdomgroups(const char *user_sid
)
217 struct winbindd_request request
;
218 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_GETUSERDOMGROUPS
, &request
,
230 if (result
!= NSS_STATUS_SUCCESS
)
233 if (response
.data
.num_entries
!= 0)
234 printf("%s", (char *)response
.extra_data
.data
);
236 SAFE_FREE(response
.extra_data
.data
);
241 /* Convert NetBIOS name to IP */
243 static BOOL
wbinfo_wins_byname(char *name
)
245 struct winbindd_request request
;
246 struct winbindd_response response
;
248 ZERO_STRUCT(request
);
249 ZERO_STRUCT(response
);
253 fstrcpy(request
.data
.winsreq
, name
);
255 if (winbindd_request_response(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
256 NSS_STATUS_SUCCESS
) {
260 /* Display response */
262 d_printf("%s\n", response
.data
.winsresp
);
267 /* Convert IP to NetBIOS name */
269 static BOOL
wbinfo_wins_byip(char *ip
)
271 struct winbindd_request request
;
272 struct winbindd_response response
;
274 ZERO_STRUCT(request
);
275 ZERO_STRUCT(response
);
279 fstrcpy(request
.data
.winsreq
, ip
);
281 if (winbindd_request_response(WINBINDD_WINS_BYIP
, &request
, &response
) !=
282 NSS_STATUS_SUCCESS
) {
286 /* Display response */
288 d_printf("%s\n", response
.data
.winsresp
);
293 /* List trusted domains */
295 static BOOL
wbinfo_list_domains(BOOL list_all_domains
)
297 struct winbindd_request request
;
298 struct winbindd_response response
;
300 ZERO_STRUCT(request
);
301 ZERO_STRUCT(response
);
305 request
.data
.list_all_domains
= list_all_domains
;
307 if (winbindd_request_response(WINBINDD_LIST_TRUSTDOM
, &request
, &response
) !=
311 /* Display response */
313 if (response
.extra_data
.data
) {
314 const char *extra_data
= (char *)response
.extra_data
.data
;
318 while(next_token(&extra_data
, name
, "\n", sizeof(fstring
))) {
319 p
= strchr(name
, '\\');
321 d_fprintf(stderr
, "Got invalid response: %s\n",
326 d_printf("%s\n", name
);
329 SAFE_FREE(response
.extra_data
.data
);
335 /* List own domain */
337 static BOOL
wbinfo_list_own_domain(void)
339 d_printf("%s\n", get_winbind_domain());
344 /* show sequence numbers */
345 static BOOL
wbinfo_show_sequence(const char *domain
)
347 struct winbindd_request request
;
348 struct winbindd_response response
;
350 ZERO_STRUCT(response
);
351 ZERO_STRUCT(request
);
354 fstrcpy( request
.domain_name
, domain
);
358 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
362 /* Display response */
364 if (response
.extra_data
.data
) {
365 char *extra_data
= (char *)response
.extra_data
.data
;
366 d_printf("%s", extra_data
);
367 SAFE_FREE(response
.extra_data
.data
);
373 /* Show domain info */
375 static BOOL
wbinfo_domain_info(const char *domain_name
)
377 struct winbindd_request request
;
378 struct winbindd_response response
;
380 ZERO_STRUCT(request
);
381 ZERO_STRUCT(response
);
383 fstrcpy(request
.domain_name
, domain_name
);
387 if (winbindd_request_response(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
391 /* Display response */
393 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
394 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
396 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
398 d_printf("Active Directory : %s\n",
399 response
.data
.domain_info
.active_directory
? "Yes" : "No");
400 d_printf("Native : %s\n",
401 response
.data
.domain_info
.native_mode
? "Yes" : "No");
403 d_printf("Primary : %s\n",
404 response
.data
.domain_info
.primary
? "Yes" : "No");
406 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
411 /* Get a foreign DC's name */
412 static BOOL
wbinfo_getdcname(const char *domain_name
)
414 struct winbindd_request request
;
415 struct winbindd_response response
;
417 ZERO_STRUCT(request
);
418 ZERO_STRUCT(response
);
420 fstrcpy(request
.domain_name
, domain_name
);
424 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
, &response
) !=
425 NSS_STATUS_SUCCESS
) {
426 d_fprintf(stderr
, "Could not get dc name for %s\n", domain_name
);
430 /* Display response */
432 d_printf("%s\n", response
.data
.dc_name
);
437 /* Check trust account password */
439 static BOOL
wbinfo_check_secret(void)
441 struct winbindd_response response
;
444 ZERO_STRUCT(response
);
446 result
= winbindd_request_response(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
448 d_printf("checking the trust secret via RPC calls %s\n",
449 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
451 if (result
!= NSS_STATUS_SUCCESS
)
452 d_fprintf(stderr
, "error code was %s (0x%x)\n",
453 response
.data
.auth
.nt_status_string
,
454 response
.data
.auth
.nt_status
);
456 return result
== NSS_STATUS_SUCCESS
;
459 /* Convert uid to sid */
461 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
463 struct winbindd_request request
;
464 struct winbindd_response response
;
466 ZERO_STRUCT(request
);
467 ZERO_STRUCT(response
);
471 request
.data
.uid
= uid
;
473 if (winbindd_request_response(WINBINDD_UID_TO_SID
, &request
, &response
) !=
477 /* Display response */
479 d_printf("%s\n", response
.data
.sid
.sid
);
484 /* Convert gid to sid */
486 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
488 struct winbindd_request request
;
489 struct winbindd_response response
;
491 ZERO_STRUCT(request
);
492 ZERO_STRUCT(response
);
496 request
.data
.gid
= gid
;
498 if (winbindd_request_response(WINBINDD_GID_TO_SID
, &request
, &response
) !=
502 /* Display response */
504 d_printf("%s\n", response
.data
.sid
.sid
);
509 /* Convert sid to uid */
511 static BOOL
wbinfo_sid_to_uid(char *sid
)
513 struct winbindd_request request
;
514 struct winbindd_response response
;
516 ZERO_STRUCT(request
);
517 ZERO_STRUCT(response
);
521 fstrcpy(request
.data
.sid
, sid
);
523 if (winbindd_request_response(WINBINDD_SID_TO_UID
, &request
, &response
) !=
527 /* Display response */
529 d_printf("%d\n", (int)response
.data
.uid
);
534 static BOOL
wbinfo_sid_to_gid(char *sid
)
536 struct winbindd_request request
;
537 struct winbindd_response response
;
539 ZERO_STRUCT(request
);
540 ZERO_STRUCT(response
);
544 fstrcpy(request
.data
.sid
, sid
);
546 if (winbindd_request_response(WINBINDD_SID_TO_GID
, &request
, &response
) !=
550 /* Display response */
552 d_printf("%d\n", (int)response
.data
.gid
);
557 static BOOL
wbinfo_allocate_uid(void)
561 if (!winbind_allocate_uid(&uid
))
564 d_printf("New uid: %d\n", uid
);
569 static BOOL
wbinfo_allocate_gid(void)
573 if (!winbind_allocate_gid(&gid
))
576 d_printf("New gid: %d\n", gid
);
581 /* Convert sid to string */
583 static BOOL
wbinfo_lookupsid(char *sid
)
585 struct winbindd_request request
;
586 struct winbindd_response response
;
588 ZERO_STRUCT(request
);
589 ZERO_STRUCT(response
);
591 /* Send off request */
593 fstrcpy(request
.data
.sid
, sid
);
595 if (winbindd_request_response(WINBINDD_LOOKUPSID
, &request
, &response
) !=
599 /* Display response */
601 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
602 winbind_separator(), response
.data
.name
.name
,
603 response
.data
.name
.type
);
608 /* Convert string to sid */
610 static BOOL
wbinfo_lookupname(char *name
)
612 struct winbindd_request request
;
613 struct winbindd_response response
;
615 /* Send off request */
617 ZERO_STRUCT(request
);
618 ZERO_STRUCT(response
);
620 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
621 request
.data
.name
.name
);
623 if (winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
627 /* Display response */
629 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
634 /* Authenticate a user with a plaintext password */
636 static BOOL
wbinfo_auth_krb5(char *username
, const char *cctype
, uint32 flags
)
638 struct winbindd_request request
;
639 struct winbindd_response response
;
643 /* Send off request */
645 ZERO_STRUCT(request
);
646 ZERO_STRUCT(response
);
648 p
= strchr(username
, '%');
652 fstrcpy(request
.data
.auth
.user
, username
);
653 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
656 fstrcpy(request
.data
.auth
.user
, username
);
658 request
.flags
= flags
;
660 fstrcpy(request
.data
.auth
.krb5_cc_type
, cctype
);
662 request
.data
.auth
.uid
= geteuid();
664 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
666 /* Display response */
668 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
669 username
, (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", cctype
);
671 if (response
.data
.auth
.nt_status
)
672 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
673 response
.data
.auth
.nt_status_string
,
674 response
.data
.auth
.nt_status
,
675 response
.data
.auth
.error_string
);
677 if (result
== NSS_STATUS_SUCCESS
) {
679 if (request
.flags
& WBFLAG_PAM_INFO3_TEXT
) {
680 if (response
.data
.auth
.info3
.user_flgs
& LOGON_CACHED_ACCOUNT
) {
681 d_printf("user_flgs: LOGON_CACHED_ACCOUNT\n");
685 if (response
.data
.auth
.krb5ccname
[0] != '\0') {
686 d_printf("credentials were put in: %s\n", response
.data
.auth
.krb5ccname
);
688 d_printf("no credentials cached\n");
692 return result
== NSS_STATUS_SUCCESS
;
695 /* Authenticate a user with a plaintext password */
697 static BOOL
wbinfo_auth(char *username
)
699 struct winbindd_request request
;
700 struct winbindd_response response
;
704 /* Send off request */
706 ZERO_STRUCT(request
);
707 ZERO_STRUCT(response
);
709 p
= strchr(username
, '%');
713 fstrcpy(request
.data
.auth
.user
, username
);
714 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
717 fstrcpy(request
.data
.auth
.user
, username
);
719 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
721 /* Display response */
723 d_printf("plaintext password authentication %s\n",
724 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
726 if (response
.data
.auth
.nt_status
)
727 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
728 response
.data
.auth
.nt_status_string
,
729 response
.data
.auth
.nt_status
,
730 response
.data
.auth
.error_string
);
732 return result
== NSS_STATUS_SUCCESS
;
735 /* Authenticate a user with a challenge/response */
737 static BOOL
wbinfo_auth_crap(char *username
)
739 struct winbindd_request request
;
740 struct winbindd_response response
;
747 /* Send off request */
749 ZERO_STRUCT(request
);
750 ZERO_STRUCT(response
);
752 p
= strchr(username
, '%');
756 fstrcpy(pass
, p
+ 1);
759 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
761 request
.data
.auth_crap
.logon_parameters
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
| MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
763 fstrcpy(request
.data
.auth_crap
.user
, name_user
);
765 fstrcpy(request
.data
.auth_crap
.domain
,
768 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
770 if (lp_client_ntlmv2_auth()) {
771 DATA_BLOB server_chal
;
772 DATA_BLOB names_blob
;
774 DATA_BLOB lm_response
;
775 DATA_BLOB nt_response
;
777 server_chal
= data_blob(request
.data
.auth_crap
.chal
, 8);
779 /* Pretend this is a login to 'us', for blob purposes */
780 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
782 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
784 &lm_response
, &nt_response
, NULL
)) {
785 data_blob_free(&names_blob
);
786 data_blob_free(&server_chal
);
789 data_blob_free(&names_blob
);
790 data_blob_free(&server_chal
);
792 memcpy(request
.data
.auth_crap
.nt_resp
, nt_response
.data
,
793 MIN(nt_response
.length
,
794 sizeof(request
.data
.auth_crap
.nt_resp
)));
795 request
.data
.auth_crap
.nt_resp_len
= nt_response
.length
;
797 memcpy(request
.data
.auth_crap
.lm_resp
, lm_response
.data
,
798 MIN(lm_response
.length
,
799 sizeof(request
.data
.auth_crap
.lm_resp
)));
800 request
.data
.auth_crap
.lm_resp_len
= lm_response
.length
;
802 data_blob_free(&nt_response
);
803 data_blob_free(&lm_response
);
806 if (lp_client_lanman_auth()
807 && SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
808 (uchar
*)request
.data
.auth_crap
.lm_resp
)) {
809 request
.data
.auth_crap
.lm_resp_len
= 24;
811 request
.data
.auth_crap
.lm_resp_len
= 0;
813 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
814 (uchar
*)request
.data
.auth_crap
.nt_resp
);
816 request
.data
.auth_crap
.nt_resp_len
= 24;
819 result
= winbindd_request_response(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
821 /* Display response */
823 d_printf("challenge/response password authentication %s\n",
824 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
826 if (response
.data
.auth
.nt_status
)
827 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
828 response
.data
.auth
.nt_status_string
,
829 response
.data
.auth
.nt_status
,
830 response
.data
.auth
.error_string
);
832 return result
== NSS_STATUS_SUCCESS
;
835 /* Authenticate a user with a plaintext password and set a token */
837 static BOOL
wbinfo_klog(char *username
)
839 struct winbindd_request request
;
840 struct winbindd_response response
;
844 /* Send off request */
846 ZERO_STRUCT(request
);
847 ZERO_STRUCT(response
);
849 p
= strchr(username
, '%');
853 fstrcpy(request
.data
.auth
.user
, username
);
854 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
857 fstrcpy(request
.data
.auth
.user
, username
);
858 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
861 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
863 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
865 /* Display response */
867 d_printf("plaintext password authentication %s\n",
868 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
870 if (response
.data
.auth
.nt_status
)
871 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
872 response
.data
.auth
.nt_status_string
,
873 response
.data
.auth
.nt_status
,
874 response
.data
.auth
.error_string
);
876 if (result
!= NSS_STATUS_SUCCESS
)
879 if (response
.extra_data
.data
== NULL
) {
880 d_fprintf(stderr
, "Did not get token data\n");
884 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
885 d_fprintf(stderr
, "Could not set token\n");
889 d_printf("Successfully created AFS token\n");
893 /* Print domain users */
895 static BOOL
print_domain_users(const char *domain
)
897 struct winbindd_request request
;
898 struct winbindd_response response
;
899 const char *extra_data
;
902 /* Send request to winbind daemon */
904 ZERO_STRUCT(request
);
905 ZERO_STRUCT(response
);
908 /* '.' is the special sign for our own domwin */
909 if ( strequal(domain
, ".") )
910 fstrcpy( request
.domain_name
, lp_workgroup() );
912 fstrcpy( request
.domain_name
, domain
);
915 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
919 /* Look through extra data */
921 if (!response
.extra_data
.data
)
924 extra_data
= (const char *)response
.extra_data
.data
;
926 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
927 d_printf("%s\n", name
);
929 SAFE_FREE(response
.extra_data
.data
);
934 /* Print domain groups */
936 static BOOL
print_domain_groups(const char *domain
)
938 struct winbindd_request request
;
939 struct winbindd_response response
;
940 const char *extra_data
;
943 ZERO_STRUCT(request
);
944 ZERO_STRUCT(response
);
947 if ( strequal(domain
, ".") )
948 fstrcpy( request
.domain_name
, lp_workgroup() );
950 fstrcpy( request
.domain_name
, domain
);
953 if (winbindd_request_response(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
957 /* Look through extra data */
959 if (!response
.extra_data
.data
)
962 extra_data
= (const char *)response
.extra_data
.data
;
964 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
965 d_printf("%s\n", name
);
967 SAFE_FREE(response
.extra_data
.data
);
972 /* Set the authorised user for winbindd access in secrets.tdb */
974 static BOOL
wbinfo_set_auth_user(char *username
)
976 const char *password
;
978 fstring user
, domain
;
980 /* Separate into user and password */
982 parse_wbinfo_domain_user(username
, domain
, user
);
984 p
= strchr(user
, '%');
990 char *thepass
= getpass("Password: ");
997 /* Store or remove DOMAIN\username%password in secrets.tdb */
1003 if (!secrets_store(SECRETS_AUTH_USER
, user
,
1004 strlen(user
) + 1)) {
1005 d_fprintf(stderr
, "error storing username\n");
1009 /* We always have a domain name added by the
1010 parse_wbinfo_domain_user() function. */
1012 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
1013 strlen(domain
) + 1)) {
1014 d_fprintf(stderr
, "error storing domain name\n");
1019 secrets_delete(SECRETS_AUTH_USER
);
1020 secrets_delete(SECRETS_AUTH_DOMAIN
);
1025 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
1026 strlen(password
) + 1)) {
1027 d_fprintf(stderr
, "error storing password\n");
1032 secrets_delete(SECRETS_AUTH_PASSWORD
);
1037 static void wbinfo_get_auth_user(void)
1039 char *user
, *domain
, *password
;
1041 /* Lift data from secrets file */
1043 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1045 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1049 SAFE_FREE(password
);
1050 d_printf("No authorised user configured\n");
1054 /* Pretty print authorised user info */
1056 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1057 user
, password
? "%" : "", password
? password
: "");
1061 SAFE_FREE(password
);
1064 static BOOL
wbinfo_ping(void)
1068 result
= winbindd_request_response(WINBINDD_PING
, NULL
, NULL
);
1070 /* Display response */
1072 d_printf("Ping to winbindd %s on fd %d\n",
1073 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
1075 return result
== NSS_STATUS_SUCCESS
;
1081 OPT_SET_AUTH_USER
= 1000,
1091 OPT_LIST_ALL_DOMAINS
,
1095 int main(int argc
, char **argv
)
1100 static char *string_arg
;
1101 static char *opt_domain_name
;
1105 struct poptOption long_options
[] = {
1108 /* longName, shortName, argInfo, argPtr, value, descrip,
1111 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1112 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1113 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1114 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1115 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1116 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1117 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1118 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1119 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1120 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1121 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1122 "Get a new UID out of idmap" },
1123 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1124 "Get a new GID out of idmap" },
1125 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1126 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1127 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1128 { "own-domain", 0, POPT_ARG_NONE
, 0, OPT_LIST_OWN_DOMAIN
, "List own domain" },
1129 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1130 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1131 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1132 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1133 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1134 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1135 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1136 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1137 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1138 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1139 "Get a DC name for a foreign domain", "domainname" },
1140 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1141 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1142 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1143 #ifdef WITH_FAKE_KASERVER
1144 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1147 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1148 /* destroys wbinfo --help output */
1149 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1151 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1156 /* Samba client initialisation */
1159 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
, True
)) {
1160 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1161 dyn_CONFIGFILE
, strerror(errno
));
1172 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1174 /* Parse command line options */
1177 poptPrintHelp(pc
, stderr
, 0);
1181 while((opt
= poptGetNextOpt(pc
)) != -1) {
1182 /* get the generic configuration parameters like --domain */
1185 poptFreeContext(pc
);
1187 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1188 POPT_CONTEXT_KEEP_FIRST
);
1190 while((opt
= poptGetNextOpt(pc
)) != -1) {
1193 if (!print_domain_users(opt_domain_name
)) {
1194 d_fprintf(stderr
, "Error looking up domain users\n");
1199 if (!print_domain_groups(opt_domain_name
)) {
1200 d_fprintf(stderr
, "Error looking up domain groups\n");
1205 if (!wbinfo_lookupsid(string_arg
)) {
1206 d_fprintf(stderr
, "Could not lookup sid %s\n", string_arg
);
1211 if (!wbinfo_lookupname(string_arg
)) {
1212 d_fprintf(stderr
, "Could not lookup name %s\n", string_arg
);
1217 if (!wbinfo_wins_byname(string_arg
)) {
1218 d_fprintf(stderr
, "Could not lookup WINS by name %s\n", string_arg
);
1223 if (!wbinfo_wins_byip(string_arg
)) {
1224 d_fprintf(stderr
, "Could not lookup WINS by IP %s\n", string_arg
);
1229 if (!wbinfo_uid_to_sid(int_arg
)) {
1230 d_fprintf(stderr
, "Could not convert uid %d to sid\n", int_arg
);
1235 if (!wbinfo_gid_to_sid(int_arg
)) {
1236 d_fprintf(stderr
, "Could not convert gid %d to sid\n",
1242 if (!wbinfo_sid_to_uid(string_arg
)) {
1243 d_fprintf(stderr
, "Could not convert sid %s to uid\n",
1249 if (!wbinfo_sid_to_gid(string_arg
)) {
1250 d_fprintf(stderr
, "Could not convert sid %s to gid\n",
1255 case OPT_ALLOCATE_UID
:
1256 if (!wbinfo_allocate_uid()) {
1257 d_fprintf(stderr
, "Could not allocate a uid\n");
1261 case OPT_ALLOCATE_GID
:
1262 if (!wbinfo_allocate_gid()) {
1263 d_fprintf(stderr
, "Could not allocate a gid\n");
1268 if (!wbinfo_check_secret()) {
1269 d_fprintf(stderr
, "Could not check secret\n");
1274 if (!wbinfo_list_domains(False
)) {
1275 d_fprintf(stderr
, "Could not list trusted domains\n");
1280 if (!wbinfo_show_sequence(opt_domain_name
)) {
1281 d_fprintf(stderr
, "Could not show sequence numbers\n");
1286 if (!wbinfo_domain_info(string_arg
)) {
1287 d_fprintf(stderr
, "Could not get domain info\n");
1292 if (!wbinfo_get_userinfo(string_arg
)) {
1293 d_fprintf(stderr
, "Could not get info for user %s\n",
1299 if (!wbinfo_get_usergroups(string_arg
)) {
1300 d_fprintf(stderr
, "Could not get groups for user %s\n",
1306 if (!wbinfo_get_usersids(string_arg
)) {
1307 d_fprintf(stderr
, "Could not get group SIDs for user SID %s\n",
1312 case OPT_USERDOMGROUPS
:
1313 if (!wbinfo_get_userdomgroups(string_arg
)) {
1314 d_fprintf(stderr
, "Could not get user's domain groups "
1315 "for user SID %s\n", string_arg
);
1320 BOOL got_error
= False
;
1322 if (!wbinfo_auth(string_arg
)) {
1323 d_fprintf(stderr
, "Could not authenticate user %s with "
1324 "plaintext password\n", string_arg
);
1328 if (!wbinfo_auth_crap(string_arg
)) {
1329 d_fprintf(stderr
, "Could not authenticate user %s with "
1330 "challenge/response\n", string_arg
);
1339 BOOL got_error
= False
;
1340 uint32 flags
= WBFLAG_PAM_KRB5
|
1341 WBFLAG_PAM_CACHED_LOGIN
|
1342 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
1343 WBFLAG_PAM_INFO3_TEXT
;
1346 const char *arg
[] = { NULL
, NULL
};
1347 const char *cctypes
[] = { "FILE",
1354 arg
[0] = string_arg
;
1356 while (next_token(arg
, tok
, LIST_SEP
, sizeof(tok
))) {
1358 for (i
=0; i
< ARRAY_SIZE(cctypes
); i
++) {
1359 if (!wbinfo_auth_krb5(tok
, cctypes
[i
], flags
)) {
1360 d_fprintf(stderr
, "Could not authenticate user [%s] with "
1361 "Kerberos (ccache: %s)\n", tok
, cctypes
[i
]);
1373 if (!wbinfo_klog(string_arg
)) {
1374 d_fprintf(stderr
, "Could not klog user\n");
1379 if (!wbinfo_ping()) {
1380 d_fprintf(stderr
, "could not ping winbindd!\n");
1384 case OPT_SET_AUTH_USER
:
1385 if (!wbinfo_set_auth_user(string_arg
)) {
1389 case OPT_GET_AUTH_USER
:
1390 wbinfo_get_auth_user();
1393 if (!wbinfo_getdcname(string_arg
)) {
1397 case OPT_SEPARATOR
: {
1398 const char sep
= winbind_separator_int(True
);
1402 d_printf("%c\n", sep
);
1405 case OPT_LIST_ALL_DOMAINS
:
1406 if (!wbinfo_list_domains(True
)) {
1410 case OPT_LIST_OWN_DOMAIN
:
1411 if (!wbinfo_list_own_domain()) {
1415 /* generic configuration options */
1416 case OPT_DOMAIN_NAME
:
1419 d_fprintf(stderr
, "Invalid option\n");
1420 poptPrintHelp(pc
, stderr
, 0);
1430 poptFreeContext(pc
);