Re: Case-insensitive regexps in rlm_files

2010-11-21 Thread Alan DeKok
Brian Candler wrote:
 Alan DeKok wrote:
 - technically this is an incompatible change for existing configs with
   User-Name == /foo/, which would have to change to User-Name == /foo/
   ?  /foo/ isn't supported right now.  So that won't cause any change.
 
 Maybe not supported, but it does work: the unquoted string /foo/ is treated
 as if it were /foo/

  Ah.  I'm not worried about changing that, quote frankly.

  Alan DeKok.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-19 Thread Alan DeKok
Brian Candler wrote:
 The benefit to us in doing this in rlm_files/rlm_fastusers is that when
 these files are rsynced out, freeradius re-reads them without needing a
 restart.

  While the modules are reloaded on HUP, so are the virtual servers.  So
you can put unlang into a file, and it will be reloaded on HUP.

 rlm_fastusers can also be a lot faster than a linear search in unlang.

  Yes, but it's not any faster than the files module.  There's no need
for fastusers any more.

 Furthermore, it also helps that the syntax is limited and line-based, as it
 results in less scope for errors.  It's just a bit too limited without //i.

  ... and many other features, which are in unlang.  I'm wary of
re-implementing the same thing multiple times.

 We currently use our own custom modules which have similar functionality to
 rlm_files and rlm_fastusers with case-insensitive regexp matching, but I'm
 keen to fold this back into mainline if possible. (*)

  It's probably simpler just to add case-insensitive regex matching to
the core.  That way *all* of the modules get the functionality, and not
just users.

  Alan DeKok.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-19 Thread Brian Candler
Alan DeKok wrote:
  The benefit to us in doing this in rlm_files/rlm_fastusers is that when
  these files are rsynced out, freeradius re-reads them without needing a
  restart.
 
   While the modules are reloaded on HUP, so are the virtual servers.  So
 you can put unlang into a file, and it will be reloaded on HUP.

