File: adm.c

package info (click to toggle)
anubis 4.1.1%2Bdfsg1-3.1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,896 kB
  • sloc: ansic: 17,484; sh: 4,923; yacc: 1,432; exp: 912; lisp: 698; lex: 415; makefile: 364; perl: 223; awk: 62; sed: 16
file content (910 lines) | stat: -rw-r--r-- 15,538 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
/* -*- buffer-read-only: t -*- vi: set ro:
   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
*/

#line 1 "adm.opt"
/* -*- c -*-
   This file is part of GNU Anubis.
   Copyright (C) 2001, 2002, 2003, 2004, 2005, 2007, 2008 The Anubis Team.

   GNU Anubis is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   GNU Anubis is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Anubis.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <anubisadm.h>

#line 20 "adm.opt"

#line 20
void print_help(void);
#line 20
void print_usage(void);
#line 99 "adm.opt"

#line 99
/* Option codes */
#line 99
enum {
#line 99
	_OPTION_INIT=255,
#line 99
	#line 99 "adm.opt"

#line 99
	OPTION_USAGE,
#line 99 "adm.opt"

#line 99
	OPTION_VERSION,

#line 99 "adm.opt"
	MAX_OPTION
#line 99
};
#line 99
static struct option long_options[] = {
#line 99
	#line 38 "adm.opt"

#line 38
	{ "create", no_argument, 0, 'c' },
#line 44 "adm.opt"

#line 44
	{ "list", no_argument, 0, 'l' },
#line 50 "adm.opt"

#line 50
	{ "add", no_argument, 0, 'a' },
#line 56 "adm.opt"

#line 56
	{ "modify", no_argument, 0, 'm' },
#line 62 "adm.opt"

#line 62
	{ "remove", no_argument, 0, 'r' },
#line 70 "adm.opt"

#line 70
	{ "authid", required_argument, 0, 'i' },
#line 78 "adm.opt"

#line 78
	{ "password", required_argument, 0, 'p' },
#line 85 "adm.opt"

#line 85
	{ "user", required_argument, 0, 'u' },
#line 92 "adm.opt"

#line 92
	{ "rcfile", required_argument, 0, 'f' },
#line 99 "adm.opt"

#line 99
	{ "help", no_argument, 0, 'h' },
#line 99 "adm.opt"

#line 99
	{ "usage", no_argument, 0, OPTION_USAGE },
#line 99 "adm.opt"

#line 99
	{ "version", no_argument, 0, OPTION_VERSION },

#line 99 "adm.opt"
	{0, 0, 0, 0}
#line 99
};
#line 99
static struct opthelp {
#line 99
        const char *opt;
#line 99
        const char *arg;
#line 99
        int is_optional;
#line 99
        const char *descr;
#line 99
} opthelp[] = {
#line 99
	#line 37 "adm.opt"

#line 37
	{ NULL, NULL, 0, N_("Administration commands:") },
#line 40 "adm.opt"

#line 40
	{ "-c, --create", NULL, 0, N_("Creates the database.") },
#line 46 "adm.opt"

#line 46
	{ "-l, --list", NULL, 0, N_("List contents of existing database.") },
#line 52 "adm.opt"

#line 52
	{ "-a, --add", NULL, 0, N_("Add a new record.") },
#line 58 "adm.opt"

#line 58
	{ "-m, --modify", NULL, 0, N_("Modify existing record.") },
#line 64 "adm.opt"

#line 64
	{ "-r, --remove", NULL, 0, N_("Remove existing record.") },
#line 68 "adm.opt"

#line 68
	{ NULL, NULL, 0, N_("Options:") },
#line 74 "adm.opt"

#line 74
	{ "-i, --authid", N_("STRING"), 0, N_("Specify the authid to operate upon. This option is mandatory with --add, --modify and --remove. It is optional when used with --list.") },
#line 81 "adm.opt"

#line 81
	{ "-p, --password", N_("STRING"), 0, N_("Specify the password for the authid. Mandatory with --add, --modify and --remove.") },
#line 88 "adm.opt"

#line 88
	{ "-u, --user", N_("STRING"), 0, N_("Specify the system user name corresponding to the given authid. Optional for --add, --modify and --remove.") },
#line 95 "adm.opt"

#line 95
	{ "-f, --rcfile", N_("STRING"), 0, N_("Specify the rc file to be used for this authid. Optional for --add, --modify and --remove.") },
#line 99 "adm.opt"

#line 99
	{ NULL, NULL, 0, N_("Other options") },
#line 99 "adm.opt"

#line 99
	{ "-h, --help", NULL, 0, N_("Give this help list") },
#line 99 "adm.opt"

#line 99
	{ "--usage", NULL, 0, N_("Give a short usage message") },
#line 99 "adm.opt"

#line 99
	{ "--version", NULL, 0, N_("Print program version") },

#line 99 "adm.opt"
};
#line 20 "adm.opt"

