Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Andy Hawkins
Hi,

In article <45676db9-d890-14a0-7743-f0340b7d1...@mail.com>,
   john doe wrote:
>> [andy@xcp-dev dnsmasq (hosts-dirs *)]$ git diff --ignore-space-at-eol
>> diff --git a/src/inotify.c b/src/inotify.c
>> old mode 100644
>> new mode 100755
>
> Is the change of the mode intentionel (from 644 to 755)?

No. Probably a combination of my editor and it being accessed via Samba.

The key change is to the content of inotify.c.

Andy


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread john doe

On 2/11/2018 4:58 PM, Andy Hawkins wrote:

Hi,

In article ,
Andy Hawkins wrote:

I could have a look at submitting a patch, but my editor is showing some
very strange indentation of the source, so I suspect I have my tab settings
incorrect. What is the standard setting for tabs on the dnasmasq source
files?


Here's an attempt at a patch. If it needs to be in a different format, then
please let me know. The changes are minimal however, so applying the patch
manually should be trivial.

[andy@xcp-dev dnsmasq (hosts-dirs *)]$ git diff --ignore-space-at-eol
diff --git a/src/inotify.c b/src/inotify.c
old mode 100644
new mode 100755


Is the change of the mode intentionel (from 644 to 755)?


index eda1d56..a655fe2
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -235,8 +235,8 @@ int inotify_check(time_t now)

   /* ignore emacs backups and dotfiles */
   if (in->len == 0 ||
- in->name[in->len - 1] == '~' ||
- (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
+ in->name[strlen(in->name) - 1] == '~' ||
+ (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') ||
   in->name[0] == '.')
 continue;

Hope that helps.

Andy


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss




--
John Doe

___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Lonnie Abelbeck
Dominik,

I'm thinking you do not want to call
--
in->name[strlen(in->name)-1];
--
before testing for "if (in->len == 0"

Lonnie


On Feb 11, 2018, at 10:10 AM, Dominik Derigs  wrote:

> Forgot to attach the proposed patch.
> 
> Best,
> Dominik
> 
> 
> On 11.02.2018 17:02, Dominik Derigs wrote:
>> Hey Andy (and list),
>> 
>> According to the inotify man page, the name buffer will always be
>> null-terminated. Furthermore, the name buffer seems to be allocated in
>> chunks of 16 bytes. I have not found an official confirmation for that.
>> 
>> I the way to go would be: char lastchar = in->name[strlen(in->name)-1];
>> 
>> I have extended your test code by the following two lines:
>> 
>> if(in->name == NULL) continue;
>> printf("DD: strlen: %lu\n", strlen(in->name));
>> char lastchar = in->name[strlen(in->name)-1];
>> printf("DD: strlen last char: %c\n", lastchar);
>> 
>> Here are results obtained with your + my debug output:
>> 
>> For a short filename without ~
>> 
>> ADH: len: 16
>> ADH: name: shortfilename
>> ADH: last char:
>> DD: strlen: 13
>> DD: strlen last char: e
>> 
>> For a short filename with ~
>> 
>> ADH: len: 16
>> ADH: name: shortfilename~
>> ADH: last char:
>> DD: strlen: 14
>> DD: strlen last char: ~
>> 
>> For a long filename without ~
>> 
>> ADH: len: 32
>> ADH: name: veryverylongfilename
>> ADH: last char:
>> DD: strlen: 20
>> DD: strlen last char: e
>> 
>> For a long filename with ~
>> 
>> ADH: len: 32
>> ADH: name: veryverylongfilename~
>> ADH: last char:
>> DD: strlen: 21
>> DD: strlen last char: ~
>> 
>> Best regards,
>> Dominik
>> 
>> 
>> On 11.02.2018 12:57, Andy Hawkins wrote:
>>> Hi,
>>> 
>>> In article ,
>>>  Andy Hawkins wrote:
 In inotify.c, around line 236 is the following code block:
 
  /* ignore emacs backups and dotfiles */
  if (in->len == 0 || 
  in->name[in->len - 1] == '~' ||
  (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
  in->name[0] == '.')
continue;
  
 However, if I create a file called 'fred~' in the directory I've specified
 using dhcp-hostsdir I still get an event in syslog that shows this file is
 being processed:
 
 Feb 11 11:14:34 xcp-gateway dnsmasq[1039]: inotify, new or changed file 
/etc/dnsmasq/dhcp-hosts.d/fred~
>>> Ok, I've done some debugging. I added the following lines:
>>> 
>>> my_syslog(LOG_INFO, "ADH: len: %d", in->len);
>>> my_syslog(LOG_INFO, "ADH: name: %s", in->name);
>>> my_syslog(LOG_INFO, "ADH: last char: %c", in->name[in->len - 1]);
>>> 
>>> And I get the following output:
>>> 
>>> dnsmasq: ADH: len: 16
>>> dnsmasq: ADH: name: fred4~
>>> dnsmasq: ADH: last char:
>>> 
>>> So, it appears that the length in in->len is being interpreted correctly.
>>> 
>>> According to the inotify man page:
>>> 
>>>  The len field counts all of the bytes in name, including the null
>>>  bytes; the length of each inotify_event structure is thus
>>>  sizeof(struct inotify_event)+len.
>>> 
>>> So in fact, 'len' seems to be a fixed length, irrespective of the length of
>>> the file name in the 'name' field.
>>> 
>>> It looks like the check should actually be something like:
>>> 
>>> /* ignore emacs backups and dotfiles */
>>> if (in->len == 0 ||
>>> in->name[strlen(in->name) - 1] == '~' ||
>>> (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') ||
>>> in->name[0] == '.')
>>> 
>>> I guess you may need to check that there's a null in the name somewhere
>>> before using strlen, otherwise you might end up running off the end of the
>>> string. I don't know inotify well enough to know if there's guaranteed to be
>>> a null in there somewhere. The manpage does say that the name field is null
>>> terminated, but I don't know if that's guaranteed or not.
>>> 
>>> I could have a look at submitting a patch, but my editor is showing some
>>> very strange indentation of the source, so I suspect I have my tab settings
>>> incorrect. What is the standard setting for tabs on the dnasmasq source
>>> files?
>>> 
>>> Thanks
>>> 
>>> Andy
>>> 
>>> 
>>> ___
>>> Dnsmasq-discuss mailing list
>>> Dnsmasq-discuss@lists.thekelleys.org.uk
>>> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
> 
> ___
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss@lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Andy Hawkins
Hi,

In article ,
   Andy Hawkins wrote:
> I could have a look at submitting a patch, but my editor is showing some
> very strange indentation of the source, so I suspect I have my tab settings
> incorrect. What is the standard setting for tabs on the dnasmasq source
> files?

Here's an attempt at a patch. If it needs to be in a different format, then
please let me know. The changes are minimal however, so applying the patch
manually should be trivial.

[andy@xcp-dev dnsmasq (hosts-dirs *)]$ git diff --ignore-space-at-eol
diff --git a/src/inotify.c b/src/inotify.c
old mode 100644
new mode 100755
index eda1d56..a655fe2
--- a/src/inotify.c
+++ b/src/inotify.c
@@ -235,8 +235,8 @@ int inotify_check(time_t now)

  /* ignore emacs backups and dotfiles */
  if (in->len == 0 ||
- in->name[in->len - 1] == '~' ||
- (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
+ in->name[strlen(in->name) - 1] == '~' ||
+ (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') ||
  in->name[0] == '.')
continue;

Hope that helps.

Andy


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Dominik Derigs
Forgot to attach the proposed patch.

Best,
Dominik


On 11.02.2018 17:02, Dominik Derigs wrote:
> Hey Andy (and list),
>
> According to the inotify man page, the name buffer will always be
> null-terminated. Furthermore, the name buffer seems to be allocated in
> chunks of 16 bytes. I have not found an official confirmation for that.
>
> I the way to go would be: char lastchar = in->name[strlen(in->name)-1];
>
> I have extended your test code by the following two lines:
>
> if(in->name == NULL) continue;
> printf("DD: strlen: %lu\n", strlen(in->name));
> char lastchar = in->name[strlen(in->name)-1];
> printf("DD: strlen last char: %c\n", lastchar);
>
> Here are results obtained with your + my debug output:
>
> For a short filename without ~
>
> ADH: len: 16
> ADH: name: shortfilename
> ADH: last char:
> DD: strlen: 13
> DD: strlen last char: e
>
> For a short filename with ~
>
> ADH: len: 16
> ADH: name: shortfilename~
> ADH: last char:
> DD: strlen: 14
> DD: strlen last char: ~
>
> For a long filename without ~
>
> ADH: len: 32
> ADH: name: veryverylongfilename
> ADH: last char:
> DD: strlen: 20
> DD: strlen last char: e
>
> For a long filename with ~
>
> ADH: len: 32
> ADH: name: veryverylongfilename~
> ADH: last char:
> DD: strlen: 21
> DD: strlen last char: ~
>
> Best regards,
> Dominik
>
>
> On 11.02.2018 12:57, Andy Hawkins wrote:
>> Hi,
>>
>> In article ,
>>Andy Hawkins wrote:
>>> In inotify.c, around line 236 is the following code block:
>>>
>>>   /* ignore emacs backups and dotfiles */
>>>   if (in->len == 0 || 
>>>   in->name[in->len - 1] == '~' ||
>>>   (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
>>>   in->name[0] == '.')
>>> continue;
>>>   
>>> However, if I create a file called 'fred~' in the directory I've specified
>>> using dhcp-hostsdir I still get an event in syslog that shows this file is
>>> being processed:
>>>
>>> Feb 11 11:14:34 xcp-gateway dnsmasq[1039]: inotify, new or changed file 
>>> /etc/dnsmasq/dhcp-hosts.d/fred~
>> Ok, I've done some debugging. I added the following lines:
>>
>>   my_syslog(LOG_INFO, "ADH: len: %d", in->len);
>>   my_syslog(LOG_INFO, "ADH: name: %s", in->name);
>>   my_syslog(LOG_INFO, "ADH: last char: %c", in->name[in->len - 1]);
>>
>> And I get the following output:
>>
>> dnsmasq: ADH: len: 16
>> dnsmasq: ADH: name: fred4~
>> dnsmasq: ADH: last char:
>>
>> So, it appears that the length in in->len is being interpreted correctly.
>>
>> According to the inotify man page:
>>
>>The len field counts all of the bytes in name, including the null
>>bytes; the length of each inotify_event structure is thus
>>sizeof(struct inotify_event)+len.
>>
>> So in fact, 'len' seems to be a fixed length, irrespective of the length of
>> the file name in the 'name' field.
>>
>> It looks like the check should actually be something like:
>>
>>   /* ignore emacs backups and dotfiles */
>>   if (in->len == 0 ||
>>   in->name[strlen(in->name) - 1] == '~' ||
>>   (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') 
>> ||
>>   in->name[0] == '.')
>>
>> I guess you may need to check that there's a null in the name somewhere
>> before using strlen, otherwise you might end up running off the end of the
>> string. I don't know inotify well enough to know if there's guaranteed to be
>> a null in there somewhere. The manpage does say that the name field is null
>> terminated, but I don't know if that's guaranteed or not.
>>
>> I could have a look at submitting a patch, but my editor is showing some
>> very strange indentation of the source, so I suspect I have my tab settings
>> incorrect. What is the standard setting for tabs on the dnasmasq source
>> files?
>>
>> Thanks
>>
>> Andy
>>
>>
>> ___
>> Dnsmasq-discuss mailing list
>> Dnsmasq-discuss@lists.thekelleys.org.uk
>> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

diff --git a/inotify.c b/inotify.c
index b5a17dd..51d13be 100644
--- a/inotify.c
+++ b/inotify.c
@@ -234,9 +234,10 @@ int inotify_check(time_t now)
 	  hit = 1;

 	  /* ignore emacs backups and dotfiles */
+	  char lastchar = in->name[strlen(in->name)-1];
 	  if (in->len == 0 ||
-	  in->name[in->len - 1] == '~' ||
-	  (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
+	  lastchar == '~' ||
+	  (in->name[0] == '#' && lastchar == '#') ||
 	  in->name[0] == '.')
 	continue;

___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Dominik Derigs
Hey Andy (and list),

According to the inotify man page, the name buffer will always be
null-terminated. Furthermore, the name buffer seems to be allocated in
chunks of 16 bytes. I have not found an official confirmation for that.

I the way to go would be: char lastchar = in->name[strlen(in->name)-1];

I have extended your test code by the following two lines:

if(in->name == NULL) continue;
printf("DD: strlen: %lu\n", strlen(in->name));
char lastchar = in->name[strlen(in->name)-1];
printf("DD: strlen last char: %c\n", lastchar);

Here are results obtained with your + my debug output:

For a short filename without ~

ADH: len: 16
ADH: name: shortfilename
ADH: last char:
DD: strlen: 13
DD: strlen last char: e

For a short filename with ~

ADH: len: 16
ADH: name: shortfilename~
ADH: last char:
DD: strlen: 14
DD: strlen last char: ~

For a long filename without ~

ADH: len: 32
ADH: name: veryverylongfilename
ADH: last char:
DD: strlen: 20
DD: strlen last char: e

For a long filename with ~

ADH: len: 32
ADH: name: veryverylongfilename~
ADH: last char:
DD: strlen: 21
DD: strlen last char: ~

Best regards,
Dominik


On 11.02.2018 12:57, Andy Hawkins wrote:
> Hi,
>
> In article ,
>Andy Hawkins wrote:
>> In inotify.c, around line 236 is the following code block:
>>
>>/* ignore emacs backups and dotfiles */
>>if (in->len == 0 || 
>>in->name[in->len - 1] == '~' ||
>>(in->name[0] == '#' && in->name[in->len - 1] == '#') ||
>>in->name[0] == '.')
>>  continue;
>>
>> However, if I create a file called 'fred~' in the directory I've specified
>> using dhcp-hostsdir I still get an event in syslog that shows this file is
>> being processed:
>>
>> Feb 11 11:14:34 xcp-gateway dnsmasq[1039]: inotify, new or changed file 
>>  /etc/dnsmasq/dhcp-hosts.d/fred~
> Ok, I've done some debugging. I added the following lines:
>
>   my_syslog(LOG_INFO, "ADH: len: %d", in->len);
>   my_syslog(LOG_INFO, "ADH: name: %s", in->name);
>   my_syslog(LOG_INFO, "ADH: last char: %c", in->name[in->len - 1]);
>
> And I get the following output:
>
> dnsmasq: ADH: len: 16
> dnsmasq: ADH: name: fred4~
> dnsmasq: ADH: last char:
>
> So, it appears that the length in in->len is being interpreted correctly.
>
> According to the inotify man page:
>
>The len field counts all of the bytes in name, including the null
>bytes; the length of each inotify_event structure is thus
>sizeof(struct inotify_event)+len.
>
> So in fact, 'len' seems to be a fixed length, irrespective of the length of
> the file name in the 'name' field.
>
> It looks like the check should actually be something like:
>
>   /* ignore emacs backups and dotfiles */
>   if (in->len == 0 ||
>   in->name[strlen(in->name) - 1] == '~' ||
>   (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') ||
>   in->name[0] == '.')
>
> I guess you may need to check that there's a null in the name somewhere
> before using strlen, otherwise you might end up running off the end of the
> string. I don't know inotify well enough to know if there's guaranteed to be
> a null in there somewhere. The manpage does say that the name field is null
> terminated, but I don't know if that's guaranteed or not.
>
> I could have a look at submitting a patch, but my editor is showing some
> very strange indentation of the source, so I suspect I have my tab settings
> incorrect. What is the standard setting for tabs on the dnasmasq source
> files?
>
> Thanks
>
> Andy
>
>
> ___
> Dnsmasq-discuss mailing list
> Dnsmasq-discuss@lists.thekelleys.org.uk
> http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Andy Hawkins
Hi,

In article ,
   Andy Hawkins wrote:
> In inotify.c, around line 236 is the following code block:
>
> /* ignore emacs backups and dotfiles */
> if (in->len == 0 || 
> in->name[in->len - 1] == '~' ||
> (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
> in->name[0] == '.')
>   continue;
> 
> However, if I create a file called 'fred~' in the directory I've specified
> using dhcp-hostsdir I still get an event in syslog that shows this file is
> being processed:
>
> Feb 11 11:14:34 xcp-gateway dnsmasq[1039]: inotify, new or changed file 
>   /etc/dnsmasq/dhcp-hosts.d/fred~

Ok, I've done some debugging. I added the following lines:

  my_syslog(LOG_INFO, "ADH: len: %d", in->len);
  my_syslog(LOG_INFO, "ADH: name: %s", in->name);
  my_syslog(LOG_INFO, "ADH: last char: %c", in->name[in->len - 1]);

And I get the following output:

dnsmasq: ADH: len: 16
dnsmasq: ADH: name: fred4~
dnsmasq: ADH: last char:

So, it appears that the length in in->len is being interpreted correctly.

According to the inotify man page:

   The len field counts all of the bytes in name, including the null
   bytes; the length of each inotify_event structure is thus
   sizeof(struct inotify_event)+len.

So in fact, 'len' seems to be a fixed length, irrespective of the length of
the file name in the 'name' field.

It looks like the check should actually be something like:

  /* ignore emacs backups and dotfiles */
  if (in->len == 0 ||
  in->name[strlen(in->name) - 1] == '~' ||
  (in->name[0] == '#' && in->name[strlen(in->name) - 1] == '#') ||
  in->name[0] == '.')

I guess you may need to check that there's a null in the name somewhere
before using strlen, otherwise you might end up running off the end of the
string. I don't know inotify well enough to know if there's guaranteed to be
a null in there somewhere. The manpage does say that the name field is null
terminated, but I don't know if that's guaranteed or not.

I could have a look at submitting a patch, but my editor is showing some
very strange indentation of the source, so I suspect I have my tab settings
incorrect. What is the standard setting for tabs on the dnasmasq source
files?

Thanks

Andy


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Andy Hawkins
Hi,

In article <20180211083655.gy21...@gpm.stappers.nl>,
   Geert Stappers wrote:
> I do read that statement as 80% of needed source code already present.
> Craft the missing source code into a patch, posted to here
> and see what happens.

I decided to do exactly that, and started looking at the code. It looks like
it should already be ignoring files that end in a ~. However, on my version
it's not.

In inotify.c, around line 236 is the following code block:

  /* ignore emacs backups and dotfiles */
  if (in->len == 0 || 
  in->name[in->len - 1] == '~' ||
  (in->name[0] == '#' && in->name[in->len - 1] == '#') ||
  in->name[0] == '.')
continue;
  
However, if I create a file called 'fred~' in the directory I've specified
using dhcp-hostsdir I still get an event in syslog that shows this file is
being processed:

Feb 11 11:14:34 xcp-gateway dnsmasq[1039]: inotify, new or changed file 
/etc/dnsmasq/dhcp-hosts.d/fred~

This suggest that either I'm reading the code incorrectly (perfectly
possible!) or that the code isn't doing what it is supposed to do?

Which is it? Anyone?

Thanks

Andy


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] Extension to hosts-dir and dhcohosts-dir

2018-02-11 Thread Geert Stappers
On Thu, Feb 08, 2018 at 09:11:43PM -, Andy Hawkins wrote:
> In article <20180208164432.GA97242@wopr>, Kurt H Maier wrote:
> > You should fix the editor; that behavior is dangerous for other reasons,
> > similar to the ones outlined here:
> > http://openwall.com/lists/oss-security/2017/11/27/2
> 
> I take your point. However, given that the facility is available for config
> files, I don't see any reason why it shouldn't be extended to other
> directories that contain files that are designed to be modified while
> dnsmasq is running.

I do read that statement as 80% of needed source code already present.
Craft the missing source code into a patch, posted to here
and see what happens.


Groeten
Geert Stappers
-- 
Leven en laten leven

___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss