~ubuntu-branches/ubuntu/hardy/openswan/hardy-updates

« back to all changes in this revision

Viewing changes to programs/pluto/whack.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2005-01-27 16:10:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050127161011-idgybmyz3vwhpfiq
Tags: 2.3.0-2
Urgency HIGH due to security issue and problems with build-deps in sarge.
* Fix the security issue. Please see
  http://www.idefense.com/application/poi/display?id=190&
      type=vulnerabilities&flashstatus=false
  for more details. Thanks to Martin Schulze for informing me about
  this issue.
  Closes: #292458: Openswan XAUTH/PAM Buffer Overflow Vulnerability
* Added a Build-Dependency to lynx.
  Closes: #291143: openswan: FTBFS: Missing build dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
14
 * for more details.
15
15
 *
16
 
 * RCSID $Id: whack.c,v 1.120.2.2 2004/06/01 14:42:36 ken Exp $
 
16
 * RCSID $Id: whack.c,v 1.139 2004/12/16 01:21:59 mcr Exp $
17
17
 */
18
18
 
19
19
#include <stdio.h>
34
34
#include <openswan.h>
35
35
 
36
36
#include "constants.h"
 
37
#include "oswlog.h"
 
38
 
37
39
#include "defs.h"
38
40
#include "whack.h"
39
41
 
 
42
/** 
 
43
 * Print the 'ipsec --whack help' message
 
44
 */
40
45
static void
41
46
help(void)
42
47
{
69
74
            " [--dnskeyondemand]"
70
75
            " \\\n   "
71
76
            " [--updown <updown>]"
72
 
            " \\\n   "
73
77
            " --to"
74
 
            " (--host <ip-address> | --id <identity> | --cert <path>)"
 
78
            " (--host <ip-address> | --id <identity>)"
 
79
            " \\\n   "
 
80
            " [--cert <path>]"
 
81
            " [--groups <access control groups>]"
75
82
            " [--ca <distinguished name>]"
76
 
            " [--sendcert yes|always|no|never|ifasked]"
 
83
            " [--sendcert]"
 
84
            " [--sendcerttype number]"
 
85
            " \\\n   "
77
86
            " [--ikeport <port-number>]"
78
87
            " \\\n   "
79
88
            " [--nexthop <ip-address>]"
 
89
            " \\\n   "
80
90
            " [--client <subnet> | --clientwithin <address range>]"
81
91
            " \\\n   "
82
92
            " [--clientprotoport <protocol>/<port>]"
 
93
            " \\\n   "
83
94
            " [--dnskeyondemand]"
84
 
            " \\\n   "
85
95
            " [--updown <updown>]"
86
 
            " \\\n   "
87
96
            " [--psk]"
88
97
            " [--rsasig]"
89
98
            " \\\n   "
100
109
            " [--reykeyfuzz <percentage>]"
101
110
            " \\\n   "
102
111
            " [--keyingtries <count>]"
 
112
            " \\\n   "
 
113
            " [--esp <esp-algos>]"
 
114
            " \\\n   "
103
115
            " [--dontrekey]"
 
116
            " [--aggrmode]"
 
117
            " [--dpddelay <seconds> --dpdtimeout <seconds>]"
 
118
            " \\\n   "
 
119
            " [--dpdaction (clear|hold)]"
 
120
            " [--forceencaps]"
 
121
 
 
122
 
104
123
#ifdef XAUTH
105
 
            " [--xauth]"
106
124
            " [--xauthserver]"
107
125
            " [--xauthclient]"
108
126
#endif
162
180
            " [--debug-dns]"
163
181
            " [--debug-pfkey]"
164
182
            " \\\n   "
 
183
            " [--debug-natt]"
 
184
            " [--debug-x509]"
 
185
            " \\\n   "
165
186
            " [--debug-private]"
166
187
            "\n\n"
167
188
#endif
172
193
            " [--listpubkeys]"
173
194
            " [--listcerts]"
174
195
            " [--listcacerts]"
 
196
            " \\\n   "
 
197
            " [--listacerts]"
 
198
            " [--listaacerts]"
 
199
            " [--listocspcerts]"
 
200
            " \\\n   "
 
201
            " [--listgroups]"
175
202
            " [--listcrls]"
 
203
            " [--listocsp]"
 
204
 
176
205
            " [--listcards]"
177
206
            " [--listall]"
178
207
            "\n\n"
 
208
        "purge: whack"
 
209
            " [--purgeocsp]"
 
210
            "\n\n"
 
211
 
 
212
        "purge: whack"
 
213
            " [--listevents]"
 
214
            "\n\n"
 
215
 
179
216
        "reread: whack"
180
217
            " [--rereadsecrets]"
181
218
            " [--rereadcacerts]"
 
219
            " [--rereadaacerts]"
 
220
            " [--rereadocspcerts]"
 
221
            " \\\n   "
 
222
            " [--rereadacerts]"
 
223
 
182
224
            " [--rereadcrls]"
183
225
            " [--rereadall]"
184
226
            "\n\n"
196
238
 
197
239
static const char *name = NULL; /* --name operand, saved for diagnostics */
198
240
 
199
 
/* print a string as a diagnostic, then exit whack unhappily */
 
241
/** Print a string as a diagnostic, then exit whack unhappily 
 
242
 *
 
243
 * @param mess The error message to print when exiting
 
244
 * @return void
 
245
 */
200
246
static void
201
247
diag(const char *mess)
202
248
{
213
259
    exit(RC_WHACK_PROBLEM);
214
260
}
215
261
 
216
 
/* conditially calls diag; prints second arg, if non-NULL, as quoted string */
 
262
/** 
 
263
 * Conditially calls diag if ugh is set.
 
264
 * Prints second arg, if non-NULL, as quoted string
 
265
 *
 
266
 * @param ugh Error message
 
267
 * @param this Optional 2nd part of error message
 
268
 * @return void
 
269
 */
217
270
static void
218
271
diagq(err_t ugh, const char *this)
219
272
{
233
286
    }
234
287
}
235
288
 
