~cyphermox/ubuntu/precise/dnsmasq/dbus

« back to all changes in this revision

Viewing changes to src/helper.c

  • Committer: Bazaar Package Importer
  • Author(s): Simon Kelley
  • Date: 2009-02-07 19:25:23 UTC
  • mfrom: (10.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090207192523-zut5qet639v1httx
 * Fix bashism in init script. (closes: #514397)
 * Tweak logging in init script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* dnsmasq is Copyright (c) 2000-2007 Simon Kelley
 
1
/* dnsmasq is Copyright (c) 2000-2009 Simon Kelley
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
10
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
   GNU General Public License for more details.
12
12
     
13
 
  You should have received a copy of the GNU General Public License
14
 
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
15
*/
16
16
 
17
17
#include "dnsmasq.h"
31
31
#ifndef NO_FORK
32
32
 
33
33
static void my_setenv(const char *name, const char *value, int *error);
34
 
 
 
34
 
35
35
struct script_data
36
36
{
37
37
  unsigned char action, hwaddr_len, hwaddr_type;
93
93
              /* kill daemon */
94
94
              send_event(event_fd, EVENT_DIE, 0);
95
95
              /* return error */
96
 
              send_event(err_fd, EVENT_HUSER_ERR, errno);;
 
96
              send_event(err_fd, EVENT_HUSER_ERR, errno);
97
97
            }
98
98
          _exit(0);
99
99
        }
130
130
      /* stringify MAC into dhcp_buff */
131
131
      p = daemon->dhcp_buff;
132
132
      if (data.hwaddr_type != ARPHRD_ETHER || data.hwaddr_len == 0) 
133
 
        p += sprintf(p, "%.2x-", data.hwaddr_type);
 
133
        p += sprintf(p, "%.2x-", data.hwaddr_type);
134
134
      for (i = 0; (i < data.hwaddr_len) && (i < DHCP_CHADDR_MAX); i++)
135
 
        {
136
 
          p += sprintf(p, "%.2x", data.hwaddr[i]);
137
 
          if (i != data.hwaddr_len - 1)
138
 
            p += sprintf(p, ":");
139
 
        }
 
135
        {
 
136
          p += sprintf(p, "%.2x", data.hwaddr[i]);
 
137
          if (i != data.hwaddr_len - 1)
 
138
            p += sprintf(p, ":");
 
139
        }
140
140
      
141
141
      /* and CLID into packet */
142
142
      if (!read_write(pipefd[0], buf, data.clid_len, 1))
237
237
      
238
238
      if (data.hostname_len != 0)
239
239
        {
 
240
          char *dot;
240
241
          hostname = (char *)buf;
241
242
          hostname[data.hostname_len - 1] = 0;
242
243
          if (!canonicalise(hostname))
243
244
            hostname = NULL;
 
245
          else if ((dot = strchr(hostname, '.')))
 
246
            {
 
247
              my_setenv("DNSMASQ_DOMAIN", dot+1, &err);
 
248
              *dot = 0;
 
249
            }
244
250
        }
245
251
      
246
252
      if (data.action == ACTION_OLD_HOSTNAME && hostname)
299
305
{
300
306
  unsigned char *p;
301
307
  size_t size;
302
 
  unsigned int i, hostname_len = 0, clid_len = 0, vclass_len = 0, uclass_len = 0;
 
308
  int i;
 
309
  unsigned int hostname_len = 0, clid_len = 0, vclass_len = 0, uclass_len = 0;
 
310
  
 
311
#ifdef HAVE_DBUS
 
312
  p = extended_hwaddr(lease->hwaddr_type, lease->hwaddr_len,
 
313
                      lease->hwaddr, lease->clid_len, lease->clid, &i);
 
314
  print_mac(daemon->namebuff, p, i);
 
315
  emit_dbus_signal(action, daemon->namebuff, hostname ? hostname : "", inet_ntoa(lease->addr));
 
316
#endif
303
317
 
304
318
  /* no script */
305
319
  if (daemon->helperfd == -1)
320
334
    {
321
335
      struct script_data *new;
322
336
      
323
 
      /* start with resonable size, will almost never need extending. */
 
337
      /* start with reasonable size, will almost never need extending. */
324
338
      if (size < sizeof(struct script_data) + 200)
325
339
        size = sizeof(struct script_data) + 200;
326
340
 
378
392
      memcpy(p, lease->userclass, uclass_len);
379
393
      p += uclass_len;
380
394
    }
381
 
  /* substitute * for space */
382
 
  for (i = 0; i < hostname_len; i++)
 
395
  /* substitute * for space: spaces are allowed in hostnames (for DNS-SD)
 
396
     and are likley to be a security hole in most scripts. */
 
397
  for (i = 0; i < (int)hostname_len; i++)
383
398
    if ((daemon->options & OPT_LEASE_RO) && hostname[i] == ' ')
384
399
      *(p++) = '*';
385
400
    else