#line 20
const char *program_version = "anubisadm" " (" PACKAGE_STRING ")";
#line 20
static char doc[] = N_("Interface for GNU Anubis database administration.");
#line 20
static char args_doc[] = N_("URL");
#line 20
static char *after_desc = N_("EXAMPLES:\n\n  1. Create the GDBM database from a plaintext file:\n\n example$ anubisadm --create gdbm:/etc/anubis.db < plaintext\n\n 2. Add SMTP authid \"test\" with password \"guessme\" and map it to the system account \"gray\":\n\n example$ anubisadm --add --authid test --password guessme --user gray gdbm:/etc/anubis.db\n\n 3. List the database:\n\n example$ anubisadm --list gdbm:/etc/anubis.db\n\n 4. List only the record with authid \"test\":\n\n example$ anubisadm --list --authid test gdbm:/etc/anubis.db \n\n");
#line 20
const char *program_bug_address = "<" PACKAGE_BUGREPORT ">";
#line 20
		    
#line 20
#define DESCRCOLUMN 30
#line 20
#define RMARGIN 79
#line 20
#define GROUPCOLUMN 2
#line 20
#define USAGECOLUMN 13
#line 20
		    
#line 20
static void
#line 20
indent (size_t start, size_t col)
#line 20
{
#line 20
  for (; start < col; start++)
#line 20
    putchar (' ');
#line 20
}
#line 20
		    
#line 20
static void
#line 20
print_option_descr (const char *descr, size_t lmargin, size_t rmargin)
#line 20
{
#line 20
  while (*descr)
#line 20
    {
#line 20
      size_t s = 0;
#line 20
      size_t i;
#line 20
      size_t width = rmargin - lmargin;
#line 20
      
#line 20
      while (*descr && (*descr == ' ' || *descr == '\t'))
#line 20
	descr++;
#line 20
      for (i = 0; ; i++)
#line 20
	{
#line 20
	  if (descr[i] == '\n')
#line 20
	    {
#line 20
	      s = i;
#line 20
	      break;
#line 20
	    }
#line 20
	  if (descr[i] == 0 || (descr[i] == ' ' || descr[i] == '\t'))
#line 20
	    {
#line 20
	      if (i > width)
#line 20
		break;
#line 20
	      s = i;
#line 20
	      if (descr[i] == 0)
#line 20
		break;
#line 20
	    }
#line 20
	}
#line 20
      if (s > width)
#line 20
	while (!(descr[s] == ' ' || descr[s] == '\t'))
#line 20
	  s--;
#line 20
      printf ("%*.*s\n", s, s, descr);
#line 20
      descr += s;
#line 20
      if (*descr)
#line 20
	{
#line 20
	  indent (0, lmargin);
#line 20
	  descr++;
#line 20
	}
#line 20
    }
#line 20
}
#line 20