236
 
/* complex combined operands return one of these enumerated values
 
289
/**
 
290
 * complex combined operands return one of these enumerated values
237
291
 * Note: these become flags in an lset_t.  Since there are more than
238
292
 * 32, we partition them into:
239
293
 * - OPT_* options (most random options)
 
294
 * - LST_* options (list various internal data)
240
295
 * - DBGOPT_* option (DEBUG options)
 
296
 * - END_* options (End description options)
241
297
 * - CD_* options (Connection Description options)
242
298
 */
243
299
enum option_enums {
263
319
    OPT_LISTEN,
264
320
    OPT_UNLISTEN,
265
321
 
266
 
    OPT_UTC,
267
 
    OPT_LISTPUBKEYS,
268
 
    OPT_LISTCERTS,
269
 
    OPT_LISTCACERTS,
270
 
    OPT_LISTCRLS,
271
 
    OPT_LISTCARDS,
272
 
    OPT_LISTALL,
 
322
    OPT_PURGEOCSP,
273
323
 
274
324
    OPT_REREADSECRETS,
275
325
    OPT_REREADCACERTS,
 
326
    OPT_REREADAACERTS,
 
327
    OPT_REREADOCSPCERTS,
 
328
    OPT_REREADACERTS,
276
329
    OPT_REREADCRLS,
277
330
    OPT_REREADALL,
278
331
 
290
343
 
291
344
#   define OPT_LAST OPT_ASYNC   /* last "normal" option */
292
345
 
 
346
/* List options */
 
347
 
 
348
#   define LST_FIRST LST_UTC   /* first list option */
 
349
    LST_UTC,
 
350
    LST_PUBKEYS,
 
351
    LST_CERTS,
 
352
    LST_CACERTS,
 
353
    LST_ACERTS,
 
354
    LST_AACERTS,
 
355
    LST_OCSPCERTS,
 
356
    LST_GROUPS,
 
357
    LST_CRLS,
 
358
    LST_OCSP,
 
359
    LST_CARDS,
 
360
    LST_EVENTS,
 
361
    LST_ALL,
 
362
 
 
363
#   define LST_LAST LST_ALL    /* last list option */
 
364
 
 
365
 
293
366
/* Connection End Description options */
294
367
 
295
368
#   define END_FIRST END_HOST   /* first end description */
297
370
    END_ID,
298
371
    END_CERT,
299
372
    END_CA,
 
373
    END_GROUPS,
300
374
    END_IKEPORT,
301
375
    END_NEXTHOP,
302
376
    END_CLIENT,
308
382
    END_MODECFGCLIENT,
309
383
    END_MODECFGSERVER,
310
384
    END_SENDCERT,
 
385
    END_CERTTYPE,
311
386
    END_SRCIP,
312
387
    END_UPDOWN,
313
388
        
319
394
    CD_TO,
320
395
 
321
396
#   define CD_POLICY_FIRST  CD_PSK
322
 
    CD_PSK,     /* same order as POLICY_* */
323
 
    CD_RSASIG,  /* same order as POLICY_* */
324
 
    CD_ENCRYPT, /* same order as POLICY_* */
325
 
    CD_AUTHENTICATE,    /* same order as POLICY_* */
326
 
    CD_COMPRESS,        /* same order as POLICY_* */
327
 
    CD_TUNNEL,  /* same order as POLICY_* */
328
 
    CD_PFS,     /* same order as POLICY_* */
329
 
    CD_DISABLEARRIVALCHECK,     /* same order as POLICY_* */
330
 
    CD_SHUNT0,  /* same order as POLICY_* */
331
 
    CD_SHUNT1,  /* same order as POLICY_* */
332
 
    CD_FAIL0,   /* same order as POLICY_* */
333
 
    CD_FAIL1,   /* same order as POLICY_* */
334
 
    CD_DONT_REKEY,      /* same order as POLICY_* */
335
 
    CD_OPP0,            /* same order as POLICY_* */
336
 
    CD_GROUP,           /* same order as POLICY_* */
337
 
    CD_GROUPED,         /* same order as POLICY_* */
338
 
    CD_UP,              /* same order as POLICY_* */
339
 
    CD_DUMMY,           /* same order as POLICY_* */
340
 
    CD_MODECFG,         /* same order as POLICY_* */
 
397
    CD_PSK,     /* same order as POLICY_* 0 */
 
398
    CD_RSASIG,  /* same order as POLICY_* 1 */
 
399
    CD_ENCRYPT, /* same order as POLICY_* 2 */
 
400
    CD_AUTHENTICATE,    /* same order as POLICY_* 3 */
 
401
    CD_COMPRESS,        /* same order as POLICY_* 4 */
 
402
    CD_TUNNEL,  /* same order as POLICY_* 5 */
 
403
    CD_PFS,     /* same order as POLICY_* 6 */
 
404
    CD_DISABLEARRIVALCHECK,     /* same order as POLICY_* 7 */
 
405
    CD_SHUNT0,  /* same order as POLICY_* 8 */
 
406
    CD_SHUNT1,  /* same order as POLICY_* 9 */
 
407
    CD_FAIL0,   /* same order as POLICY_* 10 */
 
408
    CD_FAIL1,   /* same order as POLICY_* 11 */
 
409
    CD_DONT_REKEY,      /* same order as POLICY_* 12 */
 
410
    CD_OPP0,            /* same order as POLICY_* 13 */
 
411
    CD_GROUP,           /* same order as POLICY_* 14 */
 
412
    CD_GROUPED,         /* same order as POLICY_* 15 */
 
413
    CD_UP,              /* same order as POLICY_* 16 */
 
414
    CD_DUMMY,           /* same order as POLICY_* 17 -- was XAUTH */
 
415
    CD_MODECFGPULL,     /* same order as POLICY_* 18 */
 
416
    CD_AGGRESSIVE,      /* same order as POLICY_* 19 */
341
417
    CD_TUNNELIPV4,
342
418
    CD_TUNNELIPV6,
343
419
    CD_CONNIPV4,
347
423
    CD_IPSECLIFETIME,
348
424
    CD_RKMARGIN,
349
425
    CD_RKFUZZ,
350
 
    CD_KTRIES
351
 
 
352
 
#   define CD_LAST CD_KTRIES    /* last connection description */
 
426
    CD_KTRIES,
 
427
    CD_DPDDELAY,
 
428
    CD_DPDTIMEOUT,
 
429
    CD_DPDACTION,
 
430
    CD_FORCEENCAPS,
 
431
    CD_IKE,
 
432
    CD_PFSGROUP,
 
433
    CD_ESP      
 
434
#   define CD_LAST CD_ESP       /* last connection description */
353
435
 
354
436
#ifdef DEBUG    /* must be last so others are less than 32 to fit in lset_t */
355
437
#   define DBGOPT_FIRST DBGOPT_NONE
369
451
    DBGOPT_OPPO,        /* same order as DBG_* */
370
452
    DBGOPT_CONTROLMORE, /* same order as DBG_* */
371
453
    DBGOPT_PFKEY,       /* same order as DBG_* */
372
 
    DBGOPT_NATTRAVERSAL, /* same order as DBG_* */
 
454
    DBGOPT_NATT,        /* same order as DBG_* */
 
455
    DBGOPT_X509,        /* same order as DBG_* */
 
456
    DBGOPT_DPD,         /* same order as DBG_* */
 
457
    DBGOPT_RES14,
 
458
    DBGOPT_RES15,
 
459
    DBGOPT_RES16,
 
460
    DBGOPT_RES17,
 
461
    DBGOPT_RES18,
 
462
    DBGOPT_RES19,
373
463
 
374
464
    DBGOPT_PRIVATE,     /* same order as DBG_* */
375
465
 
420
510
    { "crash", required_argument, NULL, OPT_DELETECRASH + OO },
421
511
    { "listen", no_argument, NULL, OPT_LISTEN + OO },
422
512
    { "unlisten", no_argument, NULL, OPT_UNLISTEN + OO },
423
 
    { "utc", no_argument, NULL, OPT_UTC + OO },
424
 
    { "listpubkeys", no_argument, NULL, OPT_LISTPUBKEYS + OO },
425
 
    { "listcerts", no_argument, NULL, OPT_LISTCERTS + OO },
426
 
    { "listcacerts", no_argument, NULL, OPT_LISTCACERTS + OO },
427
 
    { "listcrls", no_argument, NULL, OPT_LISTCRLS + OO },
428
 
    { "listcards", no_argument, NULL, OPT_LISTCARDS + OO },
429
 
