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(void)
35 struct winbindd_response response
;
42 ZERO_STRUCT(response
);
44 /* Send off request */
46 if (winbindd_request(WINBINDD_INFO
, NULL
, &response
) !=
48 d_printf("could not obtain winbind separator!\n");
49 /* HACK: (this module should not call lp_ funtions) */
50 return *lp_winbind_separator();
53 sep
= response
.data
.info
.winbind_separator
;
57 d_printf("winbind separator was NULL!\n");
58 /* HACK: (this module should not call lp_ funtions) */
59 sep
= *lp_winbind_separator();
65 static const char *get_winbind_domain(void)
67 struct winbindd_response response
;
68 static fstring winbind_domain
;
70 ZERO_STRUCT(response
);
72 /* Send off request */
74 if (winbindd_request(WINBINDD_DOMAIN_NAME
, NULL
, &response
) !=
76 d_printf("could not obtain winbind domain name!\n");
78 /* HACK: (this module should not call lp_ funtions) */
79 return lp_workgroup();
82 fstrcpy(winbind_domain
, response
.data
.domain_name
);
84 return winbind_domain
;
88 /* Copy of parse_domain_user from winbindd_util.c. Parse a string of the
89 form DOMAIN/user into a domain and a user */
91 static BOOL
parse_wbinfo_domain_user(const char *domuser
, fstring domain
,
95 char *p
= strchr(domuser
,winbind_separator());
98 fstrcpy(user
, domuser
);
99 fstrcpy(domain
, get_winbind_domain());
104 fstrcpy(domain
, domuser
);
105 domain
[PTR_DIFF(p
, domuser
)] = 0;
111 /* List groups a user is a member of */
113 static BOOL
wbinfo_get_usergroups(char *user
)
115 struct winbindd_request request
;
116 struct winbindd_response response
;
120 ZERO_STRUCT(response
);
124 fstrcpy(request
.data
.username
, user
);
126 result
= winbindd_request(WINBINDD_GETGROUPS
, &request
, &response
);
128 if (result
!= NSS_STATUS_SUCCESS
)
131 for (i
= 0; i
< response
.data
.num_entries
; i
++)
132 d_printf("%d\n", (int)((gid_t
*)response
.extra_data
)[i
]);
134 SAFE_FREE(response
.extra_data
);
140 /* List group SIDs a user SID is a member of */
141 static BOOL
wbinfo_get_usersids(char *user_sid
)
143 struct winbindd_request request
;
144 struct winbindd_response response
;
149 ZERO_STRUCT(response
);
152 fstrcpy(request
.data
.sid
, user_sid
);
154 result
= winbindd_request(WINBINDD_GETUSERSIDS
, &request
, &response
);
156 if (result
!= NSS_STATUS_SUCCESS
)
159 s
= response
.extra_data
;
160 for (i
= 0; i
< response
.data
.num_entries
; i
++) {
165 SAFE_FREE(response
.extra_data
);
170 static BOOL
wbinfo_get_userdomgroups(const char *user_sid
)
172 struct winbindd_request request
;
173 struct winbindd_response response
;
176 ZERO_STRUCT(response
);
179 fstrcpy(request
.data
.sid
, user_sid
);
181 result
= winbindd_request(WINBINDD_GETUSERDOMGROUPS
, &request
,
184 if (result
!= NSS_STATUS_SUCCESS
)
187 if (response
.data
.num_entries
!= 0)
188 printf("%s", (char *)response
.extra_data
);
190 SAFE_FREE(response
.extra_data
);
196 /* Convert NetBIOS name to IP */
198 static BOOL
wbinfo_wins_byname(char *name
)
200 struct winbindd_request request
;
201 struct winbindd_response response
;
203 ZERO_STRUCT(request
);
204 ZERO_STRUCT(response
);
208 fstrcpy(request
.data
.winsreq
, name
);
210 if (winbindd_request(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
211 NSS_STATUS_SUCCESS
) {
215 /* Display response */
217 printf("%s\n", response
.data
.winsresp
);
222 /* Convert IP to NetBIOS name */
224 static BOOL
wbinfo_wins_byip(char *ip
)
226 struct winbindd_request request
;
227 struct winbindd_response response
;
229 ZERO_STRUCT(request
);
230 ZERO_STRUCT(response
);
234 fstrcpy(request
.data
.winsreq
, ip
);
236 if (winbindd_request(WINBINDD_WINS_BYIP
, &request
, &response
) !=
237 NSS_STATUS_SUCCESS
) {
241 /* Display response */
243 printf("%s\n", response
.data
.winsresp
);
248 /* List trusted domains */
250 static BOOL
wbinfo_list_domains(void)
252 struct winbindd_response response
;
254 ZERO_STRUCT(response
);
258 if (winbindd_request(WINBINDD_LIST_TRUSTDOM
, NULL
, &response
) !=
262 /* Display response */
264 if (response
.extra_data
) {
265 const char *extra_data
= (char *)response
.extra_data
;
269 while(next_token(&extra_data
, name
, "\n", sizeof(fstring
))) {
270 p
= strchr(name
, '\\');
272 d_printf("Got invalid response: %s\n",
277 d_printf("%s\n", name
);
280 SAFE_FREE(response
.extra_data
);
287 /* show sequence numbers */
288 static BOOL
wbinfo_show_sequence(const char *domain
)
290 struct winbindd_request request
;
291 struct winbindd_response response
;
293 ZERO_STRUCT(response
);
294 ZERO_STRUCT(request
);
297 fstrcpy( request
.domain_name
, domain
);
301 if (winbindd_request(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
305 /* Display response */
307 if (response
.extra_data
) {
308 char *extra_data
= (char *)response
.extra_data
;
309 d_printf("%s", extra_data
);
310 SAFE_FREE(response
.extra_data
);
316 /* Show domain info */
318 static BOOL
wbinfo_domain_info(const char *domain_name
)
320 struct winbindd_request request
;
321 struct winbindd_response response
;
323 ZERO_STRUCT(request
);
324 ZERO_STRUCT(response
);
326 fstrcpy(request
.domain_name
, domain_name
);
330 if (winbindd_request(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
334 /* Display response */
336 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
337 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
339 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
341 d_printf("Active Directory : %s\n",
342 response
.data
.domain_info
.active_directory
? "Yes" : "No");
343 d_printf("Native : %s\n",
344 response
.data
.domain_info
.native_mode
? "Yes" : "No");
346 d_printf("Primary : %s\n",
347 response
.data
.domain_info
.primary
? "Yes" : "No");
349 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
354 /* Get a foreign DC's name */
355 static BOOL
wbinfo_getdcname(const char *domain_name
)
357 struct winbindd_request request
;
358 struct winbindd_response response
;
360 ZERO_STRUCT(request
);
361 ZERO_STRUCT(response
);
363 fstrcpy(request
.domain_name
, domain_name
);
367 if (winbindd_request(WINBINDD_GETDCNAME
, &request
, &response
) !=
368 NSS_STATUS_SUCCESS
) {
369 d_printf("Could not get dc name for %s\n", domain_name
);
373 /* Display response */
375 d_printf("%s\n", response
.data
.dc_name
);
380 /* Check trust account password */
382 static BOOL
wbinfo_check_secret(void)
384 struct winbindd_response response
;
387 ZERO_STRUCT(response
);
389 result
= winbindd_request(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
391 d_printf("checking the trust secret via RPC calls %s\n",
392 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
394 if (result
!= NSS_STATUS_SUCCESS
)
395 d_printf("error code was %s (0x%x)\n",
396 response
.data
.auth
.nt_status_string
,
397 response
.data
.auth
.nt_status
);
399 return result
== NSS_STATUS_SUCCESS
;
402 /* Convert uid to sid */
404 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
406 struct winbindd_request request
;
407 struct winbindd_response response
;
409 ZERO_STRUCT(request
);
410 ZERO_STRUCT(response
);
414 request
.data
.uid
= uid
;
416 if (winbindd_request(WINBINDD_UID_TO_SID
, &request
, &response
) !=
420 /* Display response */
422 d_printf("%s\n", response
.data
.sid
.sid
);
427 /* Convert gid to sid */
429 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
431 struct winbindd_request request
;
432 struct winbindd_response response
;
434 ZERO_STRUCT(request
);
435 ZERO_STRUCT(response
);
439 request
.data
.gid
= gid
;
441 if (winbindd_request(WINBINDD_GID_TO_SID
, &request
, &response
) !=
445 /* Display response */
447 d_printf("%s\n", response
.data
.sid
.sid
);
452 /* Convert sid to uid */
454 static BOOL
wbinfo_sid_to_uid(char *sid
)
456 struct winbindd_request request
;
457 struct winbindd_response response
;
459 ZERO_STRUCT(request
);
460 ZERO_STRUCT(response
);
464 fstrcpy(request
.data
.sid
, sid
);
466 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) !=
470 /* Display response */
472 d_printf("%d\n", (int)response
.data
.uid
);
477 static BOOL
wbinfo_sid_to_gid(char *sid
)
479 struct winbindd_request request
;
480 struct winbindd_response response
;
482 ZERO_STRUCT(request
);
483 ZERO_STRUCT(response
);
487 fstrcpy(request
.data
.sid
, sid
);
489 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) !=
493 /* Display response */
495 d_printf("%d\n", (int)response
.data
.gid
);
500 static BOOL
wbinfo_allocate_rid(void)
504 if (!winbind_allocate_rid(&rid
))
507 d_printf("New rid: %d\n", rid
);
512 /* Convert sid to string */
514 static BOOL
wbinfo_lookupsid(char *sid
)
516 struct winbindd_request request
;
517 struct winbindd_response response
;
519 ZERO_STRUCT(request
);
520 ZERO_STRUCT(response
);
522 /* Send off request */
524 fstrcpy(request
.data
.sid
, sid
);
526 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
530 /* Display response */
532 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
533 winbind_separator(), response
.data
.name
.name
,
534 response
.data
.name
.type
);
539 /* Convert string to sid */
541 static BOOL
wbinfo_lookupname(char *name
)
543 struct winbindd_request request
;
544 struct winbindd_response response
;
546 /* Send off request */
548 ZERO_STRUCT(request
);
549 ZERO_STRUCT(response
);
551 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
552 request
.data
.name
.name
);
554 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
558 /* Display response */
560 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
565 /* Authenticate a user with a plaintext password */
567 static BOOL
wbinfo_auth(char *username
)
569 struct winbindd_request request
;
570 struct winbindd_response response
;
574 /* Send off request */
576 ZERO_STRUCT(request
);
577 ZERO_STRUCT(response
);
579 p
= strchr(username
, '%');
583 fstrcpy(request
.data
.auth
.user
, username
);
584 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
587 fstrcpy(request
.data
.auth
.user
, username
);
589 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
591 /* Display response */
593 d_printf("plaintext password authentication %s\n",
594 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
596 if (response
.data
.auth
.nt_status
)
597 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
598 response
.data
.auth
.nt_status_string
,
599 response
.data
.auth
.nt_status
,
600 response
.data
.auth
.error_string
);
602 return result
== NSS_STATUS_SUCCESS
;
605 /* Authenticate a user with a challenge/response */
607 static BOOL
wbinfo_auth_crap(char *username
)
609 struct winbindd_request request
;
610 struct winbindd_response response
;
617 /* Send off request */
619 ZERO_STRUCT(request
);
620 ZERO_STRUCT(response
);
622 p
= strchr(username
, '%');
626 fstrcpy(pass
, p
+ 1);
629 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
631 fstrcpy(request
.data
.auth_crap
.user
, name_user
);
633 fstrcpy(request
.data
.auth_crap
.domain
,
636 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
638 if (lp_client_ntlmv2_auth()) {
639 DATA_BLOB server_chal
;
640 DATA_BLOB names_blob
;
642 DATA_BLOB lm_response
;
643 DATA_BLOB nt_response
;
645 server_chal
= data_blob(request
.data
.auth_crap
.chal
, 8);
647 /* Pretend this is a login to 'us', for blob purposes */
648 names_blob
= NTLMv2_generate_names_blob(global_myname(), lp_workgroup());
650 if (!SMBNTLMv2encrypt(name_user
, name_domain
, pass
, &server_chal
,
652 &lm_response
, &nt_response
, NULL
)) {
653 data_blob_free(&names_blob
);
654 data_blob_free(&server_chal
);
657 data_blob_free(&names_blob
);
658 data_blob_free(&server_chal
);
660 memcpy(request
.data
.auth_crap
.nt_resp
, nt_response
.data
,
661 MIN(nt_response
.length
,
662 sizeof(request
.data
.auth_crap
.nt_resp
)));
663 request
.data
.auth_crap
.nt_resp_len
= nt_response
.length
;
665 memcpy(request
.data
.auth_crap
.lm_resp
, lm_response
.data
,
666 MIN(lm_response
.length
,
667 sizeof(request
.data
.auth_crap
.lm_resp
)));
668 request
.data
.auth_crap
.lm_resp_len
= lm_response
.length
;
670 data_blob_free(&nt_response
);
671 data_blob_free(&lm_response
);
674 if (lp_client_lanman_auth()
675 && SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
676 (uchar
*)request
.data
.auth_crap
.lm_resp
)) {
677 request
.data
.auth_crap
.lm_resp_len
= 24;
679 request
.data
.auth_crap
.lm_resp_len
= 0;
681 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
682 (uchar
*)request
.data
.auth_crap
.nt_resp
);
684 request
.data
.auth_crap
.nt_resp_len
= 24;
687 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
689 /* Display response */
691 d_printf("challenge/response password authentication %s\n",
692 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
694 if (response
.data
.auth
.nt_status
)
695 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
696 response
.data
.auth
.nt_status_string
,
697 response
.data
.auth
.nt_status
,
698 response
.data
.auth
.error_string
);
700 return result
== NSS_STATUS_SUCCESS
;
703 /* Authenticate a user with a plaintext password and set a token */
705 static BOOL
wbinfo_klog(char *username
)
707 struct winbindd_request request
;
708 struct winbindd_response response
;
712 /* Send off request */
714 ZERO_STRUCT(request
);
715 ZERO_STRUCT(response
);
717 p
= strchr(username
, '%');
721 fstrcpy(request
.data
.auth
.user
, username
);
722 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
725 fstrcpy(request
.data
.auth
.user
, username
);
726 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
729 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
731 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
733 /* Display response */
735 d_printf("plaintext password authentication %s\n",
736 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
738 if (response
.data
.auth
.nt_status
)
739 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
740 response
.data
.auth
.nt_status_string
,
741 response
.data
.auth
.nt_status
,
742 response
.data
.auth
.error_string
);
744 if (result
!= NSS_STATUS_SUCCESS
)
747 if (response
.extra_data
== NULL
) {
748 d_printf("Did not get token data\n");
752 if (!afs_settoken_str((char *)response
.extra_data
)) {
753 d_printf("Could not set token\n");
757 d_printf("Successfully created AFS token\n");
761 /* Print domain users */
763 static BOOL
print_domain_users(const char *domain
)
765 struct winbindd_request request
;
766 struct winbindd_response response
;
767 const char *extra_data
;
770 /* Send request to winbind daemon */
772 ZERO_STRUCT(request
);
773 ZERO_STRUCT(response
);
776 /* '.' is the special sign for our own domwin */
777 if ( strequal(domain
, ".") )
778 fstrcpy( request
.domain_name
, lp_workgroup() );
780 fstrcpy( request
.domain_name
, domain
);
783 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
787 /* Look through extra data */
789 if (!response
.extra_data
)
792 extra_data
= (const char *)response
.extra_data
;
794 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
795 d_printf("%s\n", name
);
797 SAFE_FREE(response
.extra_data
);
802 /* Print domain groups */
804 static BOOL
print_domain_groups(const char *domain
)
806 struct winbindd_request request
;
807 struct winbindd_response response
;
808 const char *extra_data
;
811 ZERO_STRUCT(request
);
812 ZERO_STRUCT(response
);
815 if ( strequal(domain
, ".") )
816 fstrcpy( request
.domain_name
, lp_workgroup() );
818 fstrcpy( request
.domain_name
, domain
);
821 if (winbindd_request(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
825 /* Look through extra data */
827 if (!response
.extra_data
)
830 extra_data
= (const char *)response
.extra_data
;
832 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
833 d_printf("%s\n", name
);
835 SAFE_FREE(response
.extra_data
);
840 /* Set the authorised user for winbindd access in secrets.tdb */
842 static BOOL
wbinfo_set_auth_user(char *username
)
844 const char *password
;
846 fstring user
, domain
;
848 /* Separate into user and password */
850 parse_wbinfo_domain_user(username
, domain
, user
);
852 p
= strchr(user
, '%');
858 char *thepass
= getpass("Password: ");
865 /* Store or remove DOMAIN\username%password in secrets.tdb */
871 if (!secrets_store(SECRETS_AUTH_USER
, user
,
873 d_fprintf(stderr
, "error storing username\n");
877 /* We always have a domain name added by the
878 parse_wbinfo_domain_user() function. */
880 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
881 strlen(domain
) + 1)) {
882 d_fprintf(stderr
, "error storing domain name\n");
887 secrets_delete(SECRETS_AUTH_USER
);
888 secrets_delete(SECRETS_AUTH_DOMAIN
);
893 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
894 strlen(password
) + 1)) {
895 d_fprintf(stderr
, "error storing password\n");
900 secrets_delete(SECRETS_AUTH_PASSWORD
);
905 static void wbinfo_get_auth_user(void)
907 char *user
, *domain
, *password
;
909 /* Lift data from secrets file */
911 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
913 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
918 d_printf("No authorised user configured\n");
922 /* Pretty print authorised user info */
924 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
925 user
, password
? "%" : "", password
? password
: "");
932 static BOOL
wbinfo_ping(void)
936 result
= winbindd_request(WINBINDD_PING
, NULL
, NULL
);
938 /* Display response */
940 d_printf("Ping to winbindd %s on fd %d\n",
941 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
943 return result
== NSS_STATUS_SUCCESS
;
949 OPT_SET_AUTH_USER
= 1000,
958 int main(int argc
, char **argv
)
963 static char *string_arg
;
964 static char *opt_domain_name
;
968 struct poptOption long_options
[] = {
971 /* longName, shortName, argInfo, argPtr, value, descrip,
974 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
975 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
976 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
977 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
978 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
979 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
980 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
981 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
982 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
983 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
984 { "allocate-rid", 'A', POPT_ARG_NONE
, 0, 'A', "Get a new RID out of idmap" },
985 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
986 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
987 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
988 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
989 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
990 { "user-domgroups", 0, POPT_ARG_STRING
, &string_arg
,
991 OPT_USERDOMGROUPS
, "Get user domain groups", "SID" },
992 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
993 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
994 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
995 { "getdcname", 0, POPT_ARG_STRING
, &string_arg
, OPT_GETDCNAME
,
996 "Get a DC name for a foreign domain", "domainname" },
997 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
998 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
999 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1000 #ifdef WITH_FAKE_KASERVER
1001 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1007 /* Samba client initialisation */
1009 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
)) {
1010 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1011 dyn_CONFIGFILE
, strerror(errno
));
1022 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1024 /* Parse command line options */
1027 poptPrintHelp(pc
, stderr
, 0);
1031 while((opt
= poptGetNextOpt(pc
)) != -1) {
1032 /* get the generic configuration parameters like --domain */
1035 poptFreeContext(pc
);
1037 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1038 POPT_CONTEXT_KEEP_FIRST
);
1040 while((opt
= poptGetNextOpt(pc
)) != -1) {
1043 if (!print_domain_users(opt_domain_name
)) {
1044 d_printf("Error looking up domain users\n");
1049 if (!print_domain_groups(opt_domain_name
)) {
1050 d_printf("Error looking up domain groups\n");
1055 if (!wbinfo_lookupsid(string_arg
)) {
1056 d_printf("Could not lookup sid %s\n", string_arg
);
1061 if (!wbinfo_lookupname(string_arg
)) {
1062 d_printf("Could not lookup name %s\n", string_arg
);
1067 if (!wbinfo_wins_byname(string_arg
)) {
1068 d_printf("Could not lookup WINS by name %s\n", string_arg
);
1073 if (!wbinfo_wins_byip(string_arg
)) {
1074 d_printf("Could not lookup WINS by IP %s\n", string_arg
);
1079 if (!wbinfo_uid_to_sid(int_arg
)) {
1080 d_printf("Could not convert uid %d to sid\n", int_arg
);
1085 if (!wbinfo_gid_to_sid(int_arg
)) {
1086 d_printf("Could not convert gid %d to sid\n",
1092 if (!wbinfo_sid_to_uid(string_arg
)) {
1093 d_printf("Could not convert sid %s to uid\n",
1099 if (!wbinfo_sid_to_gid(string_arg
)) {
1100 d_printf("Could not convert sid %s to gid\n",
1106 if (!wbinfo_allocate_rid()) {
1107 d_printf("Could not allocate a RID\n");
1112 if (!wbinfo_check_secret()) {
1113 d_printf("Could not check secret\n");
1118 if (!wbinfo_list_domains()) {
1119 d_printf("Could not list trusted domains\n");
1124 if (!wbinfo_show_sequence(opt_domain_name
)) {
1125 d_printf("Could not show sequence numbers\n");
1130 if (!wbinfo_domain_info(string_arg
)) {
1131 d_printf("Could not get domain info\n");
1136 if (!wbinfo_get_usergroups(string_arg
)) {
1137 d_printf("Could not get groups for user %s\n",
1143 if (!wbinfo_get_usersids(string_arg
)) {
1144 d_printf("Could not get group SIDs for user SID %s\n",
1149 case OPT_USERDOMGROUPS
:
1150 if (!wbinfo_get_userdomgroups(string_arg
)) {
1151 d_printf("Could not get user's domain groups "
1152 "for user SID %s\n", string_arg
);
1157 BOOL got_error
= False
;
1159 if (!wbinfo_auth(string_arg
)) {
1160 d_printf("Could not authenticate user %s with "
1161 "plaintext password\n", string_arg
);
1165 if (!wbinfo_auth_crap(string_arg
)) {
1166 d_printf("Could not authenticate user %s with "
1167 "challenge/response\n", string_arg
);
1176 if (!wbinfo_klog(string_arg
)) {
1177 d_printf("Could not klog user\n");
1182 if (!wbinfo_ping()) {
1183 d_printf("could not ping winbindd!\n");
1187 case OPT_SET_AUTH_USER
:
1188 wbinfo_set_auth_user(string_arg
);
1190 case OPT_GET_AUTH_USER
:
1191 wbinfo_get_auth_user();
1194 wbinfo_getdcname(string_arg
);
1196 /* generic configuration options */
1197 case OPT_DOMAIN_NAME
:
1200 d_fprintf(stderr
, "Invalid option\n");
1201 poptPrintHelp(pc
, stderr
, 0);
1211 poptFreeContext(pc
);