#line 20
void
#line 20
print_help(void)
#line 20
{
#line 20
  unsigned i;
#line 20
  
#line 20
  printf ("%s %s [%s]... %s\n", _("Usage:"), "anubisadm", _("OPTION"),
#line 20
	  gettext (args_doc)); 
#line 20
  if (doc && doc[0])
#line 20
    print_option_descr(gettext (doc), 0, RMARGIN);
#line 20
  putchar ('\n');
#line 20

#line 20
  for (i = 0; i < sizeof (opthelp) / sizeof (opthelp[0]); i++)
#line 20
    {
#line 20
      unsigned n;
#line 20
      if (opthelp[i].opt)
#line 20
	{
#line 20
	  n = printf ("  %s", opthelp[i].opt);
#line 20
	  if (opthelp[i].arg)
#line 20
	    {
#line 20
	      char *cb, *ce;
#line 20
	      if (strlen (opthelp[i].opt) == 2)
#line 20
		{
#line 20
		  if (!opthelp[i].is_optional)
#line 20
		    {
#line 20
		      putchar (' ');
#line 20
		      n++;
#line 20
		    }
#line 20
		}
#line 20
	      else
#line 20
		{
#line 20
		  putchar ('=');
#line 20
		  n++;
#line 20
		}
#line 20
	      if (opthelp[i].is_optional)
#line 20
		{
#line 20
		  cb = "[";
#line 20
		  ce = "]";
#line 20
		}
#line 20
	      else
#line 20
		cb = ce = "";
#line 20
	      n += printf ("%s%s%s", cb, gettext (opthelp[i].arg), ce);
#line 20
	    }
#line 20
	  if (n >= DESCRCOLUMN)
#line 20
	    {
#line 20
	      putchar ('\n');
#line 20
	      n = 0;
#line 20
	    }
#line 20
	  indent (n, DESCRCOLUMN);
#line 20
	  print_option_descr (gettext (opthelp[i].descr), DESCRCOLUMN, RMARGIN);
#line 20
	}
#line 20
      else
#line 20
	{
#line 20
	  if (i)
#line 20
	    putchar ('\n');
#line 20
	  indent (0, GROUPCOLUMN);
#line 20
	  print_option_descr (gettext (opthelp[i].descr),
#line 20
			      GROUPCOLUMN, RMARGIN);
#line 20
	  putchar ('\n');
#line 20
	}
#line 20
    }
#line 20
  
#line 20
  putchar ('\n');
#line 20
  print_option_descr (_("Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options."), 0, RMARGIN);
#line 20
  putchar ('\n');
#line 20

#line 20
  if (after_desc)
#line 20
    {
#line 20
      print_option_descr (gettext (after_desc), 0, RMARGIN);
#line 20
    }	
#line 20
  printf (_("Report bugs to %s.\n"), program_bug_address);
#line 20
}
#line 20

