This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[samba.git] / source3 / nsswitch / wbinfo.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Winbind status program.
5
6    Copyright (C) Tim Potter      2000-2002
7    Copyright (C) Andrew Bartlett 2002
8    
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.
13    
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.
18    
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.
22 */
23
24 #include "includes.h"
25 #include "winbindd.h"
26 #include "debug.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_WINBIND
30
31 /* Prototypes from common.h */
32
33 NSS_STATUS winbindd_request(int req_type, 
34                             struct winbindd_request *request,
35                             struct winbindd_response *response);
36
37 static char winbind_separator(void)
38 {
39         struct winbindd_response response;
40         static BOOL got_sep;
41         static char sep;
42
43         if (got_sep)
44                 return sep;
45
46         ZERO_STRUCT(response);
47
48         /* Send off request */
49
50         if (winbindd_request(WINBINDD_INFO, NULL, &response) !=
51             NSS_STATUS_SUCCESS) {
52                 d_printf("could not obtain winbind separator!\n");
53                 /* HACK: (this module should not call lp_ funtions) */
54                 return *lp_winbind_separator();
55         }
56
57         sep = response.data.info.winbind_separator;
58         got_sep = True;
59
60         if (!sep) {
61                 d_printf("winbind separator was NULL!\n");
62                 /* HACK: (this module should not call lp_ funtions) */
63                 sep = *lp_winbind_separator();
64         }
65         
66         return sep;
67 }
68
69 static char *get_winbind_domain(void)
70 {
71         struct winbindd_response response;
72         static fstring winbind_domain;
73
74         ZERO_STRUCT(response);
75
76         /* Send off request */
77
78         if (winbindd_request(WINBINDD_DOMAIN_NAME, NULL, &response) !=
79             NSS_STATUS_SUCCESS) {
80                 d_printf("could not obtain winbind domain name!\n");
81                 
82                 /* HACK: (this module should not call lp_ funtions) */
83                 return lp_workgroup();
84         }
85
86         fstrcpy(winbind_domain, response.data.domain_name);
87
88         return winbind_domain;
89
90 }
91
92 /* Copy of parse_domain_user from winbindd_util.c.  Parse a string of the
93    form DOMAIN/user into a domain and a user */
94
95 static BOOL parse_wbinfo_domain_user(const char *domuser, fstring domain, 
96                                      fstring user)
97 {
98
99         char *p = strchr(domuser,winbind_separator());
100
101         if (!p) {
102                 fstrcpy(user, domuser);
103                 fstrcpy(domain, get_winbind_domain());
104                 return True;
105         }
106         
107         fstrcpy(user, p+1);
108         fstrcpy(domain, domuser);
109         domain[PTR_DIFF(p, domuser)] = 0;
110         strupper(domain);
111
112         return True;
113 }
114
115 /* List groups a user is a member of */
116
117 static BOOL wbinfo_get_usergroups(char *user)
118 {
119         struct winbindd_request request;
120         struct winbindd_response response;
121         NSS_STATUS result;
122         int i;
123         
124         ZERO_STRUCT(response);
125
126         /* Send request */
127
128         fstrcpy(request.data.username, user);
129
130         result = winbindd_request(WINBINDD_GETGROUPS, &request, &response);
131
132         if (result != NSS_STATUS_SUCCESS)
133                 return False;
134
135         for (i = 0; i < response.data.num_entries; i++)
136                 d_printf("%d\n", (int)((gid_t *)response.extra_data)[i]);
137
138         SAFE_FREE(response.extra_data);
139
140         return True;
141 }
142
143 /* Convert NetBIOS name to IP */
144
145 static BOOL wbinfo_wins_byname(char *name)
146 {
147         struct winbindd_request request;
148         struct winbindd_response response;
149
150         ZERO_STRUCT(request);
151         ZERO_STRUCT(response);
152
153         /* Send request */
154
155         fstrcpy(request.data.winsreq, name);
156
157         if (winbindd_request(WINBINDD_WINS_BYNAME, &request, &response) !=
158             NSS_STATUS_SUCCESS) {
159                 return False;
160         }
161
162         /* Display response */
163
164         printf("%s\n", response.data.winsresp);
165
166         return True;
167 }
168
169 /* Convert IP to NetBIOS name */
170
171 static BOOL wbinfo_wins_byip(char *ip)
172 {
173         struct winbindd_request request;
174         struct winbindd_response response;
175
176         ZERO_STRUCT(request);
177         ZERO_STRUCT(response);
178
179         /* Send request */
180
181         fstrcpy(request.data.winsreq, ip);
182
183         if (winbindd_request(WINBINDD_WINS_BYIP, &request, &response) !=
184             NSS_STATUS_SUCCESS) {
185                 return False;
186         }
187
188         /* Display response */
189
190         printf("%s\n", response.data.winsresp);
191
192         return True;
193 }
194
195 /* List trusted domains */
196
197 static BOOL wbinfo_list_domains(void)
198 {
199         struct winbindd_response response;
200         fstring name;
201
202         ZERO_STRUCT(response);
203
204         /* Send request */
205
206         if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) !=
207             NSS_STATUS_SUCCESS)
208                 return False;
209
210         /* Display response */
211
212         if (response.extra_data) {
213                 char *extra_data = (char *)response.extra_data;
214
215                 while(next_token(&extra_data, name, ",", sizeof(fstring)))
216                         d_printf("%s\n", name);
217
218                 SAFE_FREE(response.extra_data);
219         }
220
221         return True;
222 }
223
224
225 /* show sequence numbers */
226 static BOOL wbinfo_show_sequence(void)
227 {
228         struct winbindd_response response;
229
230         ZERO_STRUCT(response);
231
232         /* Send request */
233
234         if (winbindd_request(WINBINDD_SHOW_SEQUENCE, NULL, &response) !=
235             NSS_STATUS_SUCCESS)
236                 return False;
237
238         /* Display response */
239
240         if (response.extra_data) {
241                 char *extra_data = (char *)response.extra_data;
242                 d_printf("%s", extra_data);
243                 SAFE_FREE(response.extra_data);
244         }
245
246         return True;
247 }
248
249 /* Check trust account password */
250
251 static BOOL wbinfo_check_secret(void)
252 {
253         struct winbindd_response response;
254         NSS_STATUS result;
255
256         ZERO_STRUCT(response);
257
258         result = winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response) ==
259                 NSS_STATUS_SUCCESS;
260                 
261         d_printf("checking the trust secret via RPC calls %s\n", 
262                  (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
263
264         if (result != NSS_STATUS_SUCCESS)       
265                 d_printf("error code was %s (0x%x)\n", 
266                          response.data.auth.nt_status_string, 
267                          response.data.auth.nt_status);
268         
269         return result == NSS_STATUS_SUCCESS;    
270 }
271
272 /* Convert uid to sid */
273
274 static BOOL wbinfo_uid_to_sid(uid_t uid)
275 {
276         struct winbindd_request request;
277         struct winbindd_response response;
278
279         ZERO_STRUCT(request);
280         ZERO_STRUCT(response);
281
282         /* Send request */
283
284         request.data.uid = uid;
285
286         if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) !=
287             NSS_STATUS_SUCCESS)
288                 return False;
289
290         /* Display response */
291
292         d_printf("%s\n", response.data.sid.sid);
293
294         return True;
295 }
296
297 /* Convert gid to sid */
298
299 static BOOL wbinfo_gid_to_sid(gid_t gid)
300 {
301         struct winbindd_request request;
302         struct winbindd_response response;
303
304         ZERO_STRUCT(request);
305         ZERO_STRUCT(response);
306
307         /* Send request */
308
309         request.data.gid = gid;
310
311         if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) !=
312             NSS_STATUS_SUCCESS)
313                 return False;
314
315         /* Display response */
316
317         d_printf("%s\n", response.data.sid.sid);
318
319         return True;
320 }
321
322 /* Convert sid to uid */
323
324 static BOOL wbinfo_sid_to_uid(char *sid)
325 {
326         struct winbindd_request request;
327         struct winbindd_response response;
328
329         ZERO_STRUCT(request);
330         ZERO_STRUCT(response);
331
332         /* Send request */
333
334         fstrcpy(request.data.sid, sid);
335
336         if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) !=
337             NSS_STATUS_SUCCESS)
338                 return False;
339
340         /* Display response */
341
342         d_printf("%d\n", (int)response.data.uid);
343
344         return True;
345 }
346
347 static BOOL wbinfo_sid_to_gid(char *sid)
348 {
349         struct winbindd_request request;
350         struct winbindd_response response;
351
352         ZERO_STRUCT(request);
353         ZERO_STRUCT(response);
354
355         /* Send request */
356
357         fstrcpy(request.data.sid, sid);
358
359         if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) !=
360             NSS_STATUS_SUCCESS)
361                 return False;
362
363         /* Display response */
364
365         d_printf("%d\n", (int)response.data.gid);
366
367         return True;
368 }
369
370 /* Convert sid to string */
371
372 static BOOL wbinfo_lookupsid(char *sid)
373 {
374         struct winbindd_request request;
375         struct winbindd_response response;
376
377         ZERO_STRUCT(request);
378         ZERO_STRUCT(response);
379
380         /* Send off request */
381
382         fstrcpy(request.data.sid, sid);
383
384         if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) !=
385             NSS_STATUS_SUCCESS)
386                 return False;
387
388         /* Display response */
389
390         d_printf("%s%c%s %d\n", response.data.name.dom_name, 
391                  winbind_separator(), response.data.name.name, 
392                  response.data.name.type);
393
394         return True;
395 }
396
397 /* Convert string to sid */
398
399 static BOOL wbinfo_lookupname(char *name)
400 {
401         struct winbindd_request request;
402         struct winbindd_response response;
403
404         /* Send off request */
405
406         ZERO_STRUCT(request);
407         ZERO_STRUCT(response);
408
409         parse_wbinfo_domain_user(name, request.data.name.dom_name, 
410                                  request.data.name.name);
411
412         if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) !=
413             NSS_STATUS_SUCCESS)
414                 return False;
415
416         /* Display response */
417
418         d_printf("%s %d\n", response.data.sid.sid, response.data.sid.type);
419
420         return True;
421 }
422
423 /* Authenticate a user with a plaintext password */
424
425 static BOOL wbinfo_auth(char *username)
426 {
427         struct winbindd_request request;
428         struct winbindd_response response;
429         NSS_STATUS result;
430         char *p;
431
432         /* Send off request */
433
434         ZERO_STRUCT(request);
435         ZERO_STRUCT(response);
436
437         p = strchr(username, '%');
438
439         if (p) {
440                 *p = 0;
441                 fstrcpy(request.data.auth.user, username);
442                 fstrcpy(request.data.auth.pass, p + 1);
443                 *p = '%';
444         } else
445                 fstrcpy(request.data.auth.user, username);
446
447         result = winbindd_request(WINBINDD_PAM_AUTH, &request, &response);
448
449         /* Display response */
450
451         d_printf("plaintext password authentication %s\n", 
452                (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
453
454         d_printf("error code was %s (0x%x)\n", 
455                  response.data.auth.nt_status_string, 
456                  response.data.auth.nt_status);
457
458         return result == NSS_STATUS_SUCCESS;
459 }
460
461 /* Authenticate a user with a challenge/response */
462
463 static BOOL wbinfo_auth_crap(char *username)
464 {
465         struct winbindd_request request;
466         struct winbindd_response response;
467         NSS_STATUS result;
468         fstring name_user;
469         fstring name_domain;
470         fstring pass;
471         char *p;
472
473         /* Send off request */
474
475         ZERO_STRUCT(request);
476         ZERO_STRUCT(response);
477
478         p = strchr(username, '%');
479
480         if (p) {
481                 *p = 0;
482                 fstrcpy(pass, p + 1);
483         }
484                 
485         parse_wbinfo_domain_user(username, name_domain, name_user);
486
487         fstrcpy(request.data.auth_crap.user, name_user);
488
489         fstrcpy(request.data.auth_crap.domain, name_domain);
490
491         generate_random_buffer(request.data.auth_crap.chal, 8, False);
492         
493         SMBencrypt((uchar *)pass, request.data.auth_crap.chal, 
494                    (uchar *)request.data.auth_crap.lm_resp);
495         SMBNTencrypt((uchar *)pass, request.data.auth_crap.chal,
496                      (uchar *)request.data.auth_crap.nt_resp);
497
498         request.data.auth_crap.lm_resp_len = 24;
499         request.data.auth_crap.nt_resp_len = 24;
500
501         result = winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response);
502
503         /* Display response */
504
505         d_printf("challenge/response password authentication %s\n", 
506                (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
507
508         d_printf("error code was %s (0x%x)\n", 
509                response.data.auth.nt_status_string, 
510                response.data.auth.nt_status);
511
512         return result == NSS_STATUS_SUCCESS;
513 }
514
515 /* Print domain users */
516
517 static BOOL print_domain_users(void)
518 {
519         struct winbindd_response response;
520         char *extra_data;
521         fstring name;
522
523         /* Send request to winbind daemon */
524
525         ZERO_STRUCT(response);
526
527         if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) !=
528             NSS_STATUS_SUCCESS)
529                 return False;
530
531         /* Look through extra data */
532
533         if (!response.extra_data)
534                 return False;
535
536         extra_data = (char *)response.extra_data;
537
538         while(next_token(&extra_data, name, ",", sizeof(fstring)))
539                 d_printf("%s\n", name);
540         
541         SAFE_FREE(response.extra_data);
542
543         return True;
544 }
545
546 /* Print domain groups */
547
548 static BOOL print_domain_groups(void)
549 {
550         struct winbindd_response response;
551         char *extra_data;
552         fstring name;
553
554         ZERO_STRUCT(response);
555
556         if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) !=
557             NSS_STATUS_SUCCESS)
558                 return False;
559
560         /* Look through extra data */
561
562         if (!response.extra_data)
563                 return False;
564
565         extra_data = (char *)response.extra_data;
566
567         while(next_token(&extra_data, name, ",", sizeof(fstring)))
568                 d_printf("%s\n", name);
569
570         SAFE_FREE(response.extra_data);
571         
572         return True;
573 }
574
575 /* Set the authorised user for winbindd access in secrets.tdb */
576
577 static BOOL wbinfo_set_auth_user(char *username)
578 {
579         char *password;
580         fstring user, domain;
581
582         /* Separate into user and password */
583
584         parse_wbinfo_domain_user(username, domain, user);
585
586         password = strchr(user, '%');
587
588         if (password) {
589                 *password = 0;
590                 password++;
591         } else
592                 password = "";
593
594         /* Store in secrets.tdb */
595
596         if (!secrets_store(SECRETS_AUTH_USER, user, 
597                            strlen(user) + 1) ||
598             !secrets_store(SECRETS_AUTH_DOMAIN, domain, 
599                            strlen(domain) + 1) ||
600             !secrets_store(SECRETS_AUTH_PASSWORD, password,
601                            strlen(password) + 1)) {
602                 d_fprintf(stderr, "error storing authenticated user info\n");
603                 return False;
604         }
605
606         return True;
607 }
608
609 static BOOL wbinfo_ping(void)
610 {
611         NSS_STATUS result;
612         
613         result = winbindd_request(WINBINDD_PING, NULL, NULL);
614
615         /* Display response */
616
617         d_printf("'ping' to winbindd %s\n", 
618                (result == NSS_STATUS_SUCCESS) ? "succeeded" : "failed");
619
620         return result == NSS_STATUS_SUCCESS;
621 }
622
623 /* Print program usage */
624
625 static void usage(void)
626 {
627         d_printf("Usage: wbinfo -ug | -n name | -sSY sid | -UG uid/gid | -tm "
628                "| -[aA] user%%password\n");
629         d_printf("\t-u\t\t\tlists all domain users\n");
630         d_printf("\t-g\t\t\tlists all domain groups\n");
631         d_printf("\t-n name\t\t\tconverts name to sid\n");
632         d_printf("\t-s sid\t\t\tconverts sid to name\n");
633         d_printf("\t-N name\t\t\tconverts NetBIOS name to IP (WINS)\n");
634         d_printf("\t-I name\t\t\tconverts IP address to NetBIOS name (WINS)\n");
635         d_printf("\t-U uid\t\t\tconverts uid to sid\n");
636         d_printf("\t-G gid\t\t\tconverts gid to sid\n");
637         d_printf("\t-S sid\t\t\tconverts sid to uid\n");
638         d_printf("\t-Y sid\t\t\tconverts sid to gid\n");
639         d_printf("\t-t\t\t\tcheck shared secret\n");
640         d_printf("\t-m\t\t\tlist trusted domains\n");
641         d_printf("\t-r user\t\t\tget user groups\n");
642         d_printf("\t-a user%%password\tauthenticate user\n");
643         d_printf("\t-A user%%password\tstore user and password used by winbindd (root only)\n");
644         d_printf("\t-p\t\t\t'ping' winbindd to see if it is alive\n");
645         d_printf("\t--sequence\t\tshow sequence numbers of all domains\n");
646         d_printf("\t--set-auth-user DOMAIN\\user%%password\tset password for restrict anonymous\n");
647 }
648
649 /* Main program */
650
651 enum {
652         OPT_SET_AUTH_USER = 1000,
653         OPT_SEQUENCE
654 };
655
656 int main(int argc, char **argv)
657 {
658         extern pstring global_myname;
659         int opt;
660
661         poptContext pc;
662         static char *string_arg;
663         static int int_arg;
664         BOOL got_command = False;
665         int result = 1;
666
667         struct poptOption long_options[] = {
668
669                 /* longName, shortName, argInfo, argPtr, value, descrip, 
670                    argDesc */
671
672                 { "help", 'h', POPT_ARG_NONE, 0, 'h' },
673                 { "domain-users", 'u', POPT_ARG_NONE, 0, 'u' },
674                 { "domain-groups", 'g', POPT_ARG_NONE, 0, 'g' },
675                 { "WINS-by-name", 'N', POPT_ARG_STRING, &string_arg, 'N' },
676                 { "WINS-by-ip", 'I', POPT_ARG_STRING, &string_arg, 'I' },
677                 { "name-to-sid", 'n', POPT_ARG_STRING, &string_arg, 'n' },
678                 { "sid-to-name", 's', POPT_ARG_STRING, &string_arg, 's' },
679                 { "uid-to-sid", 'U', POPT_ARG_INT, &int_arg, 'U' },
680                 { "gid-to-sid", 'G', POPT_ARG_INT, &int_arg, 'G' },
681                 { "sid-to-uid", 'S', POPT_ARG_STRING, &string_arg, 'S' },
682                 { "sid-to-gid", 'Y', POPT_ARG_STRING, &string_arg, 'Y' },
683                 { "check-secret", 't', POPT_ARG_NONE, 0, 't' },
684                 { "trusted-domains", 'm', POPT_ARG_NONE, 0, 'm' },
685                 { "sequence", 0, POPT_ARG_NONE, 0, OPT_SEQUENCE },
686                 { "user-groups", 'r', POPT_ARG_STRING, &string_arg, 'r' },
687                 { "authenticate", 'a', POPT_ARG_STRING, &string_arg, 'a' },
688                 { "set-auth-user", 'A', POPT_ARG_STRING, &string_arg, OPT_SET_AUTH_USER },
689                 { "ping", 'p', POPT_ARG_NONE, 0, 'p' },
690                 { 0, 0, 0, 0 }
691         };
692
693         /* Samba client initialisation */
694
695         if (!*global_myname) {
696                 char *p;
697
698                 fstrcpy(global_myname, myhostname());
699                 p = strchr(global_myname, '.');
700                 if (p)
701                         *p = 0;
702         }
703
704         if (!lp_load(dyn_CONFIGFILE, True, False, False)) {
705                 d_fprintf(stderr, "wbinfo: error opening config file %s. Error was %s\n",
706                         dyn_CONFIGFILE, strerror(errno));
707                 exit(1);
708         }
709
710         load_interfaces();
711
712         /* Parse command line options */
713
714         if (argc == 1) {
715                 usage();
716                 return 1;
717         }
718
719         /* Parse options */
720
721         pc = poptGetContext("wbinfo", argc, (const char **)argv, long_options, 0);
722
723         while((opt = poptGetNextOpt(pc)) != -1) {
724                 if (got_command) {
725                         d_fprintf(stderr, "No more than one command may be specified at once.\n");
726                         exit(1);
727                 }
728                 got_command = True;
729         }
730
731         poptFreeContext(pc);
732
733         pc = poptGetContext(NULL, argc, (const char **)argv, long_options, 
734                             POPT_CONTEXT_KEEP_FIRST);
735
736         while((opt = poptGetNextOpt(pc)) != -1) {
737                 switch (opt) {
738                 case 'h':
739                         usage();
740                         result = 0;
741                         goto done;
742                 case 'u':
743                         if (!print_domain_users()) {
744                                 d_printf("Error looking up domain users\n");
745                                 goto done;
746                         }
747                         break;
748                 case 'g':
749                         if (!print_domain_groups()) {
750                                 d_printf("Error looking up domain groups\n");
751                                 goto done;
752                         }
753                         break;
754                 case 's':
755                         if (!wbinfo_lookupsid(string_arg)) {
756                                 d_printf("Could not lookup sid %s\n", string_arg);
757                                 goto done;
758                         }
759                         break;
760                 case 'n':
761                         if (!wbinfo_lookupname(string_arg)) {
762                                 d_printf("Could not lookup name %s\n", string_arg);
763                                 goto done;
764                         }
765                         break;
766                 case 'N':
767                         if (!wbinfo_wins_byname(string_arg)) {
768                                 d_printf("Could not lookup WINS by name %s\n", string_arg);
769                                 goto done;
770                         }
771                         break;
772                 case 'I':
773                         if (!wbinfo_wins_byip(string_arg)) {
774                                 d_printf("Could not lookup WINS by IP %s\n", string_arg);
775                                 goto done;
776                         }
777                         break;
778                 case 'U':
779                         if (!wbinfo_uid_to_sid(int_arg)) {
780                                 d_printf("Could not convert uid %d to sid\n", int_arg);
781                                 goto done;
782                         }
783                         break;
784                 case 'G':
785                         if (!wbinfo_gid_to_sid(int_arg)) {
786                                 d_printf("Could not convert gid %d to sid\n",
787                                        int_arg);
788                                 goto done;
789                         }
790                         break;
791                 case 'S':
792                         if (!wbinfo_sid_to_uid(string_arg)) {
793                                 d_printf("Could not convert sid %s to uid\n",
794                                        string_arg);
795                                 goto done;
796                         }
797                         break;
798                 case 'Y':
799                         if (!wbinfo_sid_to_gid(string_arg)) {
800                                 d_printf("Could not convert sid %s to gid\n",
801                                        string_arg);
802                                 goto done;
803                         }
804                         break;
805                 case 't':
806                         if (!wbinfo_check_secret()) {
807                                 d_printf("Could not check secret\n");
808                                 goto done;
809                         }
810                         break;
811                 case 'm':
812                         if (!wbinfo_list_domains()) {
813                                 d_printf("Could not list trusted domains\n");
814                                 goto done;
815                         }
816                         break;
817                 case OPT_SEQUENCE:
818                         if (!wbinfo_show_sequence()) {
819                                 d_printf("Could not show sequence numbers\n");
820                                 goto done;
821                         }
822                         break;
823                 case 'r':
824                         if (!wbinfo_get_usergroups(string_arg)) {
825                                 d_printf("Could not get groups for user %s\n", 
826                                        string_arg);
827                                 goto done;
828                         }
829                         break;
830                 case 'a': {
831                         BOOL got_error = False;
832
833                         if (!wbinfo_auth(string_arg)) {
834                                 d_printf("Could not authenticate user %s with "
835                                        "plaintext password\n", string_arg);
836                                 got_error = True;
837                         }
838
839                         if (!wbinfo_auth_crap(string_arg)) {
840                                 d_printf("Could not authenticate user %s with "
841                                        "challenge/response\n", string_arg);
842                                 got_error = True;
843                         }
844                         
845                         if (got_error)
846                                 goto done;
847                         break;
848                 }
849                 case 'p': {
850
851                         if (!wbinfo_ping()) {
852                                 d_printf("could not ping winbindd!\n");
853                                 goto done;
854                         }
855                         break;
856                 }
857                 case OPT_SET_AUTH_USER:
858                         if (!(wbinfo_set_auth_user(string_arg)))
859                                 goto done;
860                         break;
861                 default:
862                         d_fprintf(stderr, "Invalid option\n");
863                         usage();
864                         goto done;
865                 }
866         }
867
868         result = 0;
869
870         /* Exit code */
871
872  done:
873         poptFreeContext(pc);
874         return result;
875 }