However, rlm_fastusers doesn't even require a HUP: it notices any changed
file and reloads it on demand.  (rlm_files doesn't though).

   It's probably simpler just to add case-insensitive regex matching to
 the core.  That way *all* of the modules get the functionality, and not
 just users.

Absolutely. So the options I see are:


(1) lib/valuepair.c, paircmp()

* before calling regcomp, look for (?i: ... )
* if found, strip it off and add REG_ICASE to regcomp.

Advantages:
- tiny change
- fully backwards compat, regexps like (?i:...) fail to compile today

Disadvantages:
- it's a frig, as we're not really implementing non-capturing groups


(2) Set case-insensitive flag on the value

* Parse /xxx/ and /xxx/i as a PW_STRING containing xxx
* Add new flag 'case_insensitive' to attr_flags
* Use this flag when calling regcomp

Advantages:
- changes parser, but otherwise touches relatively little code
- gives the expected user syntax for regexps

Disadvantages:
- technically this is an incompatible change for existing configs with
  User-Name == /foo/, which would have to change to User-Name == /foo/
  (I think this is very unlikely in practice though)

I'd say (2) looks like the most attractive, what do you think?

As a separate point, I think it's possible to cache the regcomp when do_xlat
is not set.  This would require another field in struct value_pair (to avoid
changing strvalue into a struct).  Worthwhile?

Regards,

Brian.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-19 Thread Alan DeKok
Brian Candler wrote:
 (2) Set case-insensitive flag on the value
 
 * Parse /xxx/ and /xxx/i as a PW_STRING containing xxx
 * Add new flag 'case_insensitive' to attr_flags
 * Use this flag when calling regcomp

  sigh  That's probably better...

 Advantages:
 - changes parser, but otherwise touches relatively little code
 - gives the expected user syntax for regexps
 
 Disadvantages:
 - technically this is an incompatible change for existing configs with
   User-Name == /foo/, which would have to change to User-Name == /foo/

  ?  /foo/ isn't supported right now.  So that won't cause any change.

 As a separate point, I think it's possible to cache the regcomp when do_xlat
 is not set.  This would require another field in struct value_pair (to avoid
 changing strvalue into a struct).  Worthwhile?

  No.  That structure is already too big.

  Alan DeKok.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-19 Thread Brian Candler
Alan DeKok wrote:
  - technically this is an incompatible change for existing configs with
User-Name == /foo/, which would have to change to User-Name == /foo/
 
   ?  /foo/ isn't supported right now.  So that won't cause any change.

Maybe not supported, but it does work: the unquoted string /foo/ is treated
as if it were /foo/

DEFAULT User-Name =~ /foo/, Cleartext-Password := testing
Service-Type = Framed-User,
Framed-Protocol = PPP,
... snip

$ bin/radtest /foo/ testing localhost 1 testing123
Sending Access-Request of id 159 to 127.0.0.1 port 1812
User-Name = /foo/
User-Password = testing
NAS-IP-Address = 127.0.0.1
NAS-Port = 1
rad_recv: Access-Accept packet from host 127.0.0.1 port 1812, id=159, length=71
Service-Type = Framed-User
Framed-Protocol = PPP
... snip
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Case-insensitive regexps in rlm_files

2010-11-18 Thread Brian Candler
In rlm_files, I can't see how to make a case-insensitive regular expression.

-
DEFAULT User-Name =~ (?i:foo)
# nope, not supported by POSIX ERE. Logs:
# Invalid regular expression (?i:foo)

DEFAULT User-Name =~ /foo/i
# actually matches the character sequence /foo/i
-

Am I missing a trick here?

If I make a patch for this, would you prefer the first or second to be
implemented?  The second is nicer to use, but is probably harder to
implement.

The first could be done as a frig by stripping off an outer (?i:  ...  )
and setting the REG_ICASE flag if seen.

Regards,

Brian.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-18 Thread Alan DeKok
Brian Candler wrote:
 In rlm_files, I can't see how to make a case-insensitive regular expression.

  You can't.

 -
 DEFAULT   User-Name =~ (?i:foo)
   # nope, not supported by POSIX ERE. Logs:
   # Invalid regular expression (?i:foo)
 
 DEFAULT User-Name =~ /foo/i

  That isn't valid.  See man users.

 Am I missing a trick here?

$ man unlang

  The users file has a limited set of functionality.  Extending it
is... awkward.

 If I make a patch for this, would you prefer the first or second to be
 implemented?  The second is nicer to use, but is probably harder to
 implement.

  I'd prefer to avoid the users file entirely.  The capability already
exists in the server, in unlang.  I'd suggest using that.

  Alan DeKok.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case-insensitive regexps in rlm_files

2010-11-18 Thread Brian Candler
Alan DeKok wrote:
   I'd prefer to avoid the users file entirely.  The capability already
 exists in the server, in unlang.  I'd suggest using that.

The benefit to us in doing this in rlm_files/rlm_fastusers is that when
these files are rsynced out, freeradius re-reads them without needing a
restart. This is perceived (rightly or wrongly) as making the server more
robust.

rlm_fastusers can also be a lot faster than a linear search in unlang. 
Furthermore, it also helps that the syntax is limited and line-based, as it
results in less scope for errors.  It's just a bit too limited without //i.

We currently use our own custom modules which have similar functionality to
rlm_files and rlm_fastusers with case-insensitive regexp matching, but I'm
keen to fold this back into mainline if possible. (*)

Regards,

Brian.

(*) You don't want our current modules - they use ^^ at the start of a
regexp to turn on case-insensitive matching - but I'm happy to reimplement
them in a cleaner way.
-
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Case insensitive regexps

2004-06-21 Thread Rok Papez
Hello!
Is it possible to do case insensitive regular expression matching in
users file ?
I'd like to replace:
DEFAULT User-Name =~ ^[Aa][Nn][Oo][Nn][Yy][Mm][Oo][Uu][Ss]|[EMAIL PROTECTED]
with something like:
DEFAULT User-Name =~ m/^anonymous|[EMAIL PROTECTED]/i
lower-casing all usernames is not an option ;) since case does matter, just not in this 
case ;))).
--
Lep pozdrav,
Rok Papez.
- 
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html


Re: Case insensitive regexps

2004-06-21 Thread Alan DeKok
Rok Papez [EMAIL PROTECTED] wrote:
 Is it possible to do case insensitive regular expression matching in
 users file ?

  Not really.  The CVS head has patches which should make it easier,
but it's still not done yet.

  Alan DeKok.


- 
List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html