    { "listall", no_argument, NULL, OPT_LISTALL + OO },
 
513
    { "purgeocsp", no_argument, NULL, OPT_PURGEOCSP + OO },
 
514
 
430
515
    { "rereadsecrets", no_argument, NULL, OPT_REREADSECRETS + OO },
431
516
    { "rereadcacerts", no_argument, NULL, OPT_REREADCACERTS + OO },
 
517
    { "rereadaacerts", no_argument, NULL, OPT_REREADAACERTS + OO },
 
518
    { "rereadocspcerts", no_argument, NULL, OPT_REREADOCSPCERTS + OO },
 
519
    { "rereadacerts", no_argument, NULL, OPT_REREADACERTS + OO },
 
520
 
432
521
    { "rereadcrls", no_argument, NULL, OPT_REREADCRLS + OO },
433
522
    { "rereadall", no_argument, NULL, OPT_REREADALL + OO },
434
523
    { "status", no_argument, NULL, OPT_STATUS + OO },
442
531
 
443
532
    { "asynchronous", no_argument, NULL, OPT_ASYNC + OO },
444
533
 
 
534
    /* list options */
 
535
 
 
536
    { "utc", no_argument, NULL, LST_UTC + OO },
 
537
    { "listpubkeys", no_argument, NULL, LST_PUBKEYS + OO },
 
538
    { "listcerts", no_argument, NULL, LST_CERTS + OO },
 
539
    { "listcacerts", no_argument, NULL, LST_CACERTS + OO },
 
540
    { "listacerts", no_argument, NULL, LST_ACERTS + OO },
 
541
    { "listaacerts", no_argument, NULL, LST_AACERTS + OO },
 
542
    { "listocspcerts", no_argument, NULL, LST_OCSPCERTS + OO },
 
543
    { "listgroups", no_argument, NULL, LST_GROUPS + OO },
 
544
    { "listcrls", no_argument, NULL, LST_CRLS + OO },
 
545
    { "listocsp", no_argument, NULL, LST_OCSP + OO },
 
546
    { "listcards", no_argument, NULL, LST_CARDS + OO },
 
547
    { "listevents", no_argument, NULL, LST_EVENTS + OO },
 
548
    { "listall", no_argument, NULL, LST_ALL + OO },
 
549
                                                                                                        
445
550
 
446
551
    /* options for an end description */
447
552
 
449
554
    { "id", required_argument, NULL, END_ID + OO },
450
555
    { "cert", required_argument, NULL, END_CERT + OO },
451
556
    { "ca", required_argument, NULL, END_CA + OO },
 
557
    { "groups", required_argument, NULL, END_GROUPS + OO },
452
558
    { "ikeport", required_argument, NULL, END_IKEPORT + OO + NUMERIC_ARG },
453
559
    { "nexthop", required_argument, NULL, END_NEXTHOP + OO },
454
560
    { "client", required_argument, NULL, END_CLIENT + OO },
473
579
    { "tunnelipv4", no_argument, NULL, CD_TUNNELIPV4 + OO },
474
580
    { "tunnelipv6", no_argument, NULL, CD_TUNNELIPV6 + OO },
475
581
    { "pfs", no_argument, NULL, CD_PFS + OO },
 
582
    { "aggrmode", no_argument, NULL, CD_AGGRESSIVE + OO },
476
583
    { "disablearrivalcheck", no_argument, NULL, CD_DISABLEARRIVALCHECK + OO },
477
584
    { "initiateontraffic", no_argument, NULL
478
585
        , CD_SHUNT0 + (POLICY_SHUNT_TRAP >> POLICY_SHUNT_SHIFT << AUX_SHIFT) + OO },
491
598
    { "failreject", no_argument, NULL
492
599
        , CD_FAIL0 + (POLICY_FAIL_REJECT >> POLICY_FAIL_SHIFT << AUX_SHIFT) + OO },
493
600
    { "dontrekey", no_argument, NULL, CD_DONT_REKEY + OO },
 
601
    { "forceencaps", no_argument, NULL, CD_FORCEENCAPS + OO },
 
602
    { "dpddelay", required_argument, NULL, CD_DPDDELAY + OO + NUMERIC_ARG },
 
603
    { "dpdtimeout", required_argument, NULL, CD_DPDTIMEOUT + OO + NUMERIC_ARG },
 
604
    { "dpdaction", required_argument, NULL, CD_DPDACTION + OO },
494
605
#ifdef XAUTH
495
606
    { "xauth", no_argument, NULL, END_XAUTHSERVER + OO },
496
607
    { "xauthserver", no_argument, NULL, END_XAUTHSERVER + OO },
497
608
    { "xauthclient", no_argument, NULL, END_XAUTHCLIENT + OO },
498
609
#endif
499
610
#ifdef MODECFG
 
611
    { "modecfgpull",   no_argument, NULL, CD_MODECFGPULL + OO },
500
612
    { "modecfgserver", no_argument, NULL, END_MODECFGSERVER + OO },
501
613
    { "modecfgclient", no_argument, NULL, END_MODECFGCLIENT + OO },
502
614
    { "modeconfigserver", no_argument, NULL, END_MODECFGSERVER + OO },
503
615
    { "modeconfigclient", no_argument, NULL, END_MODECFGCLIENT + OO },
504
616
#endif
505
617
    { "sendcert", required_argument, NULL, END_SENDCERT + OO },
 
618
    { "certtype", required_argument, NULL, END_CERTTYPE + OO + NUMERIC_ARG },
506
619
    { "ipv4", no_argument, NULL, CD_CONNIPV4 + OO },
507
620
    { "ipv6", no_argument, NULL, CD_CONNIPV6 + OO },
508
621
 
512
625
    { "rekeywindow", required_argument, NULL, CD_RKMARGIN + OO + NUMERIC_ARG }, /* OBSOLETE */
513
626
    { "rekeyfuzz", required_argument, NULL, CD_RKFUZZ + OO + NUMERIC_ARG },
514
627
    { "keyingtries", required_argument, NULL, CD_KTRIES + OO + NUMERIC_ARG },
 
628
    { "ike", required_argument, NULL, CD_IKE + OO },
 
629
    { "pfsgroup", required_argument, NULL, CD_PFSGROUP + OO },
 
630
    { "esp", required_argument, NULL, CD_ESP + OO },
515
631
#ifdef DEBUG
516
632
    { "debug-none", no_argument, NULL, DBGOPT_NONE + OO },
517
633
    { "debug-all]", no_argument, NULL, DBGOPT_ALL + OO },
526
642
    { "debug-oppo", no_argument, NULL, DBGOPT_OPPO + OO },
527
643
    { "debug-controlmore", no_argument, NULL, DBGOPT_CONTROLMORE + OO },
528
644
    { "debug-pfkey",   no_argument, NULL, DBGOPT_PFKEY + OO },
529
 
