trying to get HEAD building again. If you want the code
[Samba.git] / source / nsswitch / wbinfo.c
blobf53379937043fb1a80e3a91579196faf809f5b8e
1 /*
2 Unix SMB/CIFS implementation.
4 Winbind status program.
6 Copyright (C) Tim Potter 2000-2002
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.
24 #include "includes.h"
25 #include "winbindd.h"
26 #include "debug.h"
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_WINBIND
31 extern int winbindd_fd;
33 static char winbind_separator(void)
35 struct winbindd_response response;
36 static BOOL got_sep;
37 static char sep;
39 if (got_sep)
40 return sep;
42 ZERO_STRUCT(response);
44 /* Send off request */
46 if (winbindd_request(WINBINDD_INFO, NULL, &response) !=
47 NSS_STATUS_SUCCESS) {
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;
54 got_sep = True;
56 if (!sep) {
57 d_printf("winbind separator was NULL!\n");
58 /* HACK: (this module should not call lp_ funtions) */
59 sep = *lp_winbind_separator();
62 return sep;
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) !=
75 NSS_STATUS_SUCCESS) {
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,
92 fstring user)
95 char *p = strchr(domuser,winbind_separator());
97 if (!p) {
98 fstrcpy(user, domuser);
99 fstrcpy(domain, get_winbind_domain());
100 return True;
103 fstrcpy(user, p+1);
104 fstrcpy(domain, domuser);
105 domain[PTR_DIFF(p, domuser)] = 0;
106 strupper_m(domain);
108 return True;
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;
117 NSS_STATUS result;
118 int i;
120 ZERO_STRUCT(response);
122 /* Send request */
124 fstrcpy(request.data.username, user);
126 result = winbindd_request(WINBINDD_GETGROUPS, &request, &response);
128 if (result != NSS_STATUS_SUCCESS)
129 return False;
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);
136 return True;
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);
149 /* Send request */
151 fstrcpy(request.data.winsreq, name);
153 if (winbindd_request(WINBINDD_WINS_BYNAME, &request, &response) !=
154 NSS_STATUS_SUCCESS) {
155 return False;
158 /* Display response */
160 printf("%s\n", response.data.winsresp);
162 return True;
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);
175 /* Send request */
177 fstrcpy(request.data.winsreq, ip);
179 if (winbindd_request(WINBINDD_WINS_BYIP, &request, &response) !=
180 NSS_STATUS_SUCCESS) {
181 return False;
184 /* Display response */
186 printf("%s\n", response.data.winsresp);
188 return True;
191 /* List trusted domains */
193 static BOOL wbinfo_list_domains(void)
195 struct winbindd_response response;
196 fstring name;
198 ZERO_STRUCT(response);
200 /* Send request */
202 if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) !=
203 NSS_STATUS_SUCCESS)
204 return False;
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);
217 return True;
221 /* show sequence numbers */
222 static BOOL wbinfo_show_sequence(void)
224 struct winbindd_response response;
226 ZERO_STRUCT(response);
228 /* Send request */
230 if (winbindd_request(WINBINDD_SHOW_SEQUENCE, NULL, &response) !=
231 NSS_STATUS_SUCCESS)
232 return False;
234 /* Display response */
236 if (response.extra_data) {
237 char *extra_data = (char *)response.extra_data;
238 d_printf("%s", extra_data);
239 SAFE_FREE(response.extra_data);
242 return True;
245 /* Check trust account password */
247 static BOOL wbinfo_check_secret(void)
249 struct winbindd_response response;
250 NSS_STATUS result;
252 ZERO_STRUCT(response);
254 result = winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response);
256 d_printf("checking the trust secret via RPC calls %s\n",
257 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
259 if (result != NSS_STATUS_SUCCESS)
260 d_printf("error code was %s (0x%x)\n",
261 response.data.auth.nt_status_string,
262 response.data.auth.nt_status);
264 return result == NSS_STATUS_SUCCESS;
267 /* Convert uid to sid */
269 static BOOL wbinfo_uid_to_sid(uid_t uid)
271 struct winbindd_request request;
272 struct winbindd_response response;
274 ZERO_STRUCT(request);
275 ZERO_STRUCT(response);
277 /* Send request */
279 request.data.uid = uid;
281 if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) !=
282 NSS_STATUS_SUCCESS)
283 return False;
285 /* Display response */
287 d_printf("%s\n", response.data.sid.sid);
289 return True;
292 /* Convert gid to sid */
294 static BOOL wbinfo_gid_to_sid(gid_t gid)
296 struct winbindd_request request;
297 struct winbindd_response response;
299 ZERO_STRUCT(request);
300 ZERO_STRUCT(response);
302 /* Send request */
304 request.data.gid = gid;
306 if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) !=
307 NSS_STATUS_SUCCESS)
308 return False;
310 /* Display response */
312 d_printf("%s\n", response.data.sid.sid);
314 return True;
317 /* Convert sid to uid */
319 static BOOL wbinfo_sid_to_uid(char *sid)
321 struct winbindd_request request;
322 struct winbindd_response response;
324 ZERO_STRUCT(request);
325 ZERO_STRUCT(response);
327 /* Send request */
329 fstrcpy(request.data.sid, sid);
331 if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) !=
332 NSS_STATUS_SUCCESS)
333 return False;
335 /* Display response */
337 d_printf("%d\n", (int)response.data.uid);
339 return True;
342 static BOOL wbinfo_sid_to_gid(char *sid)
344 struct winbindd_request request;
345 struct winbindd_response response;
347 ZERO_STRUCT(request);
348 ZERO_STRUCT(response);
350 /* Send request */
352 fstrcpy(request.data.sid, sid);
354 if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) !=
355 NSS_STATUS_SUCCESS)
356 return False;
358 /* Display response */
360 d_printf("%d\n", (int)response.data.gid);
362 return True;
365 /* Convert sid to string */
367 static BOOL wbinfo_lookupsid(char *sid)
369 struct winbindd_request request;
370 struct winbindd_response response;
372 ZERO_STRUCT(request);
373 ZERO_STRUCT(response);
375 /* Send off request */
377 fstrcpy(request.data.sid, sid);
379 if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) !=
380 NSS_STATUS_SUCCESS)
381 return False;
383 /* Display response */
385 d_printf("%s%c%s %d\n", response.data.name.dom_name,
386 winbind_separator(), response.data.name.name,
387 response.data.name.type);
389 return True;
392 /* Convert string to sid */
394 static BOOL wbinfo_lookupname(char *name)
396 struct winbindd_request request;
397 struct winbindd_response response;
399 /* Send off request */
401 ZERO_STRUCT(request);
402 ZERO_STRUCT(response);
404 parse_wbinfo_domain_user(name, request.data.name.dom_name,
405 request.data.name.name);
407 if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) !=
408 NSS_STATUS_SUCCESS)
409 return False;
411 /* Display response */
413 d_printf("%s %d\n", response.data.sid.sid, response.data.sid.type);
415 return True;
418 /* Authenticate a user with a plaintext password */
420 static BOOL wbinfo_auth(char *username)
422 struct winbindd_request request;
423 struct winbindd_response response;
424 NSS_STATUS result;
425 char *p;
427 /* Send off request */
429 ZERO_STRUCT(request);
430 ZERO_STRUCT(response);
432 p = strchr(username, '%');
434 if (p) {
435 *p = 0;
436 fstrcpy(request.data.auth.user, username);
437 fstrcpy(request.data.auth.pass, p + 1);
438 *p = '%';
439 } else
440 fstrcpy(request.data.auth.user, username);
442 result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);
444 /* Display response */
446 d_printf("plaintext password authentication %s\n",
447 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
449 if (response.data.auth.nt_status)
450 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
451 response.data.auth.nt_status_string,
452 response.data.auth.nt_status,
453 response.data.auth.error_string);
455 return result == NSS_STATUS_SUCCESS;
458 /* Authenticate a user with a challenge/response */
460 static BOOL wbinfo_auth_crap(char *username)
462 struct winbindd_request request;
463 struct winbindd_response response;
464 NSS_STATUS result;
465 fstring name_user;
466 fstring name_domain;
467 fstring pass;
468 char *p;
470 /* Send off request */
472 ZERO_STRUCT(request);
473 ZERO_STRUCT(response);
475 p = strchr(username, '%');
477 if (p) {
478 *p = 0;
479 fstrcpy(pass, p + 1);
482 parse_wbinfo_domain_user(username, name_domain, name_user);
484 fstrcpy(request.data.auth_crap.user, name_user);
486 fstrcpy(request.data.auth_crap.domain, name_domain);
488 generate_random_buffer(request.data.auth_crap.chal, 8, False);
490 SMBencrypt(pass, request.data.auth_crap.chal,
491 (uchar *)request.data.auth_crap.lm_resp);
492 SMBNTencrypt(pass, request.data.auth_crap.chal,
493 (uchar *)request.data.auth_crap.nt_resp);
495 request.data.auth_crap.lm_resp_len = 24;
496 request.data.auth_crap.nt_resp_len = 24;
498 result = winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response);
500 /* Display response */
502 d_printf("challenge/response password authentication %s\n",
503 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
505 if (response.data.auth.nt_status)
506 d_printf("error code was %s (0x%x)\nerror messsage was: %s\n",
507 response.data.auth.nt_status_string,
508 response.data.auth.nt_status,
509 response.data.auth.error_string);
511 return result == NSS_STATUS_SUCCESS;
514 /******************************************************************
515 create a winbindd user
516 ******************************************************************/
518 static BOOL wbinfo_create_user(char *username)
520 struct winbindd_request request;
521 struct winbindd_response response;
522 NSS_STATUS result;
524 /* Send off request */
526 ZERO_STRUCT(request);
527 ZERO_STRUCT(response);
529 request.flags = WBFLAG_ALLOCATE_RID;
530 fstrcpy(request.data.acct_mgt.username, username);
532 result = winbindd_request(WINBINDD_CREATE_USER, &request, &response);
534 if ( result == NSS_STATUS_SUCCESS )
535 d_printf("New RID is %d\n", response.data.rid);
537 return result == NSS_STATUS_SUCCESS;
540 /******************************************************************
541 remove a winbindd user
542 ******************************************************************/
544 static BOOL wbinfo_delete_user(char *username)
546 struct winbindd_request request;
547 struct winbindd_response response;
548 NSS_STATUS result;
550 /* Send off request */
552 ZERO_STRUCT(request);
553 ZERO_STRUCT(response);
555 fstrcpy(request.data.acct_mgt.username, username);
557 result = winbindd_request(WINBINDD_DELETE_USER, &request, &response);
559 return result == NSS_STATUS_SUCCESS;
562 /******************************************************************
563 create a winbindd group
564 ******************************************************************/
566 static BOOL wbinfo_create_group(char *groupname)
568 struct winbindd_request request;
569 struct winbindd_response response;
570 NSS_STATUS result;
572 /* Send off request */
574 ZERO_STRUCT(request);
575 ZERO_STRUCT(response);
577 fstrcpy(request.data.acct_mgt.groupname, groupname);
579 result = winbindd_request(WINBINDD_CREATE_GROUP, &request, &response);
581 return result == NSS_STATUS_SUCCESS;
584 /******************************************************************
585 remove a winbindd group
586 ******************************************************************/
588 static BOOL wbinfo_delete_group(char *groupname)
590 struct winbindd_request request;
591 struct winbindd_response response;
592 NSS_STATUS result;
594 /* Send off request */
596 ZERO_STRUCT(request);
597 ZERO_STRUCT(response);
599 fstrcpy(request.data.acct_mgt.groupname, groupname);
601 result = winbindd_request(WINBINDD_DELETE_GROUP, &request, &response);
603 return result == NSS_STATUS_SUCCESS;
606 /******************************************************************
607 parse a string in the form user:group
608 ******************************************************************/
610 static BOOL parse_user_group( const char *string, fstring user, fstring group )
612 char *p;
614 if ( !string )
615 return False;
617 if ( !(p = strchr( string, ':' )) )
618 return False;
620 *p = '\0';
621 p++;
623 fstrcpy( user, string );
624 fstrcpy( group, p );
626 return True;
629 /******************************************************************
630 add a user to a winbindd group
631 ******************************************************************/
633 static BOOL wbinfo_add_user_to_group(char *string)
635 struct winbindd_request request;
636 struct winbindd_response response;
637 NSS_STATUS result;
639 /* Send off request */
641 ZERO_STRUCT(request);
642 ZERO_STRUCT(response);
644 if ( !parse_user_group( string, request.data.acct_mgt.username,
645 request.data.acct_mgt.groupname))
647 d_printf("Can't parse user:group from %s\n", string);
648 return False;
651 result = winbindd_request(WINBINDD_ADD_USER_TO_GROUP, &request, &response);
653 return result == NSS_STATUS_SUCCESS;
656 /******************************************************************
657 remove a user from a winbindd group
658 ******************************************************************/
660 static BOOL wbinfo_remove_user_from_group(char *string)
662 struct winbindd_request request;
663 struct winbindd_response response;
664 NSS_STATUS result;
666 /* Send off request */
668 ZERO_STRUCT(request);
669 ZERO_STRUCT(response);
671 if ( !parse_user_group( string, request.data.acct_mgt.username,
672 request.data.acct_mgt.groupname))
674 d_printf("Can't parse user:group from %s\n", string);
675 return False;
678 result = winbindd_request(WINBINDD_REMOVE_USER_FROM_GROUP, &request, &response);
680 return result == NSS_STATUS_SUCCESS;
683 /* Print domain users */
685 static BOOL print_domain_users(void)
687 struct winbindd_response response;
688 const char *extra_data;
689 fstring name;
691 /* Send request to winbind daemon */
693 ZERO_STRUCT(response);
695 if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) !=
696 NSS_STATUS_SUCCESS)
697 return False;
699 /* Look through extra data */
701 if (!response.extra_data)
702 return False;
704 extra_data = (const char *)response.extra_data;
706 while(next_token(&extra_data, name, ",", sizeof(fstring)))
707 d_printf("%s\n", name);
709 SAFE_FREE(response.extra_data);
711 return True;
714 /* Print domain groups */
716 static BOOL print_domain_groups(void)
718 struct winbindd_response response;
719 const char *extra_data;
720 fstring name;
722 ZERO_STRUCT(response);
724 if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) !=
725 NSS_STATUS_SUCCESS)
726 return False;
728 /* Look through extra data */
730 if (!response.extra_data)
731 return False;
733 extra_data = (const char *)response.extra_data;
735 while(next_token(&extra_data, name, ",", sizeof(fstring)))
736 d_printf("%s\n", name);
738 SAFE_FREE(response.extra_data);
740 return True;
743 /* Set the authorised user for winbindd access in secrets.tdb */
745 static BOOL wbinfo_set_auth_user(char *username)
747 char *password;
748 fstring user, domain;
750 /* Separate into user and password */
752 parse_wbinfo_domain_user(username, domain, user);
754 password = strchr(user, '%');
756 if (password) {
757 *password = 0;
758 password++;
759 } else
760 password = "";
762 /* Store or remove DOMAIN\username%password in secrets.tdb */
764 secrets_init();
766 if (user[0]) {
768 if (!secrets_store(SECRETS_AUTH_USER, user,
769 strlen(user) + 1)) {
770 d_fprintf(stderr, "error storing username\n");
771 return False;
774 /* We always have a domain name added by the
775 parse_wbinfo_domain_user() function. */
777 if (!secrets_store(SECRETS_AUTH_DOMAIN, domain,
778 strlen(domain) + 1)) {
779 d_fprintf(stderr, "error storing domain name\n");
780 return False;
783 } else {
784 secrets_delete(SECRETS_AUTH_USER);
785 secrets_delete(SECRETS_AUTH_DOMAIN);
788 if (password[0]) {
790 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
791 strlen(password) + 1)) {
792 d_fprintf(stderr, "error storing password\n");
793 return False;
796 } else
797 secrets_delete(SECRETS_AUTH_PASSWORD);
799 return True;
802 static void wbinfo_get_auth_user(void)
804 char *user, *domain, *password;
806 /* Lift data from secrets file */
808 secrets_init();
810 user = secrets_fetch(SECRETS_AUTH_USER, NULL);
811 domain = secrets_fetch(SECRETS_AUTH_DOMAIN, NULL);
812 password = secrets_fetch(SECRETS_AUTH_PASSWORD, NULL);
814 if (!user && !domain && !password) {
815 d_printf("No authorised user configured\n");
816 return;
819 /* Pretty print authorised user info */
821 d_printf("%s%s%s%s%s\n", domain ? domain : "", domain ? "\\" : "",
822 user, password ? "%" : "", password ? password : "");
824 SAFE_FREE(user);
825 SAFE_FREE(domain);
826 SAFE_FREE(password);
829 static BOOL wbinfo_ping(void)
831 NSS_STATUS result;
833 result = winbindd_request(WINBINDD_PING, NULL, NULL);
835 /* Display response */
837 d_printf("Ping to winbindd %s on fd %d\n",
838 (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed", winbindd_fd);
840 return result == NSS_STATUS_SUCCESS;
843 /* Main program */
845 enum {
846 OPT_SET_AUTH_USER = 1000,
847 OPT_GET_AUTH_USER,
848 OPT_SEQUENCE
851 int main(int argc, char **argv)
853 int opt;
855 poptContext pc;
856 static char *string_arg;
857 static int int_arg;
858 BOOL got_command = False;
859 int result = 1;
861 struct poptOption long_options[] = {
862 POPT_AUTOHELP
864 /* longName, shortName, argInfo, argPtr, value, descrip,
865 argDesc */
867 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u', "Lists all domain users"},
868 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g', "Lists all domain groups" },
869 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N', "Converts NetBIOS name to IP", "NETBIOS-NAME" },
870 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I', "Converts IP address to NetBIOS name", "IP" },
871 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n', "Converts name to sid", "NAME" },
872 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's', "Converts sid to name", "SID" },
873 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U', "Converts uid to sid" , "UID" },
874 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G', "Converts gid to sid", "GID" },
875 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S', "Converts sid to uid", "SID" },
876 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y', "Converts sid to gid", "SID" },
877 { "create-user", 'c', POPT_ARG_STRING, &string_arg, 'c', "Create a local user account", "name" },
878 { "delete-user", 'x', POPT_ARG_STRING, &string_arg, 'x', "Delete a local user account", "name" },
879 { "create-group", 'C', POPT_ARG_STRING, &string_arg, 'C', "Create a local group", "name" },
880 { "delete-group", 'X', POPT_ARG_STRING, &string_arg, 'X', "Delete a local group", "name" },
881 { "add-to-group", 'o', POPT_ARG_STRING, &string_arg, 'o', "Add user to group", "user:group" },
882 { "del-from-group", 'O', POPT_ARG_STRING, &string_arg, 'O', "Remove user from group", "user:group" },
883 { "check-secret", 't', POPT_ARG_NONE, 0, 't', "Check shared secret" },
884 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm', "List trusted domains" },
885 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE, "Show sequence numbers of all domains" },
886 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r', "Get user groups", "USER" },
887 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a', "authenticate user", "user%password" },
888 { "set-auth-user", 0, POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER, "Store user and password used by winbindd (root only)", "user%password" },
889 { "get-auth-user", 0, POPT_ARG_NONE, NULL, OPT_GET_AUTH_USER, "Retrieve user and password used by winbindd (root only)", NULL },
890 { "ping", 'p', POPT_ARG_NONE, 0, 'p', "Ping winbindd to see if it is alive" },
891 POPT_COMMON_VERSION
892 POPT_TABLEEND
895 /* Samba client initialisation */
897 if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
898 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
899 dyn_CONFIGFILE, strerror(errno));
900 exit(1);
903 if (!init_names())
904 return 1;
906 load_interfaces();
908 /* Parse options */
910 pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
912 /* Parse command line options */
914 if (argc == 1) {
915 poptPrintHelp(pc, stderr, 0);
916 return 1;
919 while((opt = poptGetNextOpt(pc)) != -1) {
920 if (got_command) {
921 d_fprintf(stderr, "No more than one command may be specified at once.\n");
922 exit(1);
924 got_command = True;
927 poptFreeContext(pc);
929 pc = poptGetContext(NULL, argc, (const char **)argv, long_options,
930 POPT_CONTEXT_KEEP_FIRST);
932 while((opt = poptGetNextOpt(pc)) != -1) {
933 switch (opt) {
934 case 'u':
935 if (!print_domain_users()) {
936 d_printf("Error looking up domain users\n");
937 goto done;
939 break;
940 case 'g':
941 if (!print_domain_groups()) {
942 d_printf("Error looking up domain groups\n");
943 goto done;
945 break;
946 case 's':
947 if (!wbinfo_lookupsid(string_arg)) {
948 d_printf("Could not lookup sid %s\n", string_arg);
949 goto done;
951 break;
952 case 'n':
953 if (!wbinfo_lookupname(string_arg)) {
954 d_printf("Could not lookup name %s\n", string_arg);
955 goto done;
957 break;
958 case 'N':
959 if (!wbinfo_wins_byname(string_arg)) {
960 d_printf("Could not lookup WINS by name %s\n", string_arg);
961 goto done;
963 break;
964 case 'I':
965 if (!wbinfo_wins_byip(string_arg)) {
966 d_printf("Could not lookup WINS by IP %s\n", string_arg);
967 goto done;
969 break;
970 case 'U':
971 if (!wbinfo_uid_to_sid(int_arg)) {
972 d_printf("Could not convert uid %d to sid\n", int_arg);
973 goto done;
975 break;
976 case 'G':
977 if (!wbinfo_gid_to_sid(int_arg)) {
978 d_printf("Could not convert gid %d to sid\n",
979 int_arg);
980 goto done;
982 break;
983 case 'S':
984 if (!wbinfo_sid_to_uid(string_arg)) {
985 d_printf("Could not convert sid %s to uid\n",
986 string_arg);
987 goto done;
989 break;
990 case 'Y':
991 if (!wbinfo_sid_to_gid(string_arg)) {
992 d_printf("Could not convert sid %s to gid\n",
993 string_arg);
994 goto done;
996 break;
997 case 't':
998 if (!wbinfo_check_secret()) {
999 d_printf("Could not check secret\n");
1000 goto done;
1002 break;
1003 case 'm':
1004 if (!wbinfo_list_domains()) {
1005 d_printf("Could not list trusted domains\n");
1006 goto done;
1008 break;
1009 case OPT_SEQUENCE:
1010 if (!wbinfo_show_sequence()) {
1011 d_printf("Could not show sequence numbers\n");
1012 goto done;
1014 break;
1015 case 'r':
1016 if (!wbinfo_get_usergroups(string_arg)) {
1017 d_printf("Could not get groups for user %s\n",
1018 string_arg);
1019 goto done;
1021 break;
1022 case 'a': {
1023 BOOL got_error = False;
1025 if (!wbinfo_auth(string_arg)) {
1026 d_printf("Could not authenticate user %s with "
1027 "plaintext password\n", string_arg);
1028 got_error = True;
1031 if (!wbinfo_auth_crap(string_arg)) {
1032 d_printf("Could not authenticate user %s with "
1033 "challenge/response\n", string_arg);
1034 got_error = True;
1037 if (got_error)
1038 goto done;
1039 break;
1041 case 'c':
1042 if ( !wbinfo_create_user(string_arg) ) {
1043 d_printf("Could not create user account\n");
1044 goto done;
1046 break;
1047 case 'C':
1048 if ( !wbinfo_create_group(string_arg) ) {
1049 d_printf("Could not create group\n");
1050 goto done;
1052 break;
1053 case 'o':
1054 if ( !wbinfo_add_user_to_group(string_arg) ) {
1055 d_printf("Could not add user to group\n");
1056 goto done;
1058 break;
1059 case 'O':
1060 if ( !wbinfo_remove_user_from_group(string_arg) ) {
1061 d_printf("Could not remove user kfrom group\n");
1062 goto done;
1064 break;
1065 case 'x':
1066 if ( !wbinfo_delete_user(string_arg) ) {
1067 d_printf("Could not delete user account\n");
1068 goto done;
1070 break;
1071 case 'X':
1072 if ( !wbinfo_delete_group(string_arg) ) {
1073 d_printf("Could not delete group\n");
1074 goto done;
1076 break;
1077 case 'P':
1078 if (!wbinfo_ping()) {
1079 d_printf("could not ping winbindd!\n");
1080 goto done;
1082 break;
1083 case OPT_SET_AUTH_USER:
1084 wbinfo_set_auth_user(string_arg);
1085 break;
1086 case OPT_GET_AUTH_USER:
1087 wbinfo_get_auth_user();
1088 break;
1089 default:
1090 d_fprintf(stderr, "Invalid option\n");
1091 poptPrintHelp(pc, stderr, 0);
1092 goto done;
1096 result = 0;
1098 /* Exit code */
1100 done:
1101 poptFreeContext(pc);
1102 return result;