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
);
403 fstrcpy(request
.data
.sid
, sid
);
405 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) !=
409 /* Display response */
411 d_printf("%d\n", (int)response
.data
.uid
);
416 static BOOL
wbinfo_sid_to_gid(char *sid
)
418 struct winbindd_request request
;
419 struct winbindd_response response
;
421 ZERO_STRUCT(request
);
422 ZERO_STRUCT(response
);
426 fstrcpy(request
.data
.sid
, sid
);
428 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) !=
432 /* Display response */
434 d_printf("%d\n", (int)response
.data
.gid
);
439 /* Convert sid to string */
441 static BOOL
wbinfo_lookupsid(char *sid
)
443 struct winbindd_request request
;
444 struct winbindd_response response
;
446 ZERO_STRUCT(request
);
447 ZERO_STRUCT(response
);
449 /* Send off request */
451 fstrcpy(request
.data
.sid
, sid
);
453 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
457 /* Display response */
459 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
460 winbind_separator(), response
.data
.name
.name
,
461 response
.data
.name
.type
);
466 /* Convert string to sid */
468 static BOOL
wbinfo_lookupname(char *name
)
470 struct winbindd_request request
;
471 struct winbindd_response response
;
473 /* Send off request */
475 ZERO_STRUCT(request
);
476 ZERO_STRUCT(response
);
478 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
479 request
.data
.name
.name
);
481 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
485 /* Display response */
487 d_printf("%s %s (%d)\n", response
.data
.sid
.sid
, sid_type_lookup(response
.data
.sid
.type
), response
.data
.sid
.type
);
492 /* Authenticate a user with a plaintext password */
494 static BOOL
wbinfo_auth(char *username
)
496 struct winbindd_request request
;
497 struct winbindd_response response
;
501 /* Send off request */
503 ZERO_STRUCT(request
);
504 ZERO_STRUCT(response
);
506 p
= strchr(username
, '%');
510 fstrcpy(request
.data
.auth
.user
, username
);
511 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
514 fstrcpy(request
.data
.auth
.user
, username
);
516 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
518 /* Display response */
520 d_printf("plaintext password authentication %s\n",
521 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
523 if (response
.data
.auth
.nt_status
)
524 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
525 response
.data
.auth
.nt_status_string
,
526 response
.data
.auth
.nt_status
,
527 response
.data
.auth
.error_string
);
529 return result
== NSS_STATUS_SUCCESS
;
532 /* Authenticate a user with a challenge/response */
534 static BOOL
wbinfo_auth_crap(char *username
)
536 struct winbindd_request request
;
537 struct winbindd_response response
;
544 /* Send off request */
546 ZERO_STRUCT(request
);
547 ZERO_STRUCT(response
);
549 p
= strchr(username
, '%');
553 fstrcpy(pass
, p
+ 1);
556 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
558 if (push_utf8_fstring(request
.data
.auth_crap
.user
, name_user
) == -1) {
559 d_printf("unable to create utf8 string for '%s'\n",
564 if (push_utf8_fstring(request
.data
.auth_crap
.domain
,
565 name_domain
) == -1) {
566 d_printf("unable to create utf8 string for '%s'\n",
571 generate_random_buffer(request
.data
.auth_crap
.chal
, 8, False
);
573 SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
574 (uchar
*)request
.data
.auth_crap
.lm_resp
);
575 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
576 (uchar
*)request
.data
.auth_crap
.nt_resp
);
578 request
.data
.auth_crap
.lm_resp_len
= 24;
579 request
.data
.auth_crap
.nt_resp_len
= 24;
581 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
583 /* Display response */
585 d_printf("challenge/response password authentication %s\n",
586 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
588 if (response
.data
.auth
.nt_status
)
589 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
590 response
.data
.auth
.nt_status_string
,
591 response
.data
.auth
.nt_status
,
592 response
.data
.auth
.error_string
);
594 return result
== NSS_STATUS_SUCCESS
;
597 /******************************************************************
598 create a winbindd user
599 ******************************************************************/
601 static BOOL
wbinfo_create_user(char *username
)
603 struct winbindd_request request
;
604 struct winbindd_response response
;
607 /* Send off request */
609 ZERO_STRUCT(request
);
610 ZERO_STRUCT(response
);
612 request
.flags
= WBFLAG_ALLOCATE_RID
;
613 fstrcpy(request
.data
.acct_mgt
.username
, username
);
615 result
= winbindd_request(WINBINDD_CREATE_USER
, &request
, &response
);
617 if ( result
== NSS_STATUS_SUCCESS
)
618 d_printf("New RID is %d\n", response
.data
.rid
);
620 return result
== NSS_STATUS_SUCCESS
;
623 /******************************************************************
624 remove a winbindd user
625 ******************************************************************/
627 static BOOL
wbinfo_delete_user(char *username
)
629 struct winbindd_request request
;
630 struct winbindd_response response
;
633 /* Send off request */
635 ZERO_STRUCT(request
);
636 ZERO_STRUCT(response
);
638 fstrcpy(request
.data
.acct_mgt
.username
, username
);
640 result
= winbindd_request(WINBINDD_DELETE_USER
, &request
, &response
);
642 return result
== NSS_STATUS_SUCCESS
;
645 /******************************************************************
646 create a winbindd group
647 ******************************************************************/
649 static BOOL
wbinfo_create_group(char *groupname
)
651 struct winbindd_request request
;
652 struct winbindd_response response
;
655 /* Send off request */
657 ZERO_STRUCT(request
);
658 ZERO_STRUCT(response
);
660 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
662 result
= winbindd_request(WINBINDD_CREATE_GROUP
, &request
, &response
);
664 return result
== NSS_STATUS_SUCCESS
;
667 /******************************************************************
668 remove a winbindd group
669 ******************************************************************/
671 static BOOL
wbinfo_delete_group(char *groupname
)
673 struct winbindd_request request
;
674 struct winbindd_response response
;
677 /* Send off request */
679 ZERO_STRUCT(request
);
680 ZERO_STRUCT(response
);
682 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
684 result
= winbindd_request(WINBINDD_DELETE_GROUP
, &request
, &response
);
686 return result
== NSS_STATUS_SUCCESS
;
689 /******************************************************************
690 parse a string in the form user:group
691 ******************************************************************/
693 static BOOL
parse_user_group( const char *string
, fstring user
, fstring group
)
700 if ( !(p
= strchr( string
, ':' )) )
706 fstrcpy( user
, string
);
712 /******************************************************************
713 add a user to a winbindd group
714 ******************************************************************/
716 static BOOL
wbinfo_add_user_to_group(char *string
)
718 struct winbindd_request request
;
719 struct winbindd_response response
;
722 /* Send off request */
724 ZERO_STRUCT(request
);
725 ZERO_STRUCT(response
);
727 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
728 request
.data
.acct_mgt
.groupname
))
730 d_printf("Can't parse user:group from %s\n", string
);
734 result
= winbindd_request(WINBINDD_ADD_USER_TO_GROUP
, &request
, &response
);
736 return result
== NSS_STATUS_SUCCESS
;
739 /******************************************************************
740 remove a user from a winbindd group
741 ******************************************************************/
743 static BOOL
wbinfo_remove_user_from_group(char *string
)
745 struct winbindd_request request
;
746 struct winbindd_response response
;
749 /* Send off request */
751 ZERO_STRUCT(request
);
752 ZERO_STRUCT(response
);
754 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
755 request
.data
.acct_mgt
.groupname
))
757 d_printf("Can't parse user:group from %s\n", string
);
761 result
= winbindd_request(WINBINDD_REMOVE_USER_FROM_GROUP
, &request
, &response
);
763 return result
== NSS_STATUS_SUCCESS
;
766 /* Print domain users */
768 static BOOL
print_domain_users(const char *domain
)
770 struct winbindd_request request
;
771 struct winbindd_response response
;
772 const char *extra_data
;
775 /* Send request to winbind daemon */
777 ZERO_STRUCT(request
);
778 ZERO_STRUCT(response
);
781 /* '.' is the special sign for our own domwin */
782 if ( strequal(domain
, ".") )
783 fstrcpy( request
.domain_name
, lp_workgroup() );
785 fstrcpy( request
.domain_name
, domain
);
788 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
792 /* Look through extra data */
794 if (!response
.extra_data
)
797 extra_data
= (const char *)response
.extra_data
;
799 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
800 d_printf("%s\n", name
);
802 SAFE_FREE(response
.extra_data
);
807 /* Print domain groups */
809 static BOOL
print_domain_groups(const char *domain
)
811 struct winbindd_request request
;
812 struct winbindd_response response
;
813 const char *extra_data
;
816 ZERO_STRUCT(request
);
817 ZERO_STRUCT(response
);
820 if ( strequal(domain
, ".") )
821 fstrcpy( request
.domain_name
, lp_workgroup() );
823 fstrcpy( request
.domain_name
, domain
);
826 if (winbindd_request(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
830 /* Look through extra data */
832 if (!response
.extra_data
)
835 extra_data
= (const char *)response
.extra_data
;
837 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
838 d_printf("%s\n", name
);
840 SAFE_FREE(response
.extra_data
);
845 /* Set the authorised user for winbindd access in secrets.tdb */
847 static BOOL
wbinfo_set_auth_user(char *username
)
850 fstring user
, domain
;
852 /* Separate into user and password */
854 parse_wbinfo_domain_user(username
, domain
, user
);
856 password
= strchr(user
, '%');
862 char *thepass
= getpass("Password: ");
869 /* Store or remove DOMAIN\username%password in secrets.tdb */
875 if (!secrets_store(SECRETS_AUTH_USER
, user
,
877 d_fprintf(stderr
, "error storing username\n");
881 /* We always have a domain name added by the
882 parse_wbinfo_domain_user() function. */
884 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
885 strlen(domain
) + 1)) {
886 d_fprintf(stderr
, "error storing domain name\n");
891 secrets_delete(SECRETS_AUTH_USER
);
892 secrets_delete(SECRETS_AUTH_DOMAIN
);
897 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
898 strlen(password
) + 1)) {
899 d_fprintf(stderr
, "error storing password\n");
904 secrets_delete(SECRETS_AUTH_PASSWORD
);
909 static void wbinfo_get_auth_user(void)
911 char *user
, *domain
, *password
;
913 /* Lift data from secrets file */
915 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
917 if ((!user
|| !*user
) && (!domain
|| !*domain
) && (!password
|| !*password
)){
922 d_printf("No authorised user configured\n");
926 /* Pretty print authorised user info */
928 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? lp_winbind_separator(): "",
929 user
, password
? "%" : "", password
? password
: "");
936 static BOOL
wbinfo_ping(void)
940 result
= winbindd_request(WINBINDD_PING
, NULL
, NULL
);
942 /* Display response */
944 d_printf("Ping to winbindd %s on fd %d\n",
945 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
947 return result
== NSS_STATUS_SUCCESS
;
953 OPT_SET_AUTH_USER
= 1000,
960 int main(int argc
, char **argv
)
965 static char *string_arg
;
966 static char *opt_domain_name
;
970 struct poptOption long_options
[] = {
973 /* longName, shortName, argInfo, argPtr, value, descrip,
976 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
977 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
978 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
979 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
980 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
981 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
982 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
983 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
984 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
985 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
986 { "create-user", 'c', POPT_ARG_STRING
, &string_arg
, 'c', "Create a local user account", "name" },
987 { "delete-user", 'x', POPT_ARG_STRING
, &string_arg
, 'x', "Delete a local user account", "name" },
988 { "create-group", 'C', POPT_ARG_STRING
, &string_arg
, 'C', "Create a local group", "name" },
989 { "delete-group", 'X', POPT_ARG_STRING
, &string_arg
, 'X', "Delete a local group", "name" },
990 { "add-to-group", 'o', POPT_ARG_STRING
, &string_arg
, 'o', "Add user to group", "user:group" },
991 { "del-from-group", 'O', POPT_ARG_STRING
, &string_arg
, 'O', "Remove user from group", "user:group" },
992 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
993 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
994 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
995 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D',
996 "Show all most info we have about the domain" },
997 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
998 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
999 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
1000 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
1001 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
1002 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
1003 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
1008 /* Samba client initialisation */
1010 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
)) {
1011 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
1012 dyn_CONFIGFILE
, strerror(errno
));
1023 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
1025 /* Parse command line options */
1028 poptPrintHelp(pc
, stderr
, 0);
1032 while((opt
= poptGetNextOpt(pc
)) != -1) {
1033 /* get the generic configuration parameters like --domain */
1036 poptFreeContext(pc
);
1038 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1039 POPT_CONTEXT_KEEP_FIRST
);
1041 while((opt
= poptGetNextOpt(pc
)) != -1) {
1044 if (!print_domain_users(opt_domain_name
)) {
1045 d_printf("Error looking up domain users\n");
1050 if (!print_domain_groups(opt_domain_name
)) {
1051 d_printf("Error looking up domain groups\n");
1056 if (!wbinfo_lookupsid(string_arg
)) {
1057 d_printf("Could not lookup sid %s\n", string_arg
);
1062 if (!wbinfo_lookupname(string_arg
)) {
1063 d_printf("Could not lookup name %s\n", string_arg
);
1068 if (!wbinfo_wins_byname(string_arg
)) {
1069 d_printf("Could not lookup WINS by name %s\n", string_arg
);
1074 if (!wbinfo_wins_byip(string_arg
)) {
1075 d_printf("Could not lookup WINS by IP %s\n", string_arg
);
1080 if (!wbinfo_uid_to_sid(int_arg
)) {
1081 d_printf("Could not convert uid %d to sid\n", int_arg
);
1086 if (!wbinfo_gid_to_sid(int_arg
)) {
1087 d_printf("Could not convert gid %d to sid\n",
1093 if (!wbinfo_sid_to_uid(string_arg
)) {
1094 d_printf("Could not convert sid %s to uid\n",
1100 if (!wbinfo_sid_to_gid(string_arg
)) {
1101 d_printf("Could not convert sid %s to gid\n",
1107 if (!wbinfo_check_secret()) {
1108 d_printf("Could not check secret\n");
1113 if (!wbinfo_list_domains()) {
1114 d_printf("Could not list trusted domains\n");
1119 if (!wbinfo_show_sequence(opt_domain_name
)) {
1120 d_printf("Could not show sequence numbers\n");
1125 if (!wbinfo_domain_info(string_arg
)) {
1126 d_printf("Could not get domain info\n");
1131 if (!wbinfo_get_usergroups(string_arg
)) {
1132 d_printf("Could not get groups for user %s\n",
1138 if (!wbinfo_get_usersids(string_arg
)) {
1139 d_printf("Could not get group SIDs for user SID %s\n",
1145 BOOL got_error
= False
;
1147 if (!wbinfo_auth(string_arg
)) {
1148 d_printf("Could not authenticate user %s with "
1149 "plaintext password\n", string_arg
);
1153 if (!wbinfo_auth_crap(string_arg
)) {
1154 d_printf("Could not authenticate user %s with "
1155 "challenge/response\n", string_arg
);
1164 if ( !wbinfo_create_user(string_arg
) ) {
1165 d_printf("Could not create user account\n");
1170 if ( !wbinfo_create_group(string_arg
) ) {
1171 d_printf("Could not create group\n");
1176 if ( !wbinfo_add_user_to_group(string_arg
) ) {
1177 d_printf("Could not add user to group\n");
1182 if ( !wbinfo_remove_user_from_group(string_arg
) ) {
1183 d_printf("Could not remove user kfrom group\n");
1188 if ( !wbinfo_delete_user(string_arg
) ) {
1189 d_printf("Could not delete user account\n");
1194 if ( !wbinfo_delete_group(string_arg
) ) {
1195 d_printf("Could not delete group\n");
1200 if (!wbinfo_ping()) {
1201 d_printf("could not ping winbindd!\n");
1205 case OPT_SET_AUTH_USER
:
1206 wbinfo_set_auth_user(string_arg
);
1208 case OPT_GET_AUTH_USER
:
1209 wbinfo_get_auth_user();
1211 /* generic configuration options */
1212 case OPT_DOMAIN_NAME
:
1215 d_fprintf(stderr
, "Invalid option\n");
1216 poptPrintHelp(pc
, stderr
, 0);
1226 poptFreeContext(pc
);