~ubuntu-branches/ubuntu/trusty/gvpe/trusty-proposed

« back to all changes in this revision

Viewing changes to src/vpn.C

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2013-08-19 17:43:11 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130819174311-is2gqi9pa1z82bei
Tags: 2.25-1
* Imported Upstream version 2.25
* debian/patches: Remove upstream merged patches..
* debian/patches/fix_gvpe_conf_5: fix an empty man page.
* debian/control: Bump Standards-Version to 3.9.4 (with no changes).
* debian/copyright: Fixed license name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <sys/types.h>
41
41
#include <sys/socket.h>
42
42
#include <sys/wait.h>
 
43
#include <sys/stat.h>
43
44
#include <errno.h>
44
45
#include <time.h>
45
46
#include <unistd.h>
54
55
#include "util.h"
55
56
#include "vpn.h"
56
57
 
 
58
using namespace std;
 
59
 
57
60
vpn network; // THE vpn (bad design...)
58
61
 
59
62
/////////////////////////////////////////////////////////////////////////////
394
397
}
395
398
 
396
399
bool
 
400
vpn::drop_privileges ()
 
401
{
 
402
  if (::conf.change_root)
 
403
    {
 
404
      if (!strcmp (::conf.change_root, "/"))
 
405
        {
 
406
          char dir [L_tmpnam];
 
407
          if (!tmpnam (dir))
 
408
            {
 
409
              slog (L_CRIT, _("unable to create anonymous root path."));
 
410
              return false;
 
411
            }
 
412
 
 
413
          if (mkdir (dir, 0700))
 
414
            {
 
415
              slog (L_CRIT, _("unable to crate anonymous root directory."));
 
416
              return false;
 
417
            }
 
418
 
 
419
          if (chdir (dir))
 
420
            {
 
421
              slog (L_CRIT, _("unable to change to anonymous root directory."));
 
422
              return false;
 
423
            }
 
424
 
 
425
          if (rmdir (dir))
 
426
            slog (L_ERR, _("unable to remove anonymous root directory, continuing."));
 
427
        }
 
428
      else
 
429
        {
 
430
          if (chdir (::conf.change_root))
 
431
            {
 
432
              slog (L_CRIT, _("%s: unable to change to specified root directory."), ::conf.change_root);
 
433
              return false;
 
434
            }
 
435
        }
 
436
 
 
437
      if (chroot ("."))
 
438
        {
 
439
          slog (L_CRIT, _("unable to set new root directory."));
 
440
          return false;
 
441
        }
 
442
 
 
443
      if (chdir ("/"))
 
444
        {
 
445
          slog (L_CRIT, _("unable to set cwd to new root directory."));
 
446
          return false;
 
447
        }
 
448
    }
 
449
 
 
450
  if (::conf.change_gid)
 
451
    if (setgid (::conf.change_gid))
 
452
      {
 
453
        slog (L_CRIT, _("unable to change group id to %d."), ::conf.change_gid);
 
454
        return false;
 
455
      }
 
456
 
 
457
  if (::conf.change_uid)
 
458
    if (setuid (::conf.change_uid))
 
459
      {
 
460
        slog (L_CRIT, _("unable to change user id to %d."), ::conf.change_uid);
 
461
        return false;
 
462
      }
 
463
 
 
464
  return true;
 
465
}
 
466
 
 
467
bool
397
468
vpn::send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos)
398
469
{
399
470
  set_tos (ipv4_fd, ipv4_tos, tos);
486
557
      || pkt->typ () >= vpn_packet::PT_MAX)
487
558
    slog (L_WARN, _("(%s): received corrupted packet type %d (src %d, dst %d)."),
488
559
          (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ());
489
 
  else if (dst > conns.size ())
490
 
    slog (L_WARN, _("(%s): received corrupted packet type %d (src %d, dst %d)."),
491
 
          (const char *)rsi, pkt->typ (), pkt->src (), pkt->dst ());
492
560
  else
493
561
    {
494
562
      connection *c = conns[src - 1];
518
586
  switch (si.prot)
519
587
    {
520
588
      case PROT_IPv4:
521
 
        return send_ipv4_packet (pkt, si, tos);
 
589
        return send_ipv4_packet   (pkt, si, tos);
522
590
 
523
591
      case PROT_UDPv4:
524
 
        return send_udpv4_packet (pkt, si, tos);
 
592
        return send_udpv4_packet  (pkt, si, tos);
525
593
 
526
594
#if ENABLE_TCP
527
595
      case PROT_TCPv4:
528
 
        return send_tcpv4_packet (pkt, si, tos);
 
596
        return send_tcpv4_packet  (pkt, si, tos);
529
597
#endif
530
598
#if ENABLE_ICMP
531
599
      case PROT_ICMPv4:
533
601
#endif
534
602
#if ENABLE_DNS
535
603
      case PROT_DNSv4:
536
 
        return send_dnsv4_packet (pkt, si, tos);
 
604
        return send_dnsv4_packet  (pkt, si, tos);
537
605
#endif
538
606
      default:
539
607
        slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol."), (const char *)si);
561
629
          pkt->len = len;
562
630
 
563
631
          // raw sockets deliver the ipv4 header, but don't expect it on sends
564
 
          pkt->skip_hdr (IP_OVERHEAD);
 
632
          pkt->skip_hdr (pkt->ipv4_hdr_len ());
565
633
 
566
634
          recv_vpn_packet (pkt, si);
567
635
        }
608
676
            {
609
677
              // raw sockets deliver the ipv4, but don't expect it on sends
610
678
              // this is slow, but...
611
 
              pkt->skip_hdr (ICMP_OVERHEAD);
 
679
              pkt->skip_hdr (pkt->ipv4_hdr_len () + (ICMP_OVERHEAD - IP_OVERHEAD));
612
680
 
613
681
              recv_vpn_packet (pkt, si);
614
682
            }