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 /* Check trust account password */
283 static BOOL
wbinfo_check_secret(void)
285 struct winbindd_response response
;
288 ZERO_STRUCT(response
);
290 result
= winbindd_request(WINBINDD_CHECK_MACHACC
, NULL
, &response
);
292 d_printf("checking the trust secret via RPC calls %s\n",
293 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
295 if (result
!= NSS_STATUS_SUCCESS
)
296 d_printf("error code was %s (0x%x)\n",
297 response
.data
.auth
.nt_status_string
,
298 response
.data
.auth
.nt_status
);
300 return result
== NSS_STATUS_SUCCESS
;
303 /* Convert uid to sid */
305 static BOOL
wbinfo_uid_to_sid(uid_t uid
)
307 struct winbindd_request request
;
308 struct winbindd_response response
;
310 ZERO_STRUCT(request
);
311 ZERO_STRUCT(response
);
315 request
.data
.uid
= uid
;
317 if (winbindd_request(WINBINDD_UID_TO_SID
, &request
, &response
) !=
321 /* Display response */
323 d_printf("%s\n", response
.data
.sid
.sid
);
328 /* Convert gid to sid */
330 static BOOL
wbinfo_gid_to_sid(gid_t gid
)
332 struct winbindd_request request
;
333 struct winbindd_response response
;
335 ZERO_STRUCT(request
);
336 ZERO_STRUCT(response
);
340 request
.data
.gid
= gid
;
342 if (winbindd_request(WINBINDD_GID_TO_SID
, &request
, &response
) !=
346 /* Display response */
348 d_printf("%s\n", response
.data
.sid
.sid
);
353 /* Convert sid to uid */
355 static BOOL
wbinfo_sid_to_uid(char *sid
)
357 struct winbindd_request request
;
358 struct winbindd_response response
;
360 ZERO_STRUCT(request
);
361 ZERO_STRUCT(response
);
365 fstrcpy(request
.data
.sid
, sid
);
367 if (winbindd_request(WINBINDD_SID_TO_UID
, &request
, &response
) !=
371 /* Display response */
373 d_printf("%d\n", (int)response
.data
.uid
);
378 static BOOL
wbinfo_sid_to_gid(char *sid
)
380 struct winbindd_request request
;
381 struct winbindd_response response
;
383 ZERO_STRUCT(request
);
384 ZERO_STRUCT(response
);
388 fstrcpy(request
.data
.sid
, sid
);
390 if (winbindd_request(WINBINDD_SID_TO_GID
, &request
, &response
) !=
394 /* Display response */
396 d_printf("%d\n", (int)response
.data
.gid
);
401 /* Convert sid to string */
403 static BOOL
wbinfo_lookupsid(char *sid
)
405 struct winbindd_request request
;
406 struct winbindd_response response
;
408 ZERO_STRUCT(request
);
409 ZERO_STRUCT(response
);
411 /* Send off request */
413 fstrcpy(request
.data
.sid
, sid
);
415 if (winbindd_request(WINBINDD_LOOKUPSID
, &request
, &response
) !=
419 /* Display response */
421 d_printf("%s%c%s %d\n", response
.data
.name
.dom_name
,
422 winbind_separator(), response
.data
.name
.name
,
423 response
.data
.name
.type
);
428 /* Convert string to sid */
430 static BOOL
wbinfo_lookupname(char *name
)
432 struct winbindd_request request
;
433 struct winbindd_response response
;
435 /* Send off request */
437 ZERO_STRUCT(request
);
438 ZERO_STRUCT(response
);
440 parse_wbinfo_domain_user(name
, request
.data
.name
.dom_name
,
441 request
.data
.name
.name
);
443 if (winbindd_request(WINBINDD_LOOKUPNAME
, &request
, &response
) !=
447 /* Display response */
449 d_printf("%s %d\n", response
.data
.sid
.sid
, response
.data
.sid
.type
);
454 /* Authenticate a user with a plaintext password */
456 static BOOL
wbinfo_auth(char *username
)
458 struct winbindd_request request
;
459 struct winbindd_response response
;
463 /* Send off request */
465 ZERO_STRUCT(request
);
466 ZERO_STRUCT(response
);
468 p
= strchr(username
, '%');
472 fstrcpy(request
.data
.auth
.user
, username
);
473 fstrcpy(request
.data
.auth
.pass
, p
+ 1);
476 fstrcpy(request
.data
.auth
.user
, username
);
478 result
= winbindd_request(WINBINDD_PAM_AUTH
, &request
, &response
);
480 /* Display response */
482 d_printf("plaintext password authentication %s\n",
483 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
485 if (response
.data
.auth
.nt_status
)
486 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
487 response
.data
.auth
.nt_status_string
,
488 response
.data
.auth
.nt_status
,
489 response
.data
.auth
.error_string
);
491 return result
== NSS_STATUS_SUCCESS
;
494 /* Authenticate a user with a challenge/response */
496 static BOOL
wbinfo_auth_crap(char *username
)
498 struct winbindd_request request
;
499 struct winbindd_response response
;
506 /* Send off request */
508 ZERO_STRUCT(request
);
509 ZERO_STRUCT(response
);
511 p
= strchr(username
, '%');
515 fstrcpy(pass
, p
+ 1);
518 parse_wbinfo_domain_user(username
, name_domain
, name_user
);
520 if (push_utf8_fstring(request
.data
.auth_crap
.user
, name_user
) == -1) {
521 d_printf("unable to create utf8 string for '%s'\n",
526 if (push_utf8_fstring(request
.data
.auth_crap
.domain
,
527 name_domain
) == -1) {
528 d_printf("unable to create utf8 string for '%s'\n",
533 generate_random_buffer(request
.data
.auth_crap
.chal
, 8, False
);
535 SMBencrypt(pass
, request
.data
.auth_crap
.chal
,
536 (uchar
*)request
.data
.auth_crap
.lm_resp
);
537 SMBNTencrypt(pass
, request
.data
.auth_crap
.chal
,
538 (uchar
*)request
.data
.auth_crap
.nt_resp
);
540 request
.data
.auth_crap
.lm_resp_len
= 24;
541 request
.data
.auth_crap
.nt_resp_len
= 24;
543 result
= winbindd_request(WINBINDD_PAM_AUTH_CRAP
, &request
, &response
);
545 /* Display response */
547 d_printf("challenge/response password authentication %s\n",
548 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed");
550 if (response
.data
.auth
.nt_status
)
551 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
552 response
.data
.auth
.nt_status_string
,
553 response
.data
.auth
.nt_status
,
554 response
.data
.auth
.error_string
);
556 return result
== NSS_STATUS_SUCCESS
;
559 /******************************************************************
560 create a winbindd user
561 ******************************************************************/
563 static BOOL
wbinfo_create_user(char *username
)
565 struct winbindd_request request
;
566 struct winbindd_response response
;
569 /* Send off request */
571 ZERO_STRUCT(request
);
572 ZERO_STRUCT(response
);
574 request
.flags
= WBFLAG_ALLOCATE_RID
;
575 fstrcpy(request
.data
.acct_mgt
.username
, username
);
577 result
= winbindd_request(WINBINDD_CREATE_USER
, &request
, &response
);
579 if ( result
== NSS_STATUS_SUCCESS
)
580 d_printf("New RID is %d\n", response
.data
.rid
);
582 return result
== NSS_STATUS_SUCCESS
;
585 /******************************************************************
586 remove a winbindd user
587 ******************************************************************/
589 static BOOL
wbinfo_delete_user(char *username
)
591 struct winbindd_request request
;
592 struct winbindd_response response
;
595 /* Send off request */
597 ZERO_STRUCT(request
);
598 ZERO_STRUCT(response
);
600 fstrcpy(request
.data
.acct_mgt
.username
, username
);
602 result
= winbindd_request(WINBINDD_DELETE_USER
, &request
, &response
);
604 return result
== NSS_STATUS_SUCCESS
;
607 /******************************************************************
608 create a winbindd group
609 ******************************************************************/
611 static BOOL
wbinfo_create_group(char *groupname
)
613 struct winbindd_request request
;
614 struct winbindd_response response
;
617 /* Send off request */
619 ZERO_STRUCT(request
);
620 ZERO_STRUCT(response
);
622 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
624 result
= winbindd_request(WINBINDD_CREATE_GROUP
, &request
, &response
);
626 return result
== NSS_STATUS_SUCCESS
;
629 /******************************************************************
630 remove a winbindd group
631 ******************************************************************/
633 static BOOL
wbinfo_delete_group(char *groupname
)
635 struct winbindd_request request
;
636 struct winbindd_response response
;
639 /* Send off request */
641 ZERO_STRUCT(request
);
642 ZERO_STRUCT(response
);
644 fstrcpy(request
.data
.acct_mgt
.groupname
, groupname
);
646 result
= winbindd_request(WINBINDD_DELETE_GROUP
, &request
, &response
);
648 return result
== NSS_STATUS_SUCCESS
;
651 /******************************************************************
652 parse a string in the form user:group
653 ******************************************************************/
655 static BOOL
parse_user_group( const char *string
, fstring user
, fstring group
)
662 if ( !(p
= strchr( string
, ':' )) )
668 fstrcpy( user
, string
);
674 /******************************************************************
675 add a user to a winbindd group
676 ******************************************************************/
678 static BOOL
wbinfo_add_user_to_group(char *string
)
680 struct winbindd_request request
;
681 struct winbindd_response response
;
684 /* Send off request */
686 ZERO_STRUCT(request
);
687 ZERO_STRUCT(response
);
689 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
690 request
.data
.acct_mgt
.groupname
))
692 d_printf("Can't parse user:group from %s\n", string
);
696 result
= winbindd_request(WINBINDD_ADD_USER_TO_GROUP
, &request
, &response
);
698 return result
== NSS_STATUS_SUCCESS
;
701 /******************************************************************
702 remove a user from a winbindd group
703 ******************************************************************/
705 static BOOL
wbinfo_remove_user_from_group(char *string
)
707 struct winbindd_request request
;
708 struct winbindd_response response
;
711 /* Send off request */
713 ZERO_STRUCT(request
);
714 ZERO_STRUCT(response
);
716 if ( !parse_user_group( string
, request
.data
.acct_mgt
.username
,
717 request
.data
.acct_mgt
.groupname
))
719 d_printf("Can't parse user:group from %s\n", string
);
723 result
= winbindd_request(WINBINDD_REMOVE_USER_FROM_GROUP
, &request
, &response
);
725 return result
== NSS_STATUS_SUCCESS
;
728 /* Print domain users */
730 static BOOL
print_domain_users(const char *domain
)
732 struct winbindd_request request
;
733 struct winbindd_response response
;
734 const char *extra_data
;
737 /* Send request to winbind daemon */
739 ZERO_STRUCT(request
);
740 ZERO_STRUCT(response
);
743 /* '.' is the special sign for our own domwin */
744 if ( strequal(domain
, ".") )
745 fstrcpy( request
.domain_name
, lp_workgroup() );
747 fstrcpy( request
.domain_name
, domain
);
750 if (winbindd_request(WINBINDD_LIST_USERS
, &request
, &response
) !=
754 /* Look through extra data */
756 if (!response
.extra_data
)
759 extra_data
= (const char *)response
.extra_data
;
761 while(next_token(&extra_data
, name
, ",", sizeof(fstring
)))
762 d_printf("%s\n", name
);
764 SAFE_FREE(response
.extra_data
);
769 /* Print domain groups */
771 static BOOL
print_domain_groups(const char *domain
)
773 struct winbindd_request request
;
774 struct winbindd_response response
;
775 const char *extra_data
;
778 ZERO_STRUCT(request
);
779 ZERO_STRUCT(response
);
782 if ( strequal(domain
, ".") )
783 fstrcpy( request
.domain_name
, lp_workgroup() );
785 fstrcpy( request
.domain_name
, domain
);
788 if (winbindd_request(WINBINDD_LIST_GROUPS
, &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 /* Set the authorised user for winbindd access in secrets.tdb */
809 static BOOL
wbinfo_set_auth_user(char *username
)
812 fstring user
, domain
;
814 /* Separate into user and password */
816 parse_wbinfo_domain_user(username
, domain
, user
);
818 password
= strchr(user
, '%');
824 char *thepass
= getpass("Password: ");
831 /* Store or remove DOMAIN\username%password in secrets.tdb */
837 if (!secrets_store(SECRETS_AUTH_USER
, user
,
839 d_fprintf(stderr
, "error storing username\n");
843 /* We always have a domain name added by the
844 parse_wbinfo_domain_user() function. */
846 if (!secrets_store(SECRETS_AUTH_DOMAIN
, domain
,
847 strlen(domain
) + 1)) {
848 d_fprintf(stderr
, "error storing domain name\n");
853 secrets_delete(SECRETS_AUTH_USER
);
854 secrets_delete(SECRETS_AUTH_DOMAIN
);
859 if (!secrets_store(SECRETS_AUTH_PASSWORD
, password
,
860 strlen(password
) + 1)) {
861 d_fprintf(stderr
, "error storing password\n");
866 secrets_delete(SECRETS_AUTH_PASSWORD
);
871 static void wbinfo_get_auth_user(void)
873 char *user
, *domain
, *password
;
875 /* Lift data from secrets file */
879 user
= secrets_fetch(SECRETS_AUTH_USER
, NULL
);
880 domain
= secrets_fetch(SECRETS_AUTH_DOMAIN
, NULL
);
881 password
= secrets_fetch(SECRETS_AUTH_PASSWORD
, NULL
);
883 if (!user
&& !domain
&& !password
) {
884 d_printf("No authorised user configured\n");
888 /* Pretty print authorised user info */
890 d_printf("%s%s%s%s%s\n", domain
? domain
: "", domain
? "\\" : "",
891 user
, password
? "%" : "", password
? password
: "");
898 static BOOL
wbinfo_ping(void)
902 result
= winbindd_request(WINBINDD_PING
, NULL
, NULL
);
904 /* Display response */
906 d_printf("Ping to winbindd %s on fd %d\n",
907 (result
== NSS_STATUS_SUCCESS
) ? "succeeded" : "failed", winbindd_fd
);
909 return result
== NSS_STATUS_SUCCESS
;
915 OPT_SET_AUTH_USER
= 1000,
922 int main(int argc
, char **argv
)
927 static char *string_arg
;
928 static char *opt_domain_name
;
932 struct poptOption long_options
[] = {
935 /* longName, shortName, argInfo, argPtr, value, descrip,
938 { "domain-users", 'u', POPT_ARG_NONE
, 0, 'u', "Lists all domain users", "domain"},
939 { "domain-groups", 'g', POPT_ARG_NONE
, 0, 'g', "Lists all domain groups", "domain" },
940 { "WINS-by-name", 'N', POPT_ARG_STRING
, &string_arg
, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
941 { "WINS-by-ip", 'I', POPT_ARG_STRING
, &string_arg
, 'I', "Converts IP address to NetBIOS name", "IP" },
942 { "name-to-sid", 'n', POPT_ARG_STRING
, &string_arg
, 'n', "Converts name to sid", "NAME" },
943 { "sid-to-name", 's', POPT_ARG_STRING
, &string_arg
, 's', "Converts sid to name", "SID" },
944 { "uid-to-sid", 'U', POPT_ARG_INT
, &int_arg
, 'U', "Converts uid to sid" , "UID" },
945 { "gid-to-sid", 'G', POPT_ARG_INT
, &int_arg
, 'G', "Converts gid to sid", "GID" },
946 { "sid-to-uid", 'S', POPT_ARG_STRING
, &string_arg
, 'S', "Converts sid to uid", "SID" },
947 { "sid-to-gid", 'Y', POPT_ARG_STRING
, &string_arg
, 'Y', "Converts sid to gid", "SID" },
948 { "create-user", 'c', POPT_ARG_STRING
, &string_arg
, 'c', "Create a local user account", "name" },
949 { "delete-user", 'x', POPT_ARG_STRING
, &string_arg
, 'x', "Delete a local user account", "name" },
950 { "create-group", 'C', POPT_ARG_STRING
, &string_arg
, 'C', "Create a local group", "name" },
951 { "delete-group", 'X', POPT_ARG_STRING
, &string_arg
, 'X', "Delete a local group", "name" },
952 { "add-to-group", 'o', POPT_ARG_STRING
, &string_arg
, 'o', "Add user to group", "user:group" },
953 { "del-from-group", 'O', POPT_ARG_STRING
, &string_arg
, 'O', "Remove user from group", "user:group" },
954 { "check-secret", 't', POPT_ARG_NONE
, 0, 't', "Check shared secret" },
955 { "trusted-domains", 'm', POPT_ARG_NONE
, 0, 'm', "List trusted domains" },
956 { "sequence", 0, POPT_ARG_NONE
, 0, OPT_SEQUENCE
, "Show sequence numbers of all domains" },
957 { "user-groups", 'r', POPT_ARG_STRING
, &string_arg
, 'r', "Get user groups", "USER" },
958 { "user-sids", 0, POPT_ARG_STRING
, &string_arg
, OPT_USERSIDS
, "Get user group sids for user SID", "SID" },
959 { "authenticate", 'a', POPT_ARG_STRING
, &string_arg
, 'a', "authenticate user", "user%password" },
960 { "set-auth-user", 0, POPT_ARG_STRING
, &string_arg
, OPT_SET_AUTH_USER
, "Store user and password used by winbindd (root only)", "user%password" },
961 { "get-auth-user", 0, POPT_ARG_NONE
, NULL
, OPT_GET_AUTH_USER
, "Retrieve user and password used by winbindd (root only)", NULL
},
962 { "ping", 'p', POPT_ARG_NONE
, 0, 'p', "Ping winbindd to see if it is alive" },
963 { "domain", 0, POPT_ARG_STRING
, &opt_domain_name
, OPT_DOMAIN_NAME
, "Define to the domain to restrict operation", "domain" },
968 /* Samba client initialisation */
970 if (!lp_load(dyn_CONFIGFILE
, True
, False
, False
)) {
971 d_fprintf(stderr
, "wbinfo: error opening config file %s. Error was %s\n",
972 dyn_CONFIGFILE
, strerror(errno
));
983 pc
= poptGetContext("wbinfo", argc
, (const char **)argv
, long_options
, 0);
985 /* Parse command line options */
988 poptPrintHelp(pc
, stderr
, 0);
992 while((opt
= poptGetNextOpt(pc
)) != -1) {
993 /* get the generic configuration parameters like --domain */
998 pc
= poptGetContext(NULL
, argc
, (const char **)argv
, long_options
,
999 POPT_CONTEXT_KEEP_FIRST
);
1001 while((opt
= poptGetNextOpt(pc
)) != -1) {
1004 if (!print_domain_users(opt_domain_name
)) {
1005 d_printf("Error looking up domain users\n");
1010 if (!print_domain_groups(opt_domain_name
)) {
1011 d_printf("Error looking up domain groups\n");
1016 if (!wbinfo_lookupsid(string_arg
)) {
1017 d_printf("Could not lookup sid %s\n", string_arg
);
1022 if (!wbinfo_lookupname(string_arg
)) {
1023 d_printf("Could not lookup name %s\n", string_arg
);
1028 if (!wbinfo_wins_byname(string_arg
)) {
1029 d_printf("Could not lookup WINS by name %s\n", string_arg
);
1034 if (!wbinfo_wins_byip(string_arg
)) {
1035 d_printf("Could not lookup WINS by IP %s\n", string_arg
);
1040 if (!wbinfo_uid_to_sid(int_arg
)) {
1041 d_printf("Could not convert uid %d to sid\n", int_arg
);
1046 if (!wbinfo_gid_to_sid(int_arg
)) {
1047 d_printf("Could not convert gid %d to sid\n",
1053 if (!wbinfo_sid_to_uid(string_arg
)) {
1054 d_printf("Could not convert sid %s to uid\n",
1060 if (!wbinfo_sid_to_gid(string_arg
)) {
1061 d_printf("Could not convert sid %s to gid\n",
1067 if (!wbinfo_check_secret()) {
1068 d_printf("Could not check secret\n");
1073 if (!wbinfo_list_domains()) {
1074 d_printf("Could not list trusted domains\n");
1079 if (!wbinfo_show_sequence(opt_domain_name
)) {
1080 d_printf("Could not show sequence numbers\n");
1085 if (!wbinfo_get_usergroups(string_arg
)) {
1086 d_printf("Could not get groups for user %s\n",
1092 if (!wbinfo_get_usersids(string_arg
)) {
1093 d_printf("Could not get group SIDs for user SID %s\n",
1099 BOOL got_error
= False
;
1101 if (!wbinfo_auth(string_arg
)) {
1102 d_printf("Could not authenticate user %s with "
1103 "plaintext password\n", string_arg
);
1107 if (!wbinfo_auth_crap(string_arg
)) {
1108 d_printf("Could not authenticate user %s with "
1109 "challenge/response\n", string_arg
);
1118 if ( !wbinfo_create_user(string_arg
) ) {
1119 d_printf("Could not create user account\n");
1124 if ( !wbinfo_create_group(string_arg
) ) {
1125 d_printf("Could not create group\n");
1130 if ( !wbinfo_add_user_to_group(string_arg
) ) {
1131 d_printf("Could not add user to group\n");
1136 if ( !wbinfo_remove_user_from_group(string_arg
) ) {
1137 d_printf("Could not remove user kfrom group\n");
1142 if ( !wbinfo_delete_user(string_arg
) ) {
1143 d_printf("Could not delete user account\n");
1148 if ( !wbinfo_delete_group(string_arg
) ) {
1149 d_printf("Could not delete group\n");
1154 if (!wbinfo_ping()) {
1155 d_printf("could not ping winbindd!\n");
1159 case OPT_SET_AUTH_USER
:
1160 wbinfo_set_auth_user(string_arg
);
1162 case OPT_GET_AUTH_USER
:
1163 wbinfo_get_auth_user();
1165 /* generic configuration options */
1166 case OPT_DOMAIN_NAME
:
1169 d_fprintf(stderr
, "Invalid option\n");
1170 poptPrintHelp(pc
, stderr
, 0);
1180 poptFreeContext(pc
);