#line 20
void
#line 20
print_usage(void)
#line 20
{
#line 20
  unsigned i;
#line 20
  int f = 0;
#line 20
  unsigned n;
#line 20
  char buf[RMARGIN+1];
#line 20

#line 20
#define FLUSH                        do                                   {                              	  buf[n] = 0;              	  printf ("%s\n", buf);    	  n = USAGECOLUMN;         	  memset (buf, ' ', n);        }                                while (0)
#line 20
#define ADDC(c)   do { if (n == RMARGIN) FLUSH; buf[n++] = c; } while (0)
#line 20

#line 20
  n = snprintf (buf, sizeof buf, "%s %s ", _("Usage:"), "anubisadm");
#line 20

#line 20
  /* Print a list of short options without arguments. */
#line 20
  for (i = 0; i < sizeof (opthelp) / sizeof (opthelp[0]); i++)
#line 20
    {
#line 20
      if (opthelp[i].opt && opthelp[i].descr && opthelp[i].opt[1] != '-'
#line 20
	  && opthelp[i].arg == NULL)
#line 20
	{
#line 20
	  if (f == 0)
#line 20
	    {
#line 20
	      ADDC('[');
#line 20
	      ADDC('-');
#line 20
	      f = 1;
#line 20
	    }
#line 20
	  ADDC(opthelp[i].opt[1]);
#line 20
	}
#line 20
    }
#line 20
  if (f)
#line 20
    ADDC(']');
#line 20

#line 20
  /* Print a list of short options with arguments. */
#line 20
  for (i = 0; i < sizeof (opthelp) / sizeof (opthelp[0]); i++)
#line 20
    {
#line 20
      if (opthelp[i].opt && opthelp[i].descr && opthelp[i].opt[1] != '-'
#line 20
	  && opthelp[i].arg)
#line 20
	{
#line 20
	  size_t len = 5 
#line 20
	                + strlen (opthelp[i].arg)
#line 20
			   + (opthelp[i].is_optional ? 2 : 1);
#line 20
	  if (n + len > RMARGIN) FLUSH;
#line 20
	  buf[n++] = ' '; 
#line 20
	  buf[n++] = '['; 
#line 20
	  buf[n++] = '-';
#line 20
	  buf[n++] = opthelp[i].opt[1];
#line 20
	  if (opthelp[i].is_optional)
#line 20
	    {
#line 20
	      buf[n++] = '[';
#line 20
	      strcpy (&buf[n], opthelp[i].arg);
#line 20
	      n += strlen (opthelp[i].arg);
#line 20
	      buf[n++] = ']';
#line 20
	    }
#line 20
	  else
#line 20
	    {
#line 20
	      buf[n++] = ' ';
#line 20
	      strcpy (&buf[n], opthelp[i].arg);
#line 20
	      n += strlen (opthelp[i].arg);
#line 20
	    }
#line 20
	  buf[n++] = ']';
#line 20
	}
#line 20
    }
#line 20

#line 20
  /* Print a list of long options */
#line 20
  for (i = 0; i < sizeof (opthelp) / sizeof (opthelp[0]); i++)
#line 20
    {
#line 20
      if (opthelp[i].opt && opthelp[i].descr)
#line 20
	{
#line 20
	  size_t len;
#line 20
	  const char *longopt;
#line 20

#line 20
	  if (opthelp[i].opt[1] == '-')
#line 20
	    longopt = opthelp[i].opt;
#line 20
	  else if (opthelp[i].opt[2] == ',')
#line 20
	    longopt = opthelp[i].opt + 4;
#line 20
	  else
#line 20
	    continue;
#line 20

#line 20
	  len = 3 + strlen (longopt)
#line 20
	          + (opthelp[i].arg ? 1 + strlen (opthelp[i].arg)
#line 20
		      + (opthelp[i].is_optional ? 2 : 0) : 0);
#line 20
	  if (n + len > RMARGIN) FLUSH;
#line 20
	  buf[n++] = ' '; 
#line 20
	  buf[n++] = '['; 
#line 20
	  strcpy (&buf[n], longopt);
#line 20
	  n += strlen (longopt);
#line 20
	  if (opthelp[i].arg)
#line 20
	    {
#line 20
	      buf[n++] = '=';
#line 20
	      if (opthelp[i].is_optional)
#line 20
		{
#line 20
		  buf[n++] = '[';
#line 20
		  strcpy (&buf[n], opthelp[i].arg);
#line 20
		  n += strlen (opthelp[i].arg);
#line 20
		  buf[n++] = ']';
#line 20
		}
#line 20
	      else
#line 20
		{
#line 20
		  strcpy (&buf[n], opthelp[i].arg);
#line 20
		  n += strlen (opthelp[i].arg);
#line 20
		}
#line 20
	    }
#line 20
	  buf[n++] = ']';
#line 20
	}
#line 20
    }
#line 20
  FLUSH;
#line 20
  
#line 20
}
#line 20

