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
);
139 /* Convert NetBIOS name to IP */
141 static BOOL
wbinfo_wins_byname(char *name
)
143 struct winbindd_request request
;
144 struct winbindd_response response
;
146 ZERO_STRUCT(request
);
147 ZERO_STRUCT(response
);
151 fstrcpy(request
.data
.winsreq
, name
);
153 if (winbindd_request(WINBINDD_WINS_BYNAME
, &request
, &response
) !=
154 NSS_STATUS_SUCCESS
) {
158 /* Display response */
160 printf("%s\n", response
.data
.winsresp
);
165 /* Convert IP to NetBIOS name */
167 static BOOL
wbinfo_wins_byip(char *ip
)
169 struct winbindd_request request
;
170 struct winbindd_response response
;
172 ZERO_STRUCT(request
);
173 ZERO_STRUCT(response
);
177 fstrcpy(request
.data
.winsreq
, ip
);
179 if (winbindd_request(WINBINDD_WINS_BYIP
, &request
, &response
) !=
180 NSS_STATUS_SUCCESS
) {
184 /* Display response */
186 printf("%s\n", response
.data
.winsresp
);
191 /* List trusted domains */
193 static BOOL
wbinfo_list_domains(void)
195 struct winbindd_response response
;
198 ZERO_STRUCT(response
);
202 if (winbindd_request(WINBINDD_LIST_TRUSTDOM
, NULL
, &response
) !=
206 /* Display response */
208 if (response
.extra_data
) {
209 const char *extra_data
= (char *)response
.extra_data
;
211 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
212 d_printf("%s\n", name
);
214 SAFE_FREE(response
.extra_data
);
221 /* show sequence numbers */
222 static BOOL
wbinfo_show_sequence(const char *domain
)
224 struct winbindd_request request
;
225 struct winbindd_response response
;
227 ZERO_STRUCT(response
);
228 ZERO_STRUCT(request
);
231 fstrcpy( request
.domain_name
, domain
);
235 if (winbindd_request(WINBINDD_SHOW_SEQUENCE
, &request
, &response
) !=
239 /* Display response */
241 if (response
.extra_data
) {
242 char *extra_data
= (char *)response
.extra_data
;
243 d_printf("%s", extra_data
);
244 SAFE_FREE(response
.extra_data
);
250 /* Show domain info */
252 static BOOL
wbinfo_domain_info(const char *domain_name
)
254 struct winbindd_request request
;
255 struct winbindd_response response
;
257 ZERO_STRUCT(request
);
258 ZERO_STRUCT(response
);
260 fstrcpy(request
.domain_name
, domain_name
);
264 if (winbindd_request(WINBINDD_DOMAIN_INFO
, &request
, &response
) !=
268 /* Display response */
270 d_printf("Name : %s\n", response
.data
.domain_info
.name
);
271 d_printf("Alt_Name: %s\n", response
.data
.domain_info
.alt_name
);
273 d_printf("SID : %s\n", response
.data
.domain_info
.sid
);
275 d_printf("Native : %s\n",
276 response
.data
.domain_info
.native_mode
? "Yes" : "No");
278 d_printf("Primary : %s\n",
279 response
.data
.domain_info
.primary
? "Yes" : "No");
281 d_printf("Sequence: %d\n", response
.data
.domain_info
.sequence_number
);
286 /* Check trust account password */
288 static BOOL
wbinfo_check_secret(void)
290 struct winbindd_response response
;
293 ZERO_STRUCT(response
);
295 result
= winbindd_request(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
297 d_printf("checking the trust secret via RPC calls %s\n",
298 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
300 if (result
!= NSS_STATUS_SUCCESS
)
301 d_printf("error code was %s (0x%x)\n",
302 response
.data
.auth
.nt_status_string
,
303 response
.data
.auth
.nt_status
);
305 return result
== NSS_STATUS_SUCCESS
;
308 /* Convert uid to sid */
310 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
312 struct winbindd_request request
;
313 struct winbindd_response response
;
315 ZERO_STRUCT(request
);
316 ZERO_STRUCT(response
);
320 request
.data
.uid
= uid
;
322 if (winbindd_request(WINBINDD_UID_TO_SID
, &request
, &response
) !=
326 /* Display response */
328 d_printf("%s\n", response
.data
.sid
.sid
);
333 /* Convert gid to sid */
335 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
337 struct winbindd_request request
;
338 struct winbindd_response response
;
340 ZERO_STRUCT(request
);
341 ZERO_STRUCT(response
);
345 request
.data
.gid
= gid
;
347 if (winbindd_request(WINBINDD_GID_TO_SID
, &request
, &response
) !=
351 /* Display response */
353 d_printf("%s\n", response
.data
.sid
.sid
);
358 /* Convert sid to uid */
360 static BOOL
wbinfo_sid_to_uid(char *sid
)
362 struct winbindd_request request
;
363 struct winbindd_response response
;
365 ZERO_STRUCT(request
);
366 ZERO_STRUCT(response
);
370 fstrcpy(request
.data
.sid
, sid
);
372 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) !=
376 /* Display response */
378 d_printf("%d\n", (int)response
.data
.uid
);
383 static BOOL
wbinfo_sid_to_gid(char *sid
)
385 struct winbindd_request request
;
386 struct winbindd_response response
;
388 ZERO_STRUCT(request
);
389 ZERO_STRUCT(response
);
393 fstrcpy(request
.data
.sid
, sid
);
395 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) !=
399 /* Display response */
401 d_printf("%d\n", (int)response
.data
.gid
);
406 /* Convert sid to string */
408 static BOOL
wbinfo_lookupsid(char *sid
)
410 struct winbindd_request request
;
411 struct winbindd_response response
;
413 ZERO_STRUCT(request
);
414 ZERO_STRUCT(response
);
416 /* Send off request */
418 fstrcpy(request
.data
.sid
, sid
);
420 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
424 /* Display response */
426 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
427 winbind_separator(), response
.data
.name
.name
,
428 response
.data
.name
.type
);
433 /* Convert string to sid */
435 static BOOL
wbinfo_lookupname(char *name
)
437 struct winbindd_request request
;
438 struct winbindd_response response
;
440 /* Send off request */
442 ZERO_STRUCT(request
);
443 ZERO_STRUCT(response
);
445 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
446 request
.data
.name
.name
);
448 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
452 /* Display response */
454 d_printf("%s %d\n", response
.data
.sid
.sid
, response
.data
.sid
.type
);
459 /* Authenticate a user with a plaintext password */
461 static BOOL
wbinfo_auth(char *username
)
463 struct winbindd_request request
;
464 struct winbindd_response response
;
468 /* Send off request */
470 ZERO_STRUCT(request
);
471 ZERO_STRUCT(response
);
473 p
= strchr(username
, '%');
477 fstrcpy(request
.data
.auth
.user
, username
);
478 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
481 fstrcpy(request
.data
.auth
.user
, username
);
483 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
485 /* Display response */
487 d_printf("plaintext password authentication %s\n",
488 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
490 if (response
.data
.auth
.nt_status
)
491 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
492 response
.data
.auth
.nt_status_string
,
493 response
.data
.auth
.nt_status
,
494 response
.data
.auth
.error_string
);
496 return result
== NSS_STATUS_SUCCESS
;
499 /* Authenticate a user with a challenge/response */
501 static BOOL
wbinfo_auth_crap(char *username
)
503 struct winbindd_request request
;
504 struct winbindd_response response
;
511 /* Send off request */
513 ZERO_STRUCT(request
);
514 ZERO_STRUCT(response
);
516 p
= strchr(username
, '%');
520 fstrcpy(pass
, p
+ 1);
523 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
525 if (push_utf8_fstring(request
.data
.auth_crap
.user
, name_user
) == -1) {
526 d_printf("unable to create utf8 string for '%s'\n",
531 if (push_utf8_fstring(request
.data
.auth_crap
.domain
,
532 name_domain
) == -1) {
533 d_printf("unable to create utf8 string for '%s'\n",
538 generate_random_buffer(request
.data
.auth_crap
.chal
, 8, False
);
540 SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
541 (uchar
*)request
.data
.auth_crap
.lm_resp
);
542 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
543 (uchar
*)request
.data
.auth_crap
.nt_resp
);
545 request
.data
.auth_crap
.lm_resp_len
= 24;
546 request
.data
.auth_crap
.nt_resp_len
= 24;
548 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
550 /* Display response */
552 d_printf("challenge/response password authentication %s\n",
553 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
555 if (response
.data
.auth
.nt_status
)
556 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
557 response
.data
.auth
.nt_status_string
,
558 response
.data
.auth
.nt_status
,
559 response
.data
.auth
.error_string
);
561 return result
== NSS_STATUS_SUCCESS
;
564 /******************************************************************
565 create a winbindd user
566 ******************************************************************/
568 static BOOL
wbinfo_create_user(char *username
)
570 struct winbindd_request request
;
571 struct winbindd_response response
;
574 /* Send off request */
576 ZERO_STRUCT(request
);
577 ZERO_STRUCT(response
);
579 request
.flags
= WBFLAG_ALLOCATE_RID
;
580 fstrcpy(request
.data
.acct_mgt
.username
, username
);
582 result
= winbindd_request(WINBINDD_CREATE_USER
, &request
, &response
);
584 if ( result
== NSS_STATUS_SUCCESS
)
585 d_printf("New RID is %d\n", response
.data
.rid
);
587 return result
== NSS_STATUS_SUCCESS
;
590 /******************************************************************
591 remove a winbindd user
592 ******************************************************************/
594 static BOOL
wbinfo_delete_user(char *username
)
596 struct winbindd_request request
;
597 struct winbindd_response response
;
600 /* Send off request */
602 ZERO_STRUCT(request
);
603 ZERO_STRUCT(response
);
605 fstrcpy(request
.data
.acct_mgt
.username
, username
);
607 result
= winbindd_request(WINBINDD_DELETE_USER
, &request
, &response
);
609 return result
== NSS_STATUS_SUCCESS
;
612 /******************************************************************
613 create a winbindd group
614 ******************************************************************/
616 static BOOL
wbinfo_create_group(char *groupname
)
618 struct winbindd_request request
;
619 struct winbindd_response response
;
622 /* Send off request */
624 ZERO_STRUCT(request
);
625 ZERO_STRUCT(response
);
627 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
629 result
= winbindd_request(WINBINDD_CREATE_GROUP
, &request
, &response
);
631 return result
== NSS_STATUS_SUCCESS
;
634 /******************************************************************
635 remove a winbindd group
636 ******************************************************************/
638 static BOOL
wbinfo_delete_group(char *groupname
)
640 struct winbindd_request request
;
641 struct winbindd_response response
;
644 /* Send off request */
646 ZERO_STRUCT(request
);
647 ZERO_STRUCT(response
);
649 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
651 result
= winbindd_request(WINBINDD_DELETE_GROUP
, &request
, &response
);
653 return result
== NSS_STATUS_SUCCESS
;
656 /******************************************************************
657 parse a string in the form user:group
658 ******************************************************************/
660 static BOOL
parse_user_group( const char *string
, fstring user
, fstring group
)
667 if ( !(p
= strchr( string
, ':' )) )
673 fstrcpy( user
, string
);
679 /******************************************************************
680 add a user to a winbindd group
681 ******************************************************************/
683 static BOOL
wbinfo_add_user_to_group(char *string
)
685 struct winbindd_request request
;
686 struct winbindd_response response
;
689 /* Send off request */
691 ZERO_STRUCT(request
);
692 ZERO_STRUCT(response
);
694 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
695 request
.data
.acct_mgt
.groupname
))
697 d_printf("Can't parse user:group from %s\n", string
);
701 result
= winbindd_request(WINBINDD_ADD_USER_TO_GROUP
, &request
, &response
);
703 return result
== NSS_STATUS_SUCCESS
;
706 /******************************************************************
707 remove a user from a winbindd group
708 ******************************************************************/
710 static BOOL
wbinfo_remove_user_from_group(char *string
)
712 struct winbindd_request request
;
713 struct winbindd_response response
;
716 /* Send off request */
718 ZERO_STRUCT(request
);
719 ZERO_STRUCT(response
);
721 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
722 request
.data
.acct_mgt
.groupname
))
724 d_printf("Can't parse user:group from %s\n", string
);
728 result
= winbindd_request(WINBINDD_REMOVE_USER_FROM_GROUP
, &request
, &response
);
730 return result
== NSS_STATUS_SUCCESS
;
733 /* Print domain users */
735 static BOOL
print_domain_users(const char *domain
)
737 struct winbindd_request request
;
738 struct winbindd_response response
;
739 const char *extra_data
;
742 /* Send request to winbind daemon */
744 ZERO_STRUCT(request
);
745 ZERO_STRUCT(response
);
748 /* '.' is the special sign for our own domwin */
749 if ( strequal(domain
, ".") )
750 fstrcpy( request
.domain_name
, lp_workgroup() );
752 fstrcpy( request
.domain_name
, domain
);
755 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
759 /* Look through extra data */
761 if (!response
.extra_data
)
764 extra_data
= (const char *)response
.extra_data
;
766 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
767 d_printf("%s\n", name
);
769 SAFE_FREE(response
.extra_data
);
774 /* Print domain groups */
776 static BOOL
print_domain_groups(const char *domain
)
778 struct winbindd_request request
;
779 struct winbindd_response response
;
780 const char *extra_data
;
783 ZERO_STRUCT(request
);
784 ZERO_STRUCT(response
);
787 if ( strequal(domain
, ".") )
788 fstrcpy( request
.domain_name
, lp_workgroup() );
790 fstrcpy( request
.domain_name
, domain
);
793 if (winbindd_request(WINBINDD_LIST_GROUPS
, &request
, &response
) !=
797 /* Look through extra data */
799 if (!response
.extra_data
)
802 extra_data
= (const char *)response
.extra_data
;
804 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
805 d_printf("%s\n", name
);
807 SAFE_FREE(response
.extra_data
);
812 /* Set the authorised user for winbindd access in secrets.tdb */
814 static BOOL
wbinfo_set_auth_user(char *username
)
817 fstring user
, domain
;
819 /* Separate into user and password */
821 parse_wbinfo_domain_user(username
, domain
, user
);
823 password
= strchr(user
, '%');
829 char *thepass
= getpass("Password: ");
836 /* Store or remove DOMAIN\username%password in secrets.tdb */
842 if (!secrets_store(SECRETS_AUTH_USER
, user
,
844 d_fprintf(stderr
, "error storing username\n");
848 /* We always have a domain name added by the
849 parse_wbinfo_domain_user() function. */
851 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
852 strlen(domain
) + 1)) {
853 d_fprintf(stderr
, "error storing domain name\n");
858 secrets_delete(SECRETS_AUTH_USER
);
859 secrets_delete(SECRETS_AUTH_DOMAIN
);
864 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
865 strlen(password
) + 1)) {
866 d_fprintf(stderr
, "error storing password\n");
871 secrets_delete(SECRETS_AUTH_PASSWORD
);
876 static void wbinfo_get_auth_user(void)
878 char *user
, *domain
, *password
;
880 /* Lift data from secrets file */
884 user
= secrets_fetch(SECRETS_AUTH_USER
, NULL
);
885 domain
= secrets_fetch(SECRETS_AUTH_DOMAIN
, NULL
);
886 password
= secrets_fetch(SECRETS_AUTH_PASSWORD
, NULL
);
888 if (!user
&& !domain
&& !password
) {
889 d_printf("No authorised user configured\n");
893 /* Pretty print authorised user info */
895 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? "\\" : "",
896 user
, password
? "%" : "", password
? password
: "");
903 static BOOL
wbinfo_ping(void)
907 result
= winbindd_request(WINBINDD_PING
, NULL
, NULL
);
909 /* Display response */
911 d_printf("Ping to winbindd %s on fd %d\n",
912 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
914 return result
== NSS_STATUS_SUCCESS
;
920 OPT_SET_AUTH_USER
= 1000,
926 int main(int argc
, char **argv
)
931 static char *string_arg
;
932 static char *opt_domain_name
;
936 struct poptOption long_options
[] = {
939 /* longName, shortName, argInfo, argPtr, value, descrip,
942 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
943 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
944 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
945 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
946 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
947 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
948 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
949 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
950 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
951 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
952 { "create-user", 'c', POPT_ARG_STRING
, &string_arg
, 'c', "Create a local user account", "name" },
953 { "delete-user", 'x', POPT_ARG_STRING
, &string_arg
, 'x', "Delete a local user account", "name" },
954 { "create-group", 'C', POPT_ARG_STRING
, &string_arg
, 'C', "Create a local group", "name" },
955 { "delete-group", 'X', POPT_ARG_STRING
, &string_arg
, 'X', "Delete a local group", "name" },
956 { "add-to-group", 'o', POPT_ARG_STRING
, &string_arg
, 'o', "Add user to group", "user:group" },
957 { "del-from-group", 'O', POPT_ARG_STRING
, &string_arg
, 'O', "Remove user from group", "user:group" },
958 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
959 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
960 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
961 { "domain-info", 'D', POPT_ARG_STRING
, &string_arg
, 'D',
962 "Show all most info we have about the domain" },
963 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
964 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
965 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
966 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
967 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
968 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operatio", "domain" },
973 /* Samba client initialisation */
975 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
)) {
976 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
977 dyn_CONFIGFILE
, strerror(errno
));
988 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
990 /* Parse command line options */
993 poptPrintHelp(pc
, stderr
, 0);
997 while((opt
= poptGetNextOpt(pc
)) != -1) {
998 /* get the generic configuration parameters like --domain */
1001 poptFreeContext(pc
);
1003 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
1004 POPT_CONTEXT_KEEP_FIRST
);
1006 while((opt
= poptGetNextOpt(pc
)) != -1) {
1009 if (!print_domain_users(opt_domain_name
)) {
1010 d_printf("Error looking up domain users\n");
1015 if (!print_domain_groups(opt_domain_name
)) {
1016 d_printf("Error looking up domain groups\n");
1021 if (!wbinfo_lookupsid(string_arg
)) {
1022 d_printf("Could not lookup sid %s\n", string_arg
);
1027 if (!wbinfo_lookupname(string_arg
)) {
1028 d_printf("Could not lookup name %s\n", string_arg
);
1033 if (!wbinfo_wins_byname(string_arg
)) {
1034 d_printf("Could not lookup WINS by name %s\n", string_arg
);
1039 if (!wbinfo_wins_byip(string_arg
)) {
1040 d_printf("Could not lookup WINS by IP %s\n", string_arg
);
1045 if (!wbinfo_uid_to_sid(int_arg
)) {
1046 d_printf("Could not convert uid %d to sid\n", int_arg
);
1051 if (!wbinfo_gid_to_sid(int_arg
)) {
1052 d_printf("Could not convert gid %d to sid\n",
1058 if (!wbinfo_sid_to_uid(string_arg
)) {
1059 d_printf("Could not convert sid %s to uid\n",
1065 if (!wbinfo_sid_to_gid(string_arg
)) {
1066 d_printf("Could not convert sid %s to gid\n",
1072 if (!wbinfo_check_secret()) {
1073 d_printf("Could not check secret\n");
1078 if (!wbinfo_list_domains()) {
1079 d_printf("Could not list trusted domains\n");
1084 if (!wbinfo_show_sequence(opt_domain_name
)) {
1085 d_printf("Could not show sequence numbers\n");
1090 if (!wbinfo_domain_info(string_arg
)) {
1091 d_printf("Could not get domain info\n");
1096 if (!wbinfo_get_usergroups(string_arg
)) {
1097 d_printf("Could not get groups for user %s\n",
1103 BOOL got_error
= False
;
1105 if (!wbinfo_auth(string_arg
)) {
1106 d_printf("Could not authenticate user %s with "
1107 "plaintext password\n", string_arg
);
1111 if (!wbinfo_auth_crap(string_arg
)) {
1112 d_printf("Could not authenticate user %s with "
1113 "challenge/response\n", string_arg
);
1122 if ( !wbinfo_create_user(string_arg
) ) {
1123 d_printf("Could not create user account\n");
1128 if ( !wbinfo_create_group(string_arg
) ) {
1129 d_printf("Could not create group\n");
1134 if ( !wbinfo_add_user_to_group(string_arg
) ) {
1135 d_printf("Could not add user to group\n");
1140 if ( !wbinfo_remove_user_from_group(string_arg
) ) {
1141 d_printf("Could not remove user kfrom group\n");
1146 if ( !wbinfo_delete_user(string_arg
) ) {
1147 d_printf("Could not delete user account\n");
1152 if ( !wbinfo_delete_group(string_arg
) ) {
1153 d_printf("Could not delete group\n");
1158 if (!wbinfo_ping()) {
1159 d_printf("could not ping winbindd!\n");
1163 case OPT_SET_AUTH_USER
:
1164 wbinfo_set_auth_user(string_arg
);
1166 case OPT_GET_AUTH_USER
:
1167 wbinfo_get_auth_user();
1169 /* generic configuration options */
1170 case OPT_DOMAIN_NAME
:
1173 d_fprintf(stderr
, "Invalid option\n");
1174 poptPrintHelp(pc
, stderr
, 0);
1184 poptFreeContext(pc
);