    { "debug-nattraversal", no_argument, NULL, DBGOPT_NATTRAVERSAL + OO },
 
645
    { "debug-nattraversal", no_argument, NULL, DBGOPT_NATT + OO },
 
646
    { "debug-x509",    no_argument, NULL, DBGOPT_X509 + OO },
 
647
    { "debug-dpd",     no_argument, NULL, DBGOPT_DPD + OO },
530
648
    { "debug-private", no_argument, NULL, DBGOPT_PRIVATE + OO },
531
649
 
532
650
    { "impair-delay-adns-key-answer", no_argument, NULL, DBGOPT_IMPAIR_DELAY_ADNS_KEY_ANSWER + OO },
597
715
}
598
716
 
599
717
static void
600
 
clear_end(struct whack_end *e)
601
 
{
602
 
    zero(e);
603
 
    e->id = NULL;
604
 
    e->cert = NULL;
605
 
    e->ca = NULL;
606
 
    e->updown = NULL;
607
 
    e->host_port = IKE_UDP_PORT;
608
 
}
609
 
 
610
 
static void
611
718
update_ports(struct whack_message * m)
612
719
{
613
720
    int port;
671
778
    secret = getpass("Enter secret: ");
672
779
    secret = (secret == NULL) ? "" : secret;
673
780
 
674
 
 
675
781
    strncpy(buf, secret, bufsize);
676
782
 
677
783
    len = strlen(buf) + 1;
740
846
main(int argc, char **argv)
741
847
{
742
848
    struct whack_message msg;
 
849
    char esp_buf[256];  /* uses snprintf */
743
850
    lset_t
744
 
        opts_seen = LEMPTY,
745
 
        cd_seen = LEMPTY,
746
 
        end_seen = LEMPTY,
747
 
        end_seen_before_to;
 
851
        opts_seen = LEMPTY,
 
852
        lst_seen = LEMPTY,
 
853
        cd_seen = LEMPTY,
 
854
        end_seen = LEMPTY,
 
855
        end_seen_before_to;
748
856
    const char
749
857
        *af_used_by = NULL,
750
858
        *tunnel_af_used_by = NULL;
760
868
#else
761
869
    assert(OPTION_OFFSET + CD_LAST < NUMERIC_ARG);
762
870
#endif
763
 
    assert(OPT_LAST - OPT_FIRST < 32);
764
 
    assert(END_LAST - END_FIRST < 32);
765
 
    assert(CD_LAST - CD_FIRST < 32);
766
 
#ifdef DEBUG    /* must be last so others are less than 32 to fit in lset_t */
767
 
    assert(DBGOPT_LAST - DBGOPT_FIRST < 32);
 
871
    assert(OPT_LAST - OPT_FIRST < (sizeof cd_seen * BITS_PER_BYTE));
 
872
    assert(LST_LAST - LST_FIRST < (sizeof cd_seen * BITS_PER_BYTE));
 
873
    assert(END_LAST - END_FIRST < (sizeof cd_seen * BITS_PER_BYTE));
 
874
    assert(CD_LAST - CD_FIRST < (sizeof cd_seen * BITS_PER_BYTE));
 
875
#ifdef DEBUG    /* must be last so others are less than (sizeof cd_seen * BITS_PER_BYTE) to fit in lset_t */
 
876
    assert(DBGOPT_LAST - DBGOPT_FIRST < (sizeof cd_seen * BITS_PER_BYTE));
768
877
#endif
769
878
    /* check that POLICY bit assignment matches with CD_ */
770
879
    assert(LELEM(CD_DONT_REKEY - CD_POLICY_FIRST) == POLICY_DONT_REKEY);
776
885
    msg.name = NULL;
777
886
    msg.keyid = NULL;
778
887
    msg.keyval.ptr = NULL;
 
888
    msg.esp = NULL;
 
889
    msg.ike = NULL;
 
890
    msg.pfsgroup = NULL;
779
891
 
780
892
    msg.sa_ike_life_seconds = OAKLEY_ISAKMP_SA_LIFETIME_DEFAULT;
781
893
    msg.sa_ipsec_life_seconds = PLUTO_SA_LIFE_DURATION_DEFAULT;
830
942
                diagq("duplicated flag", long_opts[long_index].name);
831
943
            opts_seen |= f;
832
944
        }
 
945
        else if (LST_FIRST <= c && c <= LST_LAST)
 
946
        {
 
947
            /* LST_* options get added lst_seen.
 
948
             * Reject repeated options (unless later code intervenes).
 
949
             */
 
950
            lset_t f = LELEM(c - LST_FIRST);
 
951
 
 
952
            if (lst_seen & f)
 
953
                diagq("duplicated flag", long_opts[long_index].name);
 
954
            lst_seen |= f;
 
955
        }
833
956
#ifdef DEBUG
834
957
        else if (DBGOPT_FIRST <= c && c <= DBGOPT_LAST)
835
958
        {
992
1115
            msg.whack_unlisten = TRUE;
993
1116
            continue;
994
1117
 
995
 
        case OPT_UTC:           /* --utc */
996
 
            msg.whack_utc = TRUE;
 
1118
        case OPT_PURGEOCSP:     /* --purgeocsp */
 
1119
            msg.whack_purgeocsp = TRUE;
997
1120
            continue;
998
1121
 
999
 
        case OPT_LISTPUBKEYS:   /* --listpubkeys */
1000
 
        case OPT_LISTCERTS:     /* --listcerts */
1001
 
        case OPT_LISTCACERTS:   /* --listcacerts */
1002
 
        case OPT_LISTCRLS:      /* --listcrls */
1003
 
        case OPT_LISTCARDS:     /* --listcards */
1004
 
            msg.whack_list |= LELEM(c-OPT_LISTPUBKEYS);
1005
 
            continue;
1006
 
 
1007
 
        case OPT_LISTALL:       /* --listall */
1008
 
            msg.whack_list = LIST_ALL;
1009
 
            continue;
1010
 
 
1011
 
        case OPT_REREADSECRETS: /* --rereadsecrets */
1012
 
        case OPT_REREADCACERTS: /* --rereadcacerts */
1013
 
        case OPT_REREADCRLS:    /* --rereadcrls */
 
1122
        case OPT_REREADSECRETS:   /* --rereadsecrets */
 
1123
        case OPT_REREADCACERTS:   /* --rereadcacerts */
 
1124
        case OPT_REREADAACERTS:   /* --rereadaacerts */
 
1125
        case OPT_REREADOCSPCERTS: /* --rereadocspcerts */
 
1126
        case OPT_REREADACERTS:    /* --rereadacerts */
 
1127
        case OPT_REREADCRLS:      /* --rereadcrls */
1014
1128
            msg.whack_reread |= LELEM(c-OPT_REREADSECRETS);
1015
1129
            continue;
1016
1130
 
1025
1139
        case OPT_SHUTDOWN:      /* --shutdown */
1026
1140
            msg.whack_shutdown = TRUE;
1027
1141
            continue;
1028
 
 
 
1142
            
1029
1143
        case OPT_OPPO_HERE:     /* --oppohere <ip-address> */
1030
1144
            tunnel_af_used_by = long_opts[long_index].name;
1031
1145
            diagq(ttoaddr(optarg, 0, msg.tunnel_addr_family, &msg.oppo_my_client), optarg);
1044
1158
            msg.whack_async = TRUE;
1045
1159
            continue;
1046
1160
 
 
1161
        /* List options */
 
1162
 
 
1163
         case LST_UTC:          /* --utc */
 
1164
            msg.whack_utc = TRUE;
 
1165
             continue; 
 
1166
 
 
1167
        case LST_PUBKEYS:       /* --listpubkeys */
 
1168
        case LST_CERTS:         /* --listcerts */
 
1169
        case LST_CACERTS:       /* --listcacerts */
 
1170
        case LST_ACERTS:        /* --listacerts */
 
1171
        case LST_AACERTS:       /* --listaacerts */
 
1172
        case LST_OCSPCERTS:     /* --listocspcerts */
 
1173
        case LST_GROUPS:        /* --listgroups */
 
1174
        case LST_CRLS:          /* --listcrls */
 
1175
        case LST_OCSP:          /* --listocsp */
 
1176
        case LST_CARDS:         /* --listcards */
 
1177
        case LST_EVENTS:         /* --listcards */
 
1178
            msg.whack_list |= LELEM(c - LST_PUBKEYS);
 
1179
            continue;
 
1180
 
 
1181
        case LST_ALL:   /* --listall */
 
1182
            msg.whack_list = LIST_ALL;
 
1183
            continue;
1047
1184
 
1048
1185
        /* Connection Description options */
1049
1186
 
1150
1287
            {
1151
1288
                msg.right.sendcert = cert_sendifasked;
1152
1289
            }
 
1290
            else if(streq(optarg, "forced"))
 
1291
            {
 
1292
                msg.right.sendcert = cert_forcedtype;
 
1293
            }
 
1294
            else
 
1295
            {
 
1296
                diagq("whack sendcert value is not legal", optarg);
 
1297
                continue;
 
1298
            }
 
1299
            continue;
 
1300
 
 
1301
        case END_CERTTYPE:
 
1302
            msg.right.certtype = opt_whole;
1153
1303
            continue;
1154
1304
 
1155
1305
        case END_CERT:  /* --cert <path> */
1160
1310
            msg.right.ca = optarg;      /* decoded by Pluto */
1161
1311
            continue;
1162
1312
 
 
1313
        case END_GROUPS:/* --groups <access control groups> */
 
1314
            msg.right.groups = optarg;  /* decoded by Pluto */
 
1315
            continue;
 
1316
 
 
1317
 
1163
1318
        case END_IKEPORT:       /* --ikeport <port-number> */
1164
1319
            if (opt_whole<=0 || opt_whole >= 0x10000)
1165
1320
                diagq("<port-number> must be a number between 1 and 65535", optarg);
1213
1368
            continue;
1214
1369
 
1215
1370
        case END_CLIENTPROTOPORT: /* --clientprotoport <protocol>/<port> */
1216
 
            diagq(ttoprotoport(optarg, 0, &msg.right.protocol,
1217
 
                &msg.right.port), optarg);
 
1371
            diagq(ttoprotoport(optarg, 0, &msg.right.protocol, &msg.right.port
 
1372
                , &msg.right.has_port_wildcard), optarg);
1218
1373
            continue;
1219
1374
 
1220
1375
        case END_DNSKEYONDEMAND:        /* --dnskeyondemand */
1225
1380
            msg.right.updown = optarg;
1226
1381
            continue;
1227
1382
 
1228
 
 
1229
1383
        case CD_TO:             /* --to */
1230
1384
            /* process right end, move it to left, reset it */
1231
1385
            if (!LHAS(end_seen, END_HOST - END_FIRST))
1243
1397
        case CD_COMPRESS:       /* --compress */
1244
1398
        case CD_TUNNEL:         /* --tunnel */
1245
1399
        case CD_PFS:            /* --pfs */
 
1400
        case CD_AGGRESSIVE:     /* --aggrmode */
1246
1401
        case CD_DISABLEARRIVALCHECK:    /* --disablearrivalcheck */
1247
1402
        case CD_DONT_REKEY:     /* --donotrekey */
 
1403
        case CD_MODECFGPULL:    /* --modecfgpull */
1248
1404
            msg.policy |= LELEM(c - CD_POLICY_FIRST);
1249
1405
            continue;
1250
1406
 
1288
1444
            msg.sa_keying_tries = opt_whole;
1289
1445
            continue;
1290
1446
 
 
1447
        case CD_FORCEENCAPS:
 
1448
            msg.forceencaps = TRUE;
 
1449
            continue;
 
1450
 
 
1451
        case CD_DPDDELAY:
 
1452
            msg.dpd_delay = opt_whole;
 
1453
            continue;
 
1454
 
 
1455
        case CD_DPDTIMEOUT:
 
1456
            msg.dpd_timeout = opt_whole;
 
1457
            continue;
 
1458
 
 
1459
        case CD_DPDACTION:
 
1460
            msg.dpd_action = 255;
 
1461
            if( strcmp(optarg, "clear") == 0) {
 
1462
                    msg.dpd_action = DPD_ACTION_CLEAR;
 
1463
            }
 
1464
            if( strcmp(optarg, "hold") == 0) {
 
1465
                    msg.dpd_action = DPD_ACTION_HOLD;
 
1466
            }
 
1467
            continue;
 
1468
 
 
1469
        case CD_IKE:    /* --ike <ike_alg1,ike_alg2,...> */
 
1470
            msg.ike = optarg;
 
1471
            continue;
 
1472
            
 
1473
        case CD_PFSGROUP:       /* --pfsgroup modpXXXX */
 
1474
            msg.pfsgroup = optarg;
 
1475
            continue;
 
1476
 
 
1477
        case CD_ESP:    /* --esp <esp_alg1,esp_alg2,...> */
 
1478
            msg.esp = optarg;
 
1479
            continue;
 
1480
 
1291
1481
        case CD_CONNIPV4:
1292
1482
            if (LHAS(cd_seen, CD_CONNIPV6 - CD_FIRST))
1293
1483
                diag("--ipv4 conflicts with --ipv6");
1371
1561
        case DBGOPT_OPPO:       /* --debug-oppo */
1372
1562
        case DBGOPT_CONTROLMORE: /* --debug-controlmore */
1373
1563
        case DBGOPT_PFKEY:      /* --debug-pfkey */
 
1564
        case DBGOPT_NATT:       /* --debug-pfkey */
 
1565
        case DBGOPT_X509:       /* --debug-pfkey */
 
1566
        case DBGOPT_DPD:        /* --debug-dpd */
1374
1567
        case DBGOPT_PRIVATE:    /* --debug-private */
1375
1568
        case DBGOPT_IMPAIR_DELAY_ADNS_KEY_ANSWER:       /* --impair-delay-adns-key-answer */
1376
1569
        case DBGOPT_IMPAIR_DELAY_ADNS_TXT_ANSWER:       /* --impair-delay-adns-txt-answer */
1493
1686
    || msg.whack_delete || msg.whack_deletestate
1494
1687
    || msg.whack_initiate || msg.whack_oppo_initiate || msg.whack_terminate
1495
1688
    || msg.whack_route || msg.whack_unroute || msg.whack_listen
1496
 
    || msg.whack_unlisten || msg.whack_list || msg.whack_reread
 
1689
    || msg.whack_unlisten || msg.whack_list || msg.whack_purgeocsp || msg.whack_reread
1497
1690
    || msg.whack_status || msg.whack_options || msg.whack_shutdown))
