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
);
336 /* show sequence numbers */
337 static BOOL
wbinfo_show_sequence(const char *domain
)
339 struct winbindd_request request
;
340 struct winbindd_response response
;
342 ZERO_STRUCT(response
);
343 ZERO_STRUCT(request
);
346 fstrcpy( request
.domain_name
, domain
);
350 if (winbindd_request_response(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
354 /* Display response */
356 if (response
.extra_data
.data
) {
357 char *extra_data
= (char *)response
.extra_data
.data
;
358 d_printf("%s", extra_data
);
359 SAFE_FREE(response
.extra_data
.data
);
365 /* Show domain info */
367 static BOOL
wbinfo_domain_info(const char *domain_name
)
369 struct winbindd_request request
;
370 struct winbindd_response response
;
372 ZERO_STRUCT(request
);
373 ZERO_STRUCT(response
);
375 fstrcpy(request
.domain_name
, domain_name
);
379 if (winbindd_request_response(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
383 /* Display response */
385 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
386 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
388 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
390 d_printf("Active Directory : %s\n",
391 response
.data
.domain_info
.active_directory
? "Yes" : "No");
392 d_printf("Native : %s\n",
393 response
.data
.domain_info
.native_mode
? "Yes" : "No");
395 d_printf("Primary : %s\n",
396 response
.data
.domain_info
.primary
? "Yes" : "No");
398 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
403 /* Get a foreign DC's name */
404 static BOOL
wbinfo_getdcname(const char *domain_name
)
406 struct winbindd_request request
;
407 struct winbindd_response response
;
409 ZERO_STRUCT(request
);
410 ZERO_STRUCT(response
);
412 fstrcpy(request
.domain_name
, domain_name
);
416 if (winbindd_request_response(WINBINDD_GETDCNAME
, &request
, &response
) !=
417 NSS_STATUS_SUCCESS
) {
418 d_fprintf(stderr
, "Could not get dc name for %s\n", domain_name
);
422 /* Display response */
424 d_printf("%s\n", response
.data
.dc_name
);
429 /* Check trust account password */
431 static BOOL
wbinfo_check_secret(void)
433 struct winbindd_response response
;
436 ZERO_STRUCT(response
);
438 result
= winbindd_request_response(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
440 d_printf("checking the trust secret via RPC calls %s\n",
441 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
443 if (result
!= NSS_STATUS_SUCCESS
)
444 d_fprintf(stderr
, "error code was %s (0x%x)\n",
445 response
.data
.auth
.nt_status_string
,
446 response
.data
.auth
.nt_status
);
448 return result
== NSS_STATUS_SUCCESS
;
451 /* Convert uid to sid */
453 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
455 struct winbindd_request request
;
456 struct winbindd_response response
;
458 ZERO_STRUCT(request
);
459 ZERO_STRUCT(response
);
463 request
.data
.uid
= uid
;
465 if (winbindd_request_response(WINBINDD_UID_TO_SID
, &request
, &response
) !=
469 /* Display response */
471 d_printf("%s\n", response
.data
.sid
.sid
);
476 /* Convert gid to sid */
478 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
480 struct winbindd_request request
;
481 struct winbindd_response response
;
483 ZERO_STRUCT(request
);
484 ZERO_STRUCT(response
);
488 request
.data
.gid
= gid
;
490 if (winbindd_request_response(WINBINDD_GID_TO_SID
, &request
, &response
) !=
494 /* Display response */
496 d_printf("%s\n", response
.data
.sid
.sid
);
501 /* Convert sid to uid */
503 static BOOL
wbinfo_sid_to_uid(char *sid
)
505 struct winbindd_request request
;
506 struct winbindd_response response
;
508 ZERO_STRUCT(request
);
509 ZERO_STRUCT(response
);
513 fstrcpy(request
.data
.sid
, sid
);
515 if (winbindd_request_response(WINBINDD_SID_TO_UID
, &request
, &response
) !=
519 /* Display response */
521 d_printf("%d\n", (int)response
.data
.uid
);
526 static BOOL
wbinfo_sid_to_gid(char *sid
)
528 struct winbindd_request request
;
529 struct winbindd_response response
;
531 ZERO_STRUCT(request
);
532 ZERO_STRUCT(response
);
536 fstrcpy(request
.data
.sid
, sid
);
538 if (winbindd_request_response(WINBINDD_SID_TO_GID
, &request
, &response
) !=
542 /* Display response */
544 d_printf("%d\n", (int)response
.data
.gid
);
549 static BOOL
wbinfo_allocate_uid(void)
553 if (!winbind_allocate_uid(&uid
))
556 d_printf("New uid: %d\n", uid
);
561 static BOOL
wbinfo_allocate_gid(void)
565 if (!winbind_allocate_gid(&gid
))
568 d_printf("New gid: %d\n", gid
);
573 /* Convert sid to string */
575 static BOOL
wbinfo_lookupsid(char *sid
)
577 struct winbindd_request request
;
578 struct winbindd_response response
;
580 ZERO_STRUCT(request
);
581 ZERO_STRUCT(response
);
583 /* Send off request */
585 fstrcpy(request
.data
.sid
, sid
);
587 if (winbindd_request_response(WINBINDD_LOOKUPSID
, &request
, &response
) !=
591 /* Display response */
593 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
594 winbind_separator(), response
.data
.name
.name
,
595 response
.data
.name
.type
);
600 /* Convert string to sid */
602 static BOOL
wbinfo_lookupname(char *name
)
604 struct winbindd_request request
;
605 struct winbindd_response response
;
607 /* Send off request */
609 ZERO_STRUCT(request
);
610 ZERO_STRUCT(response
);
612 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
613 request
.data
.name
.name
);
615 if (winbindd_request_response(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
619 /* Display response */
621 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
626 /* Authenticate a user with a plaintext password */
628 static BOOL
wbinfo_auth_krb5(char *username
, const char *cctype
, uint32 flags
)
630 struct winbindd_request request
;
631 struct winbindd_response response
;
635 /* Send off request */
637 ZERO_STRUCT(request
);
638 ZERO_STRUCT(response
);
640 p
= strchr(username
, '%');
644 fstrcpy(request
.data
.auth
.user
, username
);
645 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
648 fstrcpy(request
.data
.auth
.user
, username
);
650 request
.flags
= flags
;
652 fstrcpy(request
.data
.auth
.krb5_cc_type
, cctype
);
654 request
.data
.auth
.uid
= geteuid();
656 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
658 /* Display response */
660 d_printf("plaintext kerberos password authentication for [%s] %s (requesting cctype: %s)\n",
661 username
, (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", cctype
);
663 if (response
.data
.auth
.nt_status
)
664 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
665 response
.data
.auth
.nt_status_string
,
666 response
.data
.auth
.nt_status
,
667 response
.data
.auth
.error_string
);
669 if (result
== NSS_STATUS_SUCCESS
) {
671 if (request
.flags
& WBFLAG_PAM_INFO3_TEXT
) {
672 if (response
.data
.auth
.info3
.user_flgs
& LOGON_CACHED_ACCOUNT
) {
673 d_printf("user_flgs: LOGON_CACHED_ACCOUNT\n");
677 if (response
.data
.auth
.krb5ccname
[0] != '\0') {
678 d_printf("credentials were put in: %s\n", response
.data
.auth
.krb5ccname
);
680 d_printf("no credentials cached\n");
684 return result
== NSS_STATUS_SUCCESS
;
687 /* Authenticate a user with a plaintext password */
689 static BOOL
wbinfo_auth(char *username
)
691 struct winbindd_request request
;
692 struct winbindd_response response
;
696 /* Send off request */
698 ZERO_STRUCT(request
);
699 ZERO_STRUCT(response
);
701 p
= strchr(username
, '%');
705 fstrcpy(request
.data
.auth
.user
, username
);
706 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
709 fstrcpy(request
.data
.auth
.user
, username
);
711 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
713 /* Display response */
715 d_printf("plaintext password authentication %s\n",
716 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
718 if (response
.data
.auth
.nt_status
)
719 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
720 response
.data
.auth
.nt_status_string
,
721 response
.data
.auth
.nt_status
,
722 response
.data
.auth
.error_string
);
724 return result
== NSS_STATUS_SUCCESS
;
727 /* Authenticate a user with a challenge/response */
729 static BOOL
wbinfo_auth_crap(char *username
)
731 struct winbindd_request request
;
732 struct winbindd_response response
;
739 /* Send off request */
741 ZERO_STRUCT(request
);
742 ZERO_STRUCT(response
);
744 p
= strchr(username
, '%');
748 fstrcpy(pass
, p
+ 1);
751 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
753 request
.data
.auth_crap
.logon_parameters
= MSV1_0_ALLOW_WORKSTATION_TRUST_ACCOUNT
| MSV1_0_ALLOW_SERVER_TRUST_ACCOUNT
;
755 fstrcpy(request
.data
.auth_crap
.user
, name_user
);
757 fstrcpy(request
.data
.auth_crap
.domain
,
760 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
762 if (lp_client_ntlmv2_auth()) {
763 DATA_BLOB server_chal
;
764 DATA_BLOB names_blob
;
766 DATA_BLOB lm_response
;
767 DATA_BLOB nt_response
;
769 server_chal
= data_blob(request
.data
.auth_crap
.chal
, 8);
771 /* Pretend this is a login to 'us', for blob purposes */
772 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
774 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
776 &lm_response
, &nt_response
, NULL
)) {
777 data_blob_free(&names_blob
);
778 data_blob_free(&server_chal
);
781 data_blob_free(&names_blob
);
782 data_blob_free(&server_chal
);
784 memcpy(request
.data
.auth_crap
.nt_resp
, nt_response
.data
,
785 MIN(nt_response
.length
,
786 sizeof(request
.data
.auth_crap
.nt_resp
)));
787 request
.data
.auth_crap
.nt_resp_len
= nt_response
.length
;
789 memcpy(request
.data
.auth_crap
.lm_resp
, lm_response
.data
,
790 MIN(lm_response
.length
,
791 sizeof(request
.data
.auth_crap
.lm_resp
)));
792 request
.data
.auth_crap
.lm_resp_len
= lm_response
.length
;
794 data_blob_free(&nt_response
);
795 data_blob_free(&lm_response
);
798 if (lp_client_lanman_auth()
799 && SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
800 (uchar
*)request
.data
.auth_crap
.lm_resp
)) {
801 request
.data
.auth_crap
.lm_resp_len
= 24;
803 request
.data
.auth_crap
.lm_resp_len
= 0;
805 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
806 (uchar
*)request
.data
.auth_crap
.nt_resp
);
808 request
.data
.auth_crap
.nt_resp_len
= 24;
811 result
= winbindd_request_response(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
813 /* Display response */
815 d_printf("challenge/response password authentication %s\n",
816 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
818 if (response
.data
.auth
.nt_status
)
819 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
820 response
.data
.auth
.nt_status_string
,
821 response
.data
.auth
.nt_status
,
822 response
.data
.auth
.error_string
);
824 return result
== NSS_STATUS_SUCCESS
;
827 /* Authenticate a user with a plaintext password and set a token */
829 static BOOL
wbinfo_klog(char *username
)
831 struct winbindd_request request
;
832 struct winbindd_response response
;
836 /* Send off request */
838 ZERO_STRUCT(request
);
839 ZERO_STRUCT(response
);
841 p
= strchr(username
, '%');
845 fstrcpy(request
.data
.auth
.user
, username
);
846 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
849 fstrcpy(request
.data
.auth
.user
, username
);
850 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
853 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
855 result
= winbindd_request_response(WINBINDD_PAM_AUTH
, &request
, &response
);
857 /* Display response */
859 d_printf("plaintext password authentication %s\n",
860 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
862 if (response
.data
.auth
.nt_status
)
863 d_fprintf(stderr
, "error code was %s (0x%x)\nerror messsage was: %s\n",
864 response
.data
.auth
.nt_status_string
,
865 response
.data
.auth
.nt_status
,
866 response
.data
.auth
.error_string
);
868 if (result
!= NSS_STATUS_SUCCESS
)
871 if (response
.extra_data
.data
== NULL
) {
872 d_fprintf(stderr
, "Did not get token data\n");
876 if (!afs_settoken_str((char *)response
.extra_data
.data
)) {
877 d_fprintf(stderr
, "Could not set token\n");
881 d_printf("Successfully created AFS token\n");
885 /* Print domain users */
887 static BOOL
print_domain_users(const char *domain
)
889 struct winbindd_request request
;
890 struct winbindd_response response
;
891 const char *extra_data
;
894 /* Send request to winbind daemon */
896 ZERO_STRUCT(request
);
897 ZERO_STRUCT(response
);
900 /* '.' is the special sign for our own domwin */
901 if ( strequal(domain
, ".") )
902 fstrcpy( request
.domain_name
, lp_workgroup() );
904 fstrcpy( request
.domain_name
, domain
);
907 if (winbindd_request_response(WINBINDD_LIST_USERS
, &request
, &response
) !=
911 /* Look through extra data */
913 if (!response
.extra_data
.data
)
916 extra_data
= (const char *)response
.extra_data
.data
;
918 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
919 d_printf("%s\n", name
);
921 SAFE_FREE(response
.extra_data
.data
);
926 /* Print domain groups */
928 static BOOL
print_domain_groups(const char *domain
)
930 struct winbindd_request request
;
931 struct winbindd_response response
;
932 const char *extra_data
;
935 ZERO_STRUCT(request
);
936 ZERO_STRUCT(response
);
939 if ( strequal(domain
, ".") )
940 fstrcpy( request
.domain_name
, lp_workgroup() );
942 fstrcpy( request
.domain_name
, domain
);
945 if (winbindd_request_response(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
949 /* Look through extra data */
951 if (!response
.extra_data
.data
)
954 extra_data
= (const char *)response
.extra_data
.data
;
956 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
957 d_printf("%s\n", name
);
959 SAFE_FREE(response
.extra_data
.data
);
964 /* Set the authorised user for winbindd access in secrets.tdb */
966 static BOOL
wbinfo_set_auth_user(char *username
)
968 const char *password
;
970 fstring user
, domain
;
972 /* Separate into user and password */
974 parse_wbinfo_domain_user(username
, domain
, user
);
976 p
= strchr(user
, '%');
982 char *thepass
= getpass("Password: ");
989 /* Store or remove DOMAIN\username%password in secrets.tdb */
995 if (!secrets_store(SECRETS_AUTH_USER
, user
,
997 d_fprintf(stderr
, "error storing username\n");
1001 /* We always have a domain name added by the
1002 parse_wbinfo_domain_user() function. */
1004 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
1005 strlen(domain
) + 1)) {
1006 d_fprintf(stderr
, "error storing domain name\n");
1011 secrets_delete(SECRETS_AUTH_USER
);
1012 secrets_delete(SECRETS_AUTH_DOMAIN
);
1017 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
1018 strlen(password
) + 1)) {
1019 d_fprintf(stderr
, "error storing password\n");
1024 secrets_delete(SECRETS_AUTH_PASSWORD
);
1029 static void wbinfo_get_auth_user(void)
1031 char *user
, *domain
, *password
;
1033 /* Lift data from secrets file */
1035 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1037 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1041 SAFE_FREE(password
);
1042 d_printf("No authorised user configured\n");
1046 /* Pretty print authorised user info */
1048 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1049 user
, password
? "%" : "", password
? password
: "");
1053 SAFE_FREE(password
);
1056 static BOOL
wbinfo_ping(void)
1060 result
= winbindd_request_response(WINBINDD_PING
, NULL
, NULL
);
1062 /* Display response */
1064 d_printf("Ping to winbindd %s on fd %d\n",
1065 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
1067 return result
== NSS_STATUS_SUCCESS
;
1073 OPT_SET_AUTH_USER
= 1000,
1083 OPT_LIST_ALL_DOMAINS
1086 int main(int argc
, char **argv
)
1091 static char *string_arg
;
1092 static char *opt_domain_name
;
1096 struct poptOption long_options
[] = {
1099 /* longName, shortName, argInfo, argPtr, value, descrip,
1102 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1103 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1104 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1105 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1106 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1107 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1108 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1109 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1110 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1111 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1112 { "allocate-uid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_UID
,
1113 "Get a new UID out of idmap" },
1114 { "allocate-gid", 0, POPT_ARG_NONE
, 0, OPT_ALLOCATE_GID
,
1115 "Get a new GID out of idmap" },
1116 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1117 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1118 { "all-domains", 0, POPT_ARG_NONE
, 0, OPT_LIST_ALL_DOMAINS
, "List all domains (trusted and own domain)" },
1119 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1120 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1121 { "user-info", 'i', POPT_ARG_STRING
, &string_arg
, 'i', "Get user info", "USER" },
1122 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1123 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
1124 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
1125 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1126 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1127 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1128 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
1129 "Get a DC name for a foreign domain", "domainname" },
1130 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1131 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1132 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1133 #ifdef WITH_FAKE_KASERVER
1134 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1137 { "krb5auth", 'K', POPT_ARG_STRING
, &string_arg
, 'K', "authenticate user using Kerberos", "user%password" },
1138 /* destroys wbinfo --help output */
1139 /* "user%password,DOM\\user%password,user@EXAMPLE.COM,EXAMPLE.COM\\user%password" }, */
1141 { "separator", 0, POPT_ARG_NONE
, 0, OPT_SEPARATOR
, "Get the active winbind separator", NULL
},
1146 /* Samba client initialisation */
1149 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
, True
)) {
1150 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1151 dyn_CONFIGFILE
, strerror(errno
));
1162 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1164 /* Parse command line options */
1167 poptPrintHelp(pc
, stderr
, 0);
1171 while((opt
= poptGetNextOpt(pc
)) != -1) {
1172 /* get the generic configuration parameters like --domain */
1175 poptFreeContext(pc
);
1177 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1178 POPT_CONTEXT_KEEP_FIRST
);
1180 while((opt
= poptGetNextOpt(pc
)) != -1) {
1183 if (!print_domain_users(opt_domain_name
)) {
1184 d_fprintf(stderr
, "Error looking up domain users\n");
1189 if (!print_domain_groups(opt_domain_name
)) {
1190 d_fprintf(stderr
, "Error looking up domain groups\n");
1195 if (!wbinfo_lookupsid(string_arg
)) {
1196 d_fprintf(stderr
, "Could not lookup sid %s\n", string_arg
);
1201 if (!wbinfo_lookupname(string_arg
)) {
1202 d_fprintf(stderr
, "Could not lookup name %s\n", string_arg
);
1207 if (!wbinfo_wins_byname(string_arg
)) {
1208 d_fprintf(stderr
, "Could not lookup WINS by name %s\n", string_arg
);
1213 if (!wbinfo_wins_byip(string_arg
)) {
1214 d_fprintf(stderr
, "Could not lookup WINS by IP %s\n", string_arg
);
1219 if (!wbinfo_uid_to_sid(int_arg
)) {
1220 d_fprintf(stderr
, "Could not convert uid %d to sid\n", int_arg
);
1225 if (!wbinfo_gid_to_sid(int_arg
)) {
1226 d_fprintf(stderr
, "Could not convert gid %d to sid\n",
1232 if (!wbinfo_sid_to_uid(string_arg
)) {
1233 d_fprintf(stderr
, "Could not convert sid %s to uid\n",
1239 if (!wbinfo_sid_to_gid(string_arg
)) {
1240 d_fprintf(stderr
, "Could not convert sid %s to gid\n",
1245 case OPT_ALLOCATE_UID
:
1246 if (!wbinfo_allocate_uid()) {
1247 d_fprintf(stderr
, "Could not allocate a uid\n");
1251 case OPT_ALLOCATE_GID
:
1252 if (!wbinfo_allocate_gid()) {
1253 d_fprintf(stderr
, "Could not allocate a gid\n");
1258 if (!wbinfo_check_secret()) {
1259 d_fprintf(stderr
, "Could not check secret\n");
1264 if (!wbinfo_list_domains(False
)) {
1265 d_fprintf(stderr
, "Could not list trusted domains\n");
1270 if (!wbinfo_show_sequence(opt_domain_name
)) {
1271 d_fprintf(stderr
, "Could not show sequence numbers\n");
1276 if (!wbinfo_domain_info(string_arg
)) {
1277 d_fprintf(stderr
, "Could not get domain info\n");
1282 if (!wbinfo_get_userinfo(string_arg
)) {
1283 d_fprintf(stderr
, "Could not get info for user %s\n",
1289 if (!wbinfo_get_usergroups(string_arg
)) {
1290 d_fprintf(stderr
, "Could not get groups for user %s\n",
1296 if (!wbinfo_get_usersids(string_arg
)) {
1297 d_fprintf(stderr
, "Could not get group SIDs for user SID %s\n",
1302 case OPT_USERDOMGROUPS
:
1303 if (!wbinfo_get_userdomgroups(string_arg
)) {
1304 d_fprintf(stderr
, "Could not get user's domain groups "
1305 "for user SID %s\n", string_arg
);
1310 BOOL got_error
= False
;
1312 if (!wbinfo_auth(string_arg
)) {
1313 d_fprintf(stderr
, "Could not authenticate user %s with "
1314 "plaintext password\n", string_arg
);
1318 if (!wbinfo_auth_crap(string_arg
)) {
1319 d_fprintf(stderr
, "Could not authenticate user %s with "
1320 "challenge/response\n", string_arg
);
1329 BOOL got_error
= False
;
1330 uint32 flags
= WBFLAG_PAM_KRB5
|
1331 WBFLAG_PAM_CACHED_LOGIN
|
1332 WBFLAG_PAM_FALLBACK_AFTER_KRB5
|
1333 WBFLAG_PAM_INFO3_TEXT
;
1336 const char *arg
[] = { NULL
, NULL
};
1337 const char *cctypes
[] = { "FILE",
1344 arg
[0] = string_arg
;
1346 while (next_token(arg
, tok
, LIST_SEP
, sizeof(tok
))) {
1348 for (i
=0; i
< ARRAY_SIZE(cctypes
); i
++) {
1349 if (!wbinfo_auth_krb5(tok
, cctypes
[i
], flags
)) {
1350 d_fprintf(stderr
, "Could not authenticate user [%s] with "
1351 "Kerberos (ccache: %s)\n", tok
, cctypes
[i
]);
1363 if (!wbinfo_klog(string_arg
)) {
1364 d_fprintf(stderr
, "Could not klog user\n");
1369 if (!wbinfo_ping()) {
1370 d_fprintf(stderr
, "could not ping winbindd!\n");
1374 case OPT_SET_AUTH_USER
:
1375 if (!wbinfo_set_auth_user(string_arg
)) {
1379 case OPT_GET_AUTH_USER
:
1380 wbinfo_get_auth_user();
1383 if (!wbinfo_getdcname(string_arg
)) {
1387 case OPT_SEPARATOR
: {
1388 const char sep
= winbind_separator_int(True
);
1392 d_printf("%c\n", sep
);
1395 case OPT_LIST_ALL_DOMAINS
:
1396 if (!wbinfo_list_domains(True
)) {
1399 /* generic configuration options */
1400 case OPT_DOMAIN_NAME
:
1403 d_fprintf(stderr
, "Invalid option\n");
1404 poptPrintHelp(pc
, stderr
, 0);
1414 poptFreeContext(pc
);