~ubuntu-branches/ubuntu/oneiric/dnsmasq/oneiric

« back to all changes in this revision

Viewing changes to src/dnsmasq.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2009-06-08 22:03:23 UTC
  • mfrom: (0.3.4 upstream) (9.1.15 karmic)
  • Revision ID: james.westby@ubuntu.com-20090608220323-ighz285qbu5dobbt
Tags: 2.49-1
 
 * New upstream.
 * Log TFTP "file not found" errors. (closes: #532201)

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#ifdef NO_FORK
34
34
"no-MMU "
35
35
#endif
36
 
#ifdef HAVE_BSD_BRIDGE
37
 
"BSD-bridge "
38
 
#endif
39
36
#ifndef HAVE_DBUS
40
37
"no-"
41
38
#endif
44
41
"no-"
45
42
#endif
46
43
"I18N "
 
44
#ifndef HAVE_DHCP
 
45
"no-"
 
46
#endif
 
47
"DHCP "
47
48
#ifndef HAVE_TFTP
48
49
"no-"
49
50
#endif
67
68
  struct iname *if_tmp;
68
69
  int piperead, pipefd[2], err_pipe[2];
69
70
  struct passwd *ent_pw = NULL;
 
71
#ifdef HAVE_DHCP
70
72
  uid_t script_uid = 0;
71
73
  gid_t script_gid = 0;
72
 
  struct group *gp= NULL;
 
74
#endif
 
75
  struct group *gp = NULL;
73
76
  long i, max_fd = sysconf(_SC_OPEN_MAX);
74
77
  char *baduser = NULL;
75
78
  int log_err;
108
111
    daemon->edns_pktsz : DNSMASQ_PACKETSZ;
109
112
  daemon->packet = safe_malloc(daemon->packet_buff_sz);
110
113
 
 
114
#ifdef HAVE_DHCP
111
115
  if (!daemon->lease_file)
112
116
    {
113
117
      if (daemon->dhcp)
114
118
        daemon->lease_file = LEASEFILE;
115
119
    }
 
120
#endif
116
121
  
117
122
  /* Close any file descriptors we inherited apart from std{in|out|err} */
118
123
  for (i = 0; i < max_fd; i++)
145
150
  
146
151
  now = dnsmasq_time();
147
152
  
 
153
#ifdef HAVE_DHCP
148
154
  if (daemon->dhcp)
149
155
    {
150
 
#if !defined(HAVE_LINUX_NETWORK) && !defined(IP_RECVIF)
151
 
      int c;
152
 
      struct iname *tmp;
153
 
      for (c = 0, tmp = daemon->if_names; tmp; tmp = tmp->next)
154
 
        if (!tmp->isloop)
155
 
          c++;
156
 
      if (c != 1)
157
 
        die(_("must set exactly one interface on broken systems without IP_RECVIF"), NULL, EC_BADCONF);
158
 
#endif
159
156
      /* Note that order matters here, we must call lease_init before
160
157
         creating any file descriptors which shouldn't be leaked
161
158
         to the lease-script init process. */
162
159
      lease_init(now);
163
160
      dhcp_init();
164
161
    }
 
162
#endif
165
163
 
166
164
  if (!enumerate_interfaces())
167
165
    die(_("failed to find list of interfaces: %s"), NULL, EC_MISC);
204
202
  if (daemon->port != 0)
205
203
    pre_allocate_sfds();
206
204
 
 
205
#ifdef HAVE_DHCP
207
206
  /* Note getpwnam returns static storage */
208
207
  if (daemon->dhcp && daemon->lease_change_command && daemon->scriptuser)
209
208
    {
215
214
      else
216
215
        baduser = daemon->scriptuser;
217
216
    }
 
217
#endif
218
218
  
219
219
  if (daemon->username && !(ent_pw = getpwnam(daemon->username)))
220
220
    baduser = daemon->username;
290
290
             When startup is complete we close this and the process terminates. */
291
291
          safe_pipe(err_pipe, 0);
292
292
          
293
 
          if ((pid = fork()) == -1 )
294
 
            die(_("cannot fork into background: %s"), NULL, EC_MISC);
 
293
          if ((pid = fork()) == -1)
 
294
            /* fd == -1 since we've not forked, never returns. */
 
295
            send_event(-1, EVENT_FORK_ERR, errno);
295
296
           
296
297
          if (pid != 0)
297
298
            {
312
313
          /* NO calls to die() from here on. */
313
314
          
314
315
          setsid();
315
 
          pid = fork();
316
 
 
317
 
          if (pid != 0 && pid != -1)
 
316
         
 
317
          if ((pid = fork()) == -1)
 
318
            send_event(err_pipe[1], EVENT_FORK_ERR, errno);
 
319
         
 
320
          if (pid != 0)
318
321
            _exit(0);
319
322
        }
320
323
#endif
349
352
   
350
353
   /* if we are to run scripts, we need to fork a helper before dropping root. */
351
354
  daemon->helperfd = -1;
352
 
#ifndef NO_FORK
 
355
#if defined(HAVE_DHCP) && !defined(NO_FORK) 
353
356
  if (daemon->dhcp && daemon->lease_change_command)
354
357
    daemon->helperfd = create_helper(pipewrite, err_pipe[1], script_uid, script_gid, max_fd);
355
358
#endif
380
383
          if (capset(hdr, data) == -1 || prctl(PR_SET_KEEPCAPS, 1) == -1)
381
384
            bad_capabilities = errno;
382
385
                          
383
 
#elif defined(HAVE_SOLARIS_PRIVS)
 
386
#elif defined(HAVE_SOLARIS_NETWORK)
384
387
          /* http://developers.sun.com/solaris/articles/program_privileges.html */
385
388
          priv_set_t *priv_set;
386
389
          
400
403
          if (priv_set)
401
404
            priv_freeset(priv_set);
402
405
 
403
 
#elif defined(HAVE_SOLARIS_NETWORK)
404
 
 
405
 
          bad_capabilities = ENOTSUP;
406
406
#endif    
407
407
 
408
408
          if (bad_capabilities != 0)
482
482
  if (daemon->max_logs != 0)
483
483
    my_syslog(LOG_INFO, _("asynchronous logging enabled, queue limit is %d messages"), daemon->max_logs);
484
484
 
 
485
#ifdef HAVE_DHCP
485
486
  if (daemon->dhcp)
486
487
    {
487
488
      struct dhcp_context *dhcp_tmp;
490
491
        {
491
492
          prettyprint_time(daemon->dhcp_buff2, dhcp_tmp->lease_time);
492
493
          strcpy(daemon->dhcp_buff, inet_ntoa(dhcp_tmp->start));
493
 
          my_syslog(LOG_INFO, 
 
494
          my_syslog(MS_DHCP | LOG_INFO, 
494
495
                    (dhcp_tmp->flags & CONTEXT_STATIC) ? 
495
496
                    _("DHCP, static leases only on %.0s%s, lease time %s") :
 
497
                    (dhcp_tmp->flags & CONTEXT_PROXY) ?
 
498
                    _("DHCP, proxy on subnet %.0s%s%.0s") :
496
499
                    _("DHCP, IP range %s -- %s, lease time %s"),
497
500
                    daemon->dhcp_buff, inet_ntoa(dhcp_tmp->end), daemon->dhcp_buff2);
498
501
        }
499
502
    }
 
503
#endif
500
504
 
501
505
#ifdef HAVE_TFTP
502
506
  if (daemon->options & OPT_TFTP)
506
510
        max_fd = FD_SETSIZE;
507
511
#endif
508
512
 
509
 
      my_syslog(LOG_INFO, "TFTP %s%s %s", 
 
513
      my_syslog(MS_TFTP | LOG_INFO, "TFTP %s%s %s", 
510
514
                daemon->tftp_prefix ? _("root is ") : _("enabled"),
511
515
                daemon->tftp_prefix ? daemon->tftp_prefix: "",
512
516
                daemon->options & OPT_TFTP_SECURE ? _("secure mode") : "");
534
538
      if (daemon->tftp_max > max_fd)
535
539
        {
536
540
          daemon->tftp_max = max_fd;
537
 
          my_syslog(LOG_WARNING, 
 
541
          my_syslog(MS_TFTP | LOG_WARNING, 
538
542
                    _("restricting maximum simultaneous TFTP transfers to %d"), 
539
543
                    daemon->tftp_max);
540
544
        }
582
586
      set_dbus_listeners(&maxfd, &rset, &wset, &eset);
583
587
#endif  
584
588
  
 
589
#ifdef HAVE_DHCP
585
590
      if (daemon->dhcp)
586
591
        {
587
592
          FD_SET(daemon->dhcpfd, &rset);
588
593
          bump_maxfd(daemon->dhcpfd, &maxfd);
589
594
        }
 
595
#endif
590
596
 
591
597
#ifdef HAVE_LINUX_NETWORK
592
598
      FD_SET(daemon->netlinkfd, &rset);
596
602
      FD_SET(piperead, &rset);
597
603
      bump_maxfd(piperead, &maxfd);
598
604
 
599
 
#ifndef NO_FORK
 
605
#ifdef HAVE_DHCP
 
606
#  ifndef NO_FORK
600
607
      while (helper_buf_empty() && do_script_run(now));
601
608
 
602
609
      if (!helper_buf_empty())
604
611
          FD_SET(daemon->helperfd, &wset);
605
612
          bump_maxfd(daemon->helperfd, &maxfd);
606
613
        }
607
 
#else
 
614
#  else
608
615
      /* need this for other side-effects */
609
616
      while (do_script_run(now));
 
617
#  endif
610
618
#endif
611
 
      
 
619
   
612
620
      /* must do this just before select(), when we know no
613
621
         more calls to my_syslog() can occur */
614
622
      set_log_writer(&wset, &maxfd);
662
670
      check_tftp_listeners(&rset, now);
663
671
#endif      
664
672
 
 
673
#ifdef HAVE_DHCP
665
674
      if (daemon->dhcp && FD_ISSET(daemon->dhcpfd, &rset))
666
675
        dhcp_packet(now);
667
676
 
668
 
#ifndef NO_FORK
 
677
#  ifndef NO_FORK
669
678
      if (daemon->helperfd != -1 && FD_ISSET(daemon->helperfd, &wset))
670
679
        helper_write();
 
680
#  endif
671
681
#endif
672
682
 
673
683
    }
737
747
    {
738
748
    case EVENT_DIE:
739
749
      exit(0);
 
750
 
 
751
    case EVENT_FORK_ERR:
 
752
      die(_("cannot fork into background: %s"), NULL, EC_MISC);
740
753
  
741
754
    case EVENT_PIPE_ERR:
742
755
      die(_("failed to create helper: %s"), NULL, EC_MISC);
777
790
            reload_servers(daemon->resolv_files->name);
778
791
            check_servers();
779
792
          }
 
793
#ifdef HAVE_DHCP
780
794
        rerun_scripts();
 
795
#endif
781
796
        break;
782
797
        
783
798
      case EVENT_DUMP:
786
801
        break;
787
802
        
788
803
      case EVENT_ALARM:
 
804
#ifdef HAVE_DHCP
789
805
        if (daemon->dhcp)
790
806
          {
791
807
            lease_prune(NULL, now);
792
808
            lease_update_file(now);
793
809
          }
 
810
#endif
794
811
        break;
795
812
                
796
813
      case EVENT_CHILD:
840
857
          if (daemon->tcp_pids[i] != 0)
841
858
            kill(daemon->tcp_pids[i], SIGALRM);
842
859
        
843
 
#ifndef NO_FORK
 
860
#if defined(HAVE_DHCP) && !defined(NO_FORK)
844
861
        /* handle pending lease transitions */
845
862
        if (daemon->helperfd != -1)
846
863
          {
904
921
          warned = 0;
905
922
          check_servers();
906
923
          if (daemon->options & OPT_RELOAD)
907
 
            cache_reload(daemon->addn_hosts);
 
924
            cache_reload();
908
925
        }
909
926
      else 
910
927
        {
921
938
void clear_cache_and_reload(time_t now)
922
939
{
923
940
  if (daemon->port != 0)
924
 
    cache_reload(daemon->addn_hosts);
 
941
    cache_reload();
925
942
  
 
943
#ifdef HAVE_DHCP
926
944
  if (daemon->dhcp)
927
945
    {
928
946
      if (daemon->options & OPT_ETHERS)
934
952
      lease_update_file(now); 
935
953
      lease_update_dns();
936
954
    }
 
955
#endif
937
956
}
938
957
 
939
958
static int set_dns_listeners(time_t now, fd_set *set, int *maxfdp)
1135
1154
    }
1136
1155
}
1137
1156
 
1138
 
 
 
1157
#ifdef HAVE_DHCP
1139
1158
int make_icmp_sock(void)
1140
1159
{
1141
1160
  int fd;
1258
1277
 
1259
1278
  return gotreply;
1260
1279
}
 
1280
#endif
1261
1281
 
1262
1282