1498
1691
    {
1499
1692
        diag("no action specified; try --help for hints");
1500
1693
    }
1501
1694
 
 
1695
    if(msg.policy & POLICY_AGGRESSIVE) {
 
1696
        if(msg.ike == NULL) {
 
1697
            diag("can not specify aggressive mode without ike= to set algorithm");
 
1698
        }
 
1699
    }
 
1700
 
1502
1701
    update_ports(&msg);
1503
1702
 
1504
1703
    /* tricky quick and dirty check for wild values */
1513
1712
    check_life_time(msg.sa_ipsec_life_seconds, SA_LIFE_DURATION_MAXIMUM
1514
1713
        , "ipseclifetime", &msg);
1515
1714
 
 
1715
    if(msg.dpd_delay && !msg.dpd_timeout)
 
1716
            diag("dpddelay specified, but dpdtimeout is zero, both should be specified");
 
1717
    if(!msg.dpd_delay && msg.dpd_timeout)
 
1718
            diag("dpdtimeout specified, but dpddelay is zero, both should be specified");
 
1719
    if(msg.dpd_action != DPD_ACTION_CLEAR && msg.dpd_action != DPD_ACTION_HOLD) {
 
1720
            diag("dpdaction can only be \"clear\" or \"hold\", defaulting to \"hold\"");
 
1721
            msg.dpd_action = DPD_ACTION_HOLD;
 
1722
    }
 
