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