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