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 /* Convert NetBIOS name to IP */
172 static BOOL
wbinfo_wins_byname(char *name
)
174 struct winbindd_request request
;
175 struct winbindd_response response
;
177 ZERO_STRUCT(request
);
178 ZERO_STRUCT(response
);
182 fstrcpy(request
.data
.winsreq
, name
);
184 if (winbindd_request(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
185 NSS_STATUS_SUCCESS
) {
189 /* Display response */
191 printf("%s\n", response
.data
.winsresp
);
196 /* Convert IP to NetBIOS name */
198 static BOOL
wbinfo_wins_byip(char *ip
)
200 struct winbindd_request request
;
201 struct winbindd_response response
;
203 ZERO_STRUCT(request
);
204 ZERO_STRUCT(response
);
208 fstrcpy(request
.data
.winsreq
, ip
);
210 if (winbindd_request(WINBINDD_WINS_BYIP
, &request
, &response
) !=
211 NSS_STATUS_SUCCESS
) {
215 /* Display response */
217 printf("%s\n", response
.data
.winsresp
);
222 /* List trusted domains */
224 static BOOL
wbinfo_list_domains(void)
226 struct winbindd_response response
;
229 ZERO_STRUCT(response
);
233 if (winbindd_request(WINBINDD_LIST_TRUSTDOM
, NULL
, &response
) !=
237 /* Display response */
239 if (response
.extra_data
) {
240 const char *extra_data
= (char *)response
.extra_data
;
242 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
243 d_printf("%s\n", name
);
245 SAFE_FREE(response
.extra_data
);
252 /* show sequence numbers */
253 static BOOL
wbinfo_show_sequence(const char *domain
)
255 struct winbindd_request request
;
256 struct winbindd_response response
;
258 ZERO_STRUCT(response
);
259 ZERO_STRUCT(request
);
262 fstrcpy( request
.domain_name
, domain
);
266 if (winbindd_request(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
270 /* Display response */
272 if (response
.extra_data
) {
273 char *extra_data
= (char *)response
.extra_data
;
274 d_printf("%s", extra_data
);
275 SAFE_FREE(response
.extra_data
);
281 /* Show domain info */
283 static BOOL
wbinfo_domain_info(const char *domain_name
)
285 struct winbindd_request request
;
286 struct winbindd_response response
;
288 ZERO_STRUCT(request
);
289 ZERO_STRUCT(response
);
291 fstrcpy(request
.domain_name
, domain_name
);
295 if (winbindd_request(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
299 /* Display response */
301 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
302 d_printf("Alt_Name : %s\n", response
.data
.domain_info
.alt_name
);
304 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
306 d_printf("Active Directory : %s\n",
307 response
.data
.domain_info
.active_directory
? "Yes" : "No");
308 d_printf("Native : %s\n",
309 response
.data
.domain_info
.native_mode
? "Yes" : "No");
311 d_printf("Primary : %s\n",
312 response
.data
.domain_info
.primary
? "Yes" : "No");
314 d_printf("Sequence : %d\n", response
.data
.domain_info
.sequence_number
);
319 /* Check trust account password */
321 static BOOL
wbinfo_check_secret(void)
323 struct winbindd_response response
;
326 ZERO_STRUCT(response
);
328 result
= winbindd_request(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
330 d_printf("checking the trust secret via RPC calls %s\n",
331 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
333 if (result
!= NSS_STATUS_SUCCESS
)
334 d_printf("error code was %s (0x%x)\n",
335 response
.data
.auth
.nt_status_string
,
336 response
.data
.auth
.nt_status
);
338 return result
== NSS_STATUS_SUCCESS
;
341 /* Convert uid to sid */
343 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
345 struct winbindd_request request
;
346 struct winbindd_response response
;
348 ZERO_STRUCT(request
);
349 ZERO_STRUCT(response
);
353 request
.data
.uid
= uid
;
355 if (winbindd_request(WINBINDD_UID_TO_SID
, &request
, &response
) !=
359 /* Display response */
361 d_printf("%s\n", response
.data
.sid
.sid
);
366 /* Convert gid to sid */
368 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
370 struct winbindd_request request
;
371 struct winbindd_response response
;
373 ZERO_STRUCT(request
);
374 ZERO_STRUCT(response
);
378 request
.data
.gid
= gid
;
380 if (winbindd_request(WINBINDD_GID_TO_SID
, &request
, &response
) !=
384 /* Display response */
386 d_printf("%s\n", response
.data
.sid
.sid
);
391 /* Convert sid to uid */
393 static BOOL
wbinfo_sid_to_uid(char *sid
)
395 struct winbindd_request request
;
396 struct winbindd_response response
;
398 ZERO_STRUCT(request
);
399 ZERO_STRUCT(response
);
401 /* First see whether the SID is actually a user -- otherwise
402 * winbind might end up a uid number for a group SID and this
403 * is asking for trouble later. */
405 fstrcpy(request
.data
.sid
, sid
);
407 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
408 NSS_STATUS_SUCCESS
) {
409 d_printf("Could not lookup sid %s\n", sid
);
413 if (response
.data
.name
.type
!= SID_NAME_USER
) {
414 d_printf("SID is of type %s\n",
415 sid_type_lookup(response
.data
.name
.type
));
419 ZERO_STRUCT(request
);
420 ZERO_STRUCT(response
);
424 fstrcpy(request
.data
.sid
, sid
);
426 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) !=
430 /* Display response */
432 d_printf("%d\n", (int)response
.data
.uid
);
437 static BOOL
wbinfo_sid_to_gid(char *sid
)
439 struct winbindd_request request
;
440 struct winbindd_response response
;
442 ZERO_STRUCT(request
);
443 ZERO_STRUCT(response
);
445 /* First see whether the SID is actually a group -- otherwise
446 * winbind might end up a gid number for a user SID and this
447 * is asking for trouble later. */
449 fstrcpy(request
.data
.sid
, sid
);
451 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
452 NSS_STATUS_SUCCESS
) {
453 d_printf("Could not lookup sid %s\n", sid
);
457 if ((response
.data
.name
.type
!= SID_NAME_DOM_GRP
) &&
458 (response
.data
.name
.type
!= SID_NAME_ALIAS
) &&
459 (response
.data
.name
.type
!= SID_NAME_WKN_GRP
)) {
460 d_printf("SID is of type %s\n",
461 sid_type_lookup(response
.data
.name
.type
));
467 fstrcpy(request
.data
.sid
, sid
);
469 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) !=
473 /* Display response */
475 d_printf("%d\n", (int)response
.data
.gid
);
480 static BOOL
wbinfo_allocate_rid(void)
484 if (!winbind_allocate_rid(&rid
))
487 d_printf("New rid: %d\n", rid
);
492 /* Convert sid to string */
494 static BOOL
wbinfo_lookupsid(char *sid
)
496 struct winbindd_request request
;
497 struct winbindd_response response
;
499 ZERO_STRUCT(request
);
500 ZERO_STRUCT(response
);
502 /* Send off request */
504 fstrcpy(request
.data
.sid
, sid
);
506 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
510 /* Display response */
512 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
513 winbind_separator(), response
.data
.name
.name
,
514 response
.data
.name
.type
);
519 /* Convert string to sid */
521 static BOOL
wbinfo_lookupname(char *name
)
523 struct winbindd_request request
;
524 struct winbindd_response response
;
526 /* Send off request */
528 ZERO_STRUCT(request
);
529 ZERO_STRUCT(response
);
531 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
532 request
.data
.name
.name
);
534 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
538 /* Display response */
540 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
545 /* Authenticate a user with a plaintext password */
547 static BOOL
wbinfo_auth(char *username
)
549 struct winbindd_request request
;
550 struct winbindd_response response
;
554 /* Send off request */
556 ZERO_STRUCT(request
);
557 ZERO_STRUCT(response
);
559 p
= strchr(username
, '%');
563 fstrcpy(request
.data
.auth
.user
, username
);
564 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
567 fstrcpy(request
.data
.auth
.user
, username
);
569 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
571 /* Display response */
573 d_printf("plaintext password authentication %s\n",
574 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
576 if (response
.data
.auth
.nt_status
)
577 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
578 response
.data
.auth
.nt_status_string
,
579 response
.data
.auth
.nt_status
,
580 response
.data
.auth
.error_string
);
582 return result
== NSS_STATUS_SUCCESS
;
585 /* Authenticate a user with a challenge/response */
587 static BOOL
wbinfo_auth_crap(char *username
)
589 struct winbindd_request request
;
590 struct winbindd_response response
;
597 /* Send off request */
599 ZERO_STRUCT(request
);
600 ZERO_STRUCT(response
);
602 p
= strchr(username
, '%');
606 fstrcpy(pass
, p
+ 1);
609 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
611 if (push_utf8_fstring(request
.data
.auth_crap
.user
, name_user
) == -1) {
612 d_printf("unable to create utf8 string for '%s'\n",
617 if (push_utf8_fstring(request
.data
.auth_crap
.domain
,
618 name_domain
) == -1) {
619 d_printf("unable to create utf8 string for '%s'\n",
624 generate_random_buffer(request
.data
.auth_crap
.chal
, 8);
626 SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
627 (uchar
*)request
.data
.auth_crap
.lm_resp
);
628 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
629 (uchar
*)request
.data
.auth_crap
.nt_resp
);
631 request
.data
.auth_crap
.lm_resp_len
= 24;
632 request
.data
.auth_crap
.nt_resp_len
= 24;
634 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
636 /* Display response */
638 d_printf("challenge/response password authentication %s\n",
639 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
641 if (response
.data
.auth
.nt_status
)
642 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
643 response
.data
.auth
.nt_status_string
,
644 response
.data
.auth
.nt_status
,
645 response
.data
.auth
.error_string
);
647 return result
== NSS_STATUS_SUCCESS
;
650 /* Authenticate a user with a plaintext password and set a token */
652 static BOOL
wbinfo_klog(char *username
)
654 struct winbindd_request request
;
655 struct winbindd_response response
;
659 /* Send off request */
661 ZERO_STRUCT(request
);
662 ZERO_STRUCT(response
);
664 p
= strchr(username
, '%');
668 fstrcpy(request
.data
.auth
.user
, username
);
669 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
672 fstrcpy(request
.data
.auth
.user
, username
);
673 fstrcpy(request
.data
.auth
.pass
, getpass("Password: "));
676 request
.flags
|= WBFLAG_PAM_AFS_TOKEN
;
678 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
680 /* Display response */
682 d_printf("plaintext password authentication %s\n",
683 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
685 if (response
.data
.auth
.nt_status
)
686 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
687 response
.data
.auth
.nt_status_string
,
688 response
.data
.auth
.nt_status
,
689 response
.data
.auth
.error_string
);
691 if (result
!= NSS_STATUS_SUCCESS
)
694 if (response
.extra_data
== NULL
) {
695 d_printf("Did not get token data\n");
699 if (!afs_settoken_str((char *)response
.extra_data
)) {
700 d_printf("Could not set token\n");
704 d_printf("Successfully created AFS token\n");
708 /******************************************************************
709 create a winbindd user
710 ******************************************************************/
712 static BOOL
wbinfo_create_user(char *username
)
714 struct winbindd_request request
;
715 struct winbindd_response response
;
718 /* Send off request */
720 ZERO_STRUCT(request
);
721 ZERO_STRUCT(response
);
723 request
.flags
= WBFLAG_ALLOCATE_RID
;
724 fstrcpy(request
.data
.acct_mgt
.username
, username
);
726 result
= winbindd_request(WINBINDD_CREATE_USER
, &request
, &response
);
728 if ( result
== NSS_STATUS_SUCCESS
)
729 d_printf("New RID is %d\n", response
.data
.rid
);
731 return result
== NSS_STATUS_SUCCESS
;
734 /******************************************************************
735 remove a winbindd user
736 ******************************************************************/
738 static BOOL
wbinfo_delete_user(char *username
)
740 struct winbindd_request request
;
741 struct winbindd_response response
;
744 /* Send off request */
746 ZERO_STRUCT(request
);
747 ZERO_STRUCT(response
);
749 fstrcpy(request
.data
.acct_mgt
.username
, username
);
751 result
= winbindd_request(WINBINDD_DELETE_USER
, &request
, &response
);
753 return result
== NSS_STATUS_SUCCESS
;
756 /******************************************************************
757 create a winbindd group
758 ******************************************************************/
760 static BOOL
wbinfo_create_group(char *groupname
)
762 struct winbindd_request request
;
763 struct winbindd_response response
;
766 /* Send off request */
768 ZERO_STRUCT(request
);
769 ZERO_STRUCT(response
);
771 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
773 result
= winbindd_request(WINBINDD_CREATE_GROUP
, &request
, &response
);
775 return result
== NSS_STATUS_SUCCESS
;
778 /******************************************************************
779 remove a winbindd group
780 ******************************************************************/
782 static BOOL
wbinfo_delete_group(char *groupname
)
784 struct winbindd_request request
;
785 struct winbindd_response response
;
788 /* Send off request */
790 ZERO_STRUCT(request
);
791 ZERO_STRUCT(response
);
793 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
795 result
= winbindd_request(WINBINDD_DELETE_GROUP
, &request
, &response
);
797 return result
== NSS_STATUS_SUCCESS
;
800 /******************************************************************
801 parse a string in the form user:group
802 ******************************************************************/
804 static BOOL
parse_user_group( const char *string
, fstring user
, fstring group
)
811 if ( !(p
= strchr( string
, ':' )) )
817 fstrcpy( user
, string
);
823 /******************************************************************
824 add a user to a winbindd group
825 ******************************************************************/
827 static BOOL
wbinfo_add_user_to_group(char *string
)
829 struct winbindd_request request
;
830 struct winbindd_response response
;
833 /* Send off request */
835 ZERO_STRUCT(request
);
836 ZERO_STRUCT(response
);
838 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
839 request
.data
.acct_mgt
.groupname
))
841 d_printf("Can't parse user:group from %s\n", string
);
845 result
= winbindd_request(WINBINDD_ADD_USER_TO_GROUP
, &request
, &response
);
847 return result
== NSS_STATUS_SUCCESS
;
850 /******************************************************************
851 remove a user from a winbindd group
852 ******************************************************************/
854 static BOOL
wbinfo_remove_user_from_group(char *string
)
856 struct winbindd_request request
;
857 struct winbindd_response response
;
860 /* Send off request */
862 ZERO_STRUCT(request
);
863 ZERO_STRUCT(response
);
865 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
866 request
.data
.acct_mgt
.groupname
))
868 d_printf("Can't parse user:group from %s\n", string
);
872 result
= winbindd_request(WINBINDD_REMOVE_USER_FROM_GROUP
, &request
, &response
);
874 return result
== NSS_STATUS_SUCCESS
;
877 /* Print domain users */
879 static BOOL
print_domain_users(const char *domain
)
881 struct winbindd_request request
;
882 struct winbindd_response response
;
883 const char *extra_data
;
886 /* Send request to winbind daemon */
888 ZERO_STRUCT(request
);
889 ZERO_STRUCT(response
);
892 /* '.' is the special sign for our own domwin */
893 if ( strequal(domain
, ".") )
894 fstrcpy( request
.domain_name
, lp_workgroup() );
896 fstrcpy( request
.domain_name
, domain
);
899 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
903 /* Look through extra data */
905 if (!response
.extra_data
)
908 extra_data
= (const char *)response
.extra_data
;
910 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
911 d_printf("%s\n", name
);
913 SAFE_FREE(response
.extra_data
);
918 /* Print domain groups */
920 static BOOL
print_domain_groups(const char *domain
)
922 struct winbindd_request request
;
923 struct winbindd_response response
;
924 const char *extra_data
;
927 ZERO_STRUCT(request
);
928 ZERO_STRUCT(response
);
931 if ( strequal(domain
, ".") )
932 fstrcpy( request
.domain_name
, lp_workgroup() );
934 fstrcpy( request
.domain_name
, domain
);
937 if (winbindd_request(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
941 /* Look through extra data */
943 if (!response
.extra_data
)
946 extra_data
= (const char *)response
.extra_data
;
948 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
949 d_printf("%s\n", name
);
951 SAFE_FREE(response
.extra_data
);
956 /* Set the authorised user for winbindd access in secrets.tdb */
958 static BOOL
wbinfo_set_auth_user(char *username
)
960 const char *password
;
962 fstring user
, domain
;
964 /* Separate into user and password */
966 parse_wbinfo_domain_user(username
, domain
, user
);
968 p
= strchr(user
, '%');
974 char *thepass
= getpass("Password: ");
981 /* Store or remove DOMAIN\username%password in secrets.tdb */
987 if (!secrets_store(SECRETS_AUTH_USER
, user
,
989 d_fprintf(stderr
, "error storing username\n");
993 /* We always have a domain name added by the
994 parse_wbinfo_domain_user() function. */
996 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
997 strlen(domain
) + 1)) {
998 d_fprintf(stderr
, "error storing domain name\n");
1003 secrets_delete(SECRETS_AUTH_USER
);
1004 secrets_delete(SECRETS_AUTH_DOMAIN
);
1009 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
1010 strlen(password
) + 1)) {
1011 d_fprintf(stderr
, "error storing password\n");
1016 secrets_delete(SECRETS_AUTH_PASSWORD
);
1021 static void wbinfo_get_auth_user(void)
1023 char *user
, *domain
, *password
;
1025 /* Lift data from secrets file */
1027 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
1029 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
1033 SAFE_FREE(password
);
1034 d_printf("No authorised user configured\n");
1038 /* Pretty print authorised user info */
1040 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
1041 user
, password
? "%" : "", password
? password
: "");
1045 SAFE_FREE(password
);
1048 static BOOL
wbinfo_ping(void)
1052 result
= winbindd_request(WINBINDD_PING
, NULL
, NULL
);
1054 /* Display response */
1056 d_printf("Ping to winbindd %s on fd %d\n",
1057 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
1059 return result
== NSS_STATUS_SUCCESS
;
1065 OPT_SET_AUTH_USER
= 1000,
1072 int main(int argc
, char **argv
)
1077 static char *string_arg
;
1078 static char *opt_domain_name
;
1082 struct poptOption long_options
[] = {
1085 /* longName, shortName, argInfo, argPtr, value, descrip,
1088 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
1089 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
1090 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
1091 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
1092 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
1093 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
1094 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
1095 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
1096 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
1097 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
1098 { "allocate-rid", 'A', POPT_ARG_NONE
, 0, 'A', "Get a new RID out of idmap" },
1099 { "create-user", 'c', POPT_ARG_STRING
, &string_arg
, 'c', "Create a local user account", "name" },
1100 { "delete-user", 'x', POPT_ARG_STRING
, &string_arg
, 'x', "Delete a local user account", "name" },
1101 { "create-group", 'C', POPT_ARG_STRING
, &string_arg
, 'C', "Create a local group", "name" },
1102 { "delete-group", 'X', POPT_ARG_STRING
, &string_arg
, 'X', "Delete a local group", "name" },
1103 { "add-to-group", 'o', POPT_ARG_STRING
, &string_arg
, 'o', "Add user to group", "user:group" },
1104 { "del-from-group", 'O', POPT_ARG_STRING
, &string_arg
, 'O', "Remove user from group", "user:group" },
1105 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
1106 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
1107 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
1108 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D', "Show most of the info we have about the domain" },
1109 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
1110 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
1111 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1112 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1113 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1114 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1115 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1116 #ifdef WITH_FAKE_KASERVER
1117 { "klog", 'k', POPT_ARG_STRING
, &string_arg
, 'k', "set an AFS token from winbind", "user%password" },
1123 /* Samba client initialisation */
1125 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
)) {
1126 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1127 dyn_CONFIGFILE
, strerror(errno
));
1138 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1140 /* Parse command line options */
1143 poptPrintHelp(pc
, stderr
, 0);
1147 while((opt
= poptGetNextOpt(pc
)) != -1) {
1148 /* get the generic configuration parameters like --domain */
1151 poptFreeContext(pc
);
1153 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1154 POPT_CONTEXT_KEEP_FIRST
);
1156 while((opt
= poptGetNextOpt(pc
)) != -1) {
1159 if (!print_domain_users(opt_domain_name
)) {
1160 d_printf("Error looking up domain users\n");
1165 if (!print_domain_groups(opt_domain_name
)) {
1166 d_printf("Error looking up domain groups\n");
1171 if (!wbinfo_lookupsid(string_arg
)) {
1172 d_printf("Could not lookup sid %s\n", string_arg
);
1177 if (!wbinfo_lookupname(string_arg
)) {
1178 d_printf("Could not lookup name %s\n", string_arg
);
1183 if (!wbinfo_wins_byname(string_arg
)) {
1184 d_printf("Could not lookup WINS by name %s\n", string_arg
);
1189 if (!wbinfo_wins_byip(string_arg
)) {
1190 d_printf("Could not lookup WINS by IP %s\n", string_arg
);
1195 if (!wbinfo_uid_to_sid(int_arg
)) {
1196 d_printf("Could not convert uid %d to sid\n", int_arg
);
1201 if (!wbinfo_gid_to_sid(int_arg
)) {
1202 d_printf("Could not convert gid %d to sid\n",
1208 if (!wbinfo_sid_to_uid(string_arg
)) {
1209 d_printf("Could not convert sid %s to uid\n",
1215 if (!wbinfo_sid_to_gid(string_arg
)) {
1216 d_printf("Could not convert sid %s to gid\n",
1222 if (!wbinfo_allocate_rid()) {
1223 d_printf("Could not allocate a RID\n");
1228 if (!wbinfo_check_secret()) {
1229 d_printf("Could not check secret\n");
1234 if (!wbinfo_list_domains()) {
1235 d_printf("Could not list trusted domains\n");
1240 if (!wbinfo_show_sequence(opt_domain_name
)) {
1241 d_printf("Could not show sequence numbers\n");
1246 if (!wbinfo_domain_info(string_arg
)) {
1247 d_printf("Could not get domain info\n");
1252 if (!wbinfo_get_usergroups(string_arg
)) {
1253 d_printf("Could not get groups for user %s\n",
1259 if (!wbinfo_get_usersids(string_arg
)) {
1260 d_printf("Could not get group SIDs for user SID %s\n",
1266 BOOL got_error
= False
;
1268 if (!wbinfo_auth(string_arg
)) {
1269 d_printf("Could not authenticate user %s with "
1270 "plaintext password\n", string_arg
);
1274 if (!wbinfo_auth_crap(string_arg
)) {
1275 d_printf("Could not authenticate user %s with "
1276 "challenge/response\n", string_arg
);
1285 if (!wbinfo_klog(string_arg
)) {
1286 d_printf("Could not klog user\n");
1291 if ( !wbinfo_create_user(string_arg
) ) {
1292 d_printf("Could not create user account\n");
1297 if ( !wbinfo_create_group(string_arg
) ) {
1298 d_printf("Could not create group\n");
1303 if ( !wbinfo_add_user_to_group(string_arg
) ) {
1304 d_printf("Could not add user to group\n");
1309 if ( !wbinfo_remove_user_from_group(string_arg
) ) {
1310 d_printf("Could not remove user from group\n");
1315 if ( !wbinfo_delete_user(string_arg
) ) {
1316 d_printf("Could not delete user account\n");
1321 if ( !wbinfo_delete_group(string_arg
) ) {
1322 d_printf("Could not delete group\n");
1327 if (!wbinfo_ping()) {
1328 d_printf("could not ping winbindd!\n");
1332 case OPT_SET_AUTH_USER
:
1333 wbinfo_set_auth_user(string_arg
);
1335 case OPT_GET_AUTH_USER
:
1336 wbinfo_get_auth_user();
1338 /* generic configuration options */
1339 case OPT_DOMAIN_NAME
:
1342 d_fprintf(stderr
, "Invalid option\n");
1343 poptPrintHelp(pc
, stderr
, 0);
1353 poptFreeContext(pc
);