1723
 
 
1724
 
1516
1725
    /* pack strings for inclusion in message */
1517
1726
    next_str = msg.string;
1518
1727
    str_roof = &msg.string[sizeof(msg.string)];
1519
1728
 
 
1729
    /* build esp message as esp="<esp>;<pfsgroup>" */
 
1730
    if (msg.pfsgroup) {
 
1731
            snprintf(esp_buf, sizeof (esp_buf), "%s;%s", 
 
1732
                    msg.esp ? msg.esp : "",
 
1733
                    msg.pfsgroup ? msg.pfsgroup : "");
 
1734
            msg.esp=esp_buf;
 
1735
    }
1520
1736
    if (!pack_str(&msg.name)            /* string  1 */
1521
1737
    || !pack_str(&msg.left.id)          /* string  2 */
1522
1738
    || !pack_str(&msg.left.cert)        /* string  3 */
1523
1739
    || !pack_str(&msg.left.ca)          /* string  4 */
1524
 
    || !pack_str(&msg.left.updown)      /* string  5 */
 
1740
    || !pack_str(&msg.left.groups)      /* string  5 */
 
1741
    || !pack_str(&msg.left.updown)      /* string  6 */
1525
1742
#ifdef VIRTUAL_IP
1526
1743
    || !pack_str(&msg.left.virt)
1527
1744
#endif
1528
 
    || !pack_str(&msg.right.id)         /* string  6 */
1529
 
    || !pack_str(&msg.right.cert)       /* string  7 */
1530
 
    || !pack_str(&msg.right.ca)         /* string  8 */
1531
 
    || !pack_str(&msg.right.updown)     /* string  9 */
 
1745
    || !pack_str(&msg.right.id)         /* string  7 */
 
1746
    || !pack_str(&msg.right.cert)       /* string  8 */
 
1747
    || !pack_str(&msg.right.ca)         /* string  9 */
 
1748
    || !pack_str(&msg.right.groups)     /* string  10 */
 
1749
    || !pack_str(&msg.right.updown)     /* string  11 */
1532
1750
#ifdef VIRTUAL_IP
1533
1751
    || !pack_str(&msg.right.virt)
1534
1752
#endif
1535
 
    || !pack_str(&msg.keyid)            /* string 10 */
1536
 
    || !pack_str(&msg.myid)             /* string 11 */
 
1753
    || !pack_str(&msg.keyid)            /* string 12 */
 
1754
    || !pack_str(&msg.myid)             /* string 13 */
 
1755
    || !pack_str(&msg.ike)              /* string 14 */
 
1756
    || !pack_str(&msg.esp)              /* string 15 */
1537
1757
    || str_roof - next_str < (ptrdiff_t)msg.keyval.len)    /* chunk (sort of string 5) */