#line 20
const char version_etc_copyright[] =
#line 20
  /* Do *not* mark this string for translation.  %s is a copyright
     symbol suitable for this locale. */
#line 20
  "Copyright %s 2001, 2002, 2003, 2004, 2005, 2007, 2008 The Anubis Team.";
#line 20

#line 20
void
#line 20
print_version_only(const char *program_version, FILE *stream)
#line 20
{
#line 20
  fprintf (stream, "%s\n", program_version);
#line 20
  /* TRANSLATORS: Translate "(C)" to the copyright symbol
     (C-in-a-circle), if this symbol is available in the user's
     locale.  Otherwise, do not translate "(C)"; leave it as-is.  */
#line 20
  fprintf (stream, version_etc_copyright, _("(C)"));
#line 20
  fputc ('\n', stream);
#line 20
}
#line 20

#line 20
void
#line 20
print_version(const char *program_version, FILE *stream)
#line 20
{
#line 20
  print_version_only(program_version, stream);
#line 20
	
#line 20
  fputs (_("License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law.\n\n"),
#line 20
	 stream);
#line 20
}
#line 20

#line 99 "adm.opt"

#line 99


void
adm_get_options (int argc, char *argv[], operation_fp *operation, int *index)
{
    
#line 104
 {
#line 104
  int c;
#line 104

#line 104
  while ((c = getopt_long(argc, argv, "clamri:p:u:f:h",
#line 104
                          long_options, NULL)) != EOF)
#line 104
    {
#line 104
      switch (c)
#line 104
        {
#line 104
        default:
#line 104
	   exit(1);
#line 104
	#line 40 "adm.opt"
	 case 'c':
#line 40
          {
#line 40

       *operation = op_create;

#line 42
             break;
#line 42
          }
#line 46 "adm.opt"
	 case 'l':
#line 46
          {
#line 46

	  *operation = op_list;

#line 48
             break;
#line 48
          }
#line 52 "adm.opt"
	 case 'a':
#line 52
          {
#line 52

	  *operation = op_add;

#line 54
             break;
#line 54
          }
#line 58 "adm.opt"
	 case 'm':
#line 58
          {
#line 58

	  *operation = op_modify;

#line 60
             break;
#line 60
          }
#line 64 "adm.opt"
	 case 'r':
#line 64
          {
#line 64

	  rcfile = optarg;

#line 66
             break;
#line 66
          }
#line 74 "adm.opt"
	 case 'i':
#line 74
          {
#line 74

	  authid = optarg;

#line 76
             break;
#line 76
          }
#line 81 "adm.opt"
	 case 'p':
#line 81
          {
#line 81

	  password = optarg;

#line 83
             break;
#line 83
          }
#line 88 "adm.opt"
	 case 'u':
#line 88
          {
#line 88

	  username = optarg;

#line 90
             break;
#line 90
          }
#line 95 "adm.opt"
	 case 'f':
#line 95
          {
#line 95

	  rcfile = optarg;

#line 97
             break;
#line 97
          }
#line 99 "adm.opt"
	 case 'h':
#line 99
          {
#line 99

#line 99
		print_help ();
#line 99
                exit (0);
#line 99
	 
#line 99
             break;
#line 99
          }
#line 99 "adm.opt"
	 case OPTION_USAGE:
#line 99
          {
#line 99

#line 99
		print_usage ();
#line 99
		exit (0);
#line 99
	 
#line 99
             break;
#line 99
          }
#line 99 "adm.opt"
	 case OPTION_VERSION:
#line 99
          {
#line 99

#line 99
		/* Give version */
#line 99
		print_version(program_version, stdout);
#line 99
		exit (0);
#line 99
         
#line 99
             break;
#line 99
          }

#line 104 "adm.opt"
        }
#line 104
    }
#line 104
  *index = optind;
#line 104
 }   
#line 104
;
}