1538
1758
        diag("too many bytes of strings to fit in message to pluto");
1539
1759
 
1542
1762
    next_str += msg.keyval.len;
1543
1763
 
1544
1764
    msg.magic = ((opts_seen & ~(LELEM(OPT_SHUTDOWN) | LELEM(OPT_STATUS)))
1545
 
                | cd_seen) != LEMPTY
 
1765
                | lst_seen | cd_seen) != LEMPTY
1546
1766
            || msg.whack_options
1547
1767
        ? WHACK_MAGIC : WHACK_BASIC_MAGIC;
1548
1768
 
1664
1884
                        case RC_ENTERSECRET:
1665
1885
                            if(!gotxauthpass)
1666
1886
                            {
1667
 
                                xauthpasslen = get_secret(xauthpass, 128);
 
1887
                                xauthpasslen = get_secret(xauthpass
 
1888
                                                          , sizeof(xauthpass));
1668
1889
                            }
1669
1890
                            send_reply(sock, xauthpass, xauthpasslen);
1670
1891
                            break;
1692
1913
        return exit_status;
1693
1914
    }
1694
1915
}
 
1916
 
 
1917
/*
 
1918
 * Local Variables:
 
1919
 * c-basic-offset:4
 
1920
 * c-style: pluto
 
1921
 * End:
 
1922
 */