lists.arthurdejong.org
RSS feed

nss-pam-ldapd branch master updated. 0.8.12-104-g646dfa8

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd branch master updated. 0.8.12-104-g646dfa8



This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "nss-pam-ldapd".

The branch, master has been updated
       via  646dfa81025a89c50b81bf91dd95fd828606718d (commit)
       via  54a3dbae5500fd7c512b3351c432df240f1b8c13 (commit)
       via  8655355b399127b7771fab6623de3bcc89984e10 (commit)
       via  6c05b7607294b943d8d01d9e282a8b2fec8616a9 (commit)
       via  373196473d567f0264a1af61f30847cbe96985ca (commit)
      from  f56f9267469fe6556fc946036db003b5ca85a7eb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=646dfa81025a89c50b81bf91dd95fd828606718d

commit 646dfa81025a89c50b81bf91dd95fd828606718d
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Mar 3 15:46:19 2013 +0100

    document the trimming expressions in the nslcd.conf(5) manual page

diff --git a/man/nslcd.conf.5.xml b/man/nslcd.conf.5.xml
index 4eb77bb..986f874 100644
--- a/man/nslcd.conf.5.xml
+++ b/man/nslcd.conf.5.xml
@@ -899,19 +899,52 @@
    <varlistentry>
     <term><literal>${attr:+word}</literal></term>
     <listitem><para>
-     (use alternative) will substitbute word if attribute is set, otherwise
-     substitute the empty string
+     (use alternative) will substitbute <literal>word</literal> if attribute
+     is set, otherwise substitute the empty string
+    </para></listitem>
+   </varlistentry>
+   <varlistentry> <!-- since 0.9.0 -->
+    <term><literal>${attr#word}</literal></term>
+    <listitem><para>
+     remove the shortest possible match of <literal>word</literal> from the
+     left of the attribute value
+    </para></listitem>
+   </varlistentry>
+   <varlistentry> <!-- since 0.9.0 (pynslcd only) -->
+    <term><literal>${attr##word}</literal></term>
+    <listitem><para>
+     remove the longest possible match of <literal>word</literal> from the
+     left of the attribute value (<command>pynslcd</command> only)
+    </para></listitem>
+   </varlistentry>
+   <varlistentry> <!-- since 0.9.0 (pynslcd only) -->
+    <term><literal>${attr%word}</literal></term>
+    <listitem><para>
+     remove the shortest possible match of <literal>word</literal> from the
+     right of the attribute value (<command>pynslcd</command> only)
+    </para></listitem>
+   </varlistentry>
+   <varlistentry> <!-- since 0.9.0 (pynslcd only) -->
+    <term><literal>${attr%%word}</literal></term>
+    <listitem><para>
+     remove the longest possible match of <literal>word</literal> from the
+     right of the attribute value (<command>pynslcd</command> only)
     </para></listitem>
    </varlistentry>
   </variablelist>
   <para>
-   Quote (<literal>"</literal>), dollar (<literal>$</literal>) or
+   Only the # matching expression is supported in <command>nslcd</command>
+   and only with the ? wildcard symbol. The <command>pynslcd</command>
+   implementation supports full matching.
+  </para>
+  <para>
+   Quote (<literal>"</literal>), dollar (<literal>$</literal>) and
    backslash (<literal>\</literal>) characters should be escaped with a
    backslash (<literal>\</literal>).
   </para>
   <para>
-   The <command>nslcd</command> daemon checks the expressions to figure
-   out which attributes to fetch from <acronym>LDAP</acronym>.
+   The expressions are checked to figure out which attributes to fetch
+   from <acronym>LDAP</acronym>.
    Some examples to demonstrate how these expressions may be used in
    attribute mapping:
   </para>
@@ -937,6 +970,13 @@
      otherwise leave value empty
     </para></listitem>
    </varlistentry>
+   <varlistentry>
+    <term><literal>"${userPassword#{crypt\}}"</literal></term>
+    <listitem><para>
+     strip the {crypt} prefix from the userPassword attribute, returning
+     the raw hash value
+    </para></listitem>
+   </varlistentry>
   </variablelist>
  </refsect1>
 

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=54a3dbae5500fd7c512b3351c432df240f1b8c13

commit 54a3dbae5500fd7c512b3351c432df240f1b8c13
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Mar 3 14:12:36 2013 +0100

    support trimming expressions with full shell glob matching in pynslcd

diff --git a/pynslcd/expr.py b/pynslcd/expr.py
index 0f2eb2e..24728cc 100644
--- a/pynslcd/expr.py
+++ b/pynslcd/expr.py
@@ -1,7 +1,7 @@
 
 # expr.py - expression handling functions
 #
-# Copyright (C) 2011, 2012 Arthur de Jong
+# Copyright (C) 2011, 2012, 2013 Arthur de Jong
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -28,8 +28,32 @@
 'foo=YY'
 >>> expr.value(dict(bar=['YY', 'ZZ']))
 'foo=YY'
+>>> Expression(r'${passwd#{crypt\}}').value(dict(passwd='{crypt}HASH'))
+'HASH'
+>>> Expression('${var#trim}').value(dict(var='notrimme'))
+'notrimme'
+>>> Expression('${var#?trim}').value(dict(var='xtrimme'))
+'me'
+>>> Expression('${var#*trim}').value(dict(var='xxxtrimme'))
+'me'
+>>> Expression('${var%.txt}').value(dict(var='foo.txt'))
+'foo'
+>>> Expression('${x#$y}').value(dict(x='a/b', y='a'))
+'/b'
+>>> Expression('${var#t*is}').value(dict(var='this is a test'))
+' is a test'
+>>> Expression('${var##t*is}').value(dict(var='this is a test'))
+' a test'
+>>> Expression('${var%t*st}').value(dict(var='this is a test'))
+'this is a '
+>>> Expression('${var%%t*st}').value(dict(var='this is a test'))
+''
 """
 
+import fnmatch
+import re
+
+
 # exported names
 __all__ = ('Expression', )
 
@@ -82,7 +106,17 @@ class DollarExpression(object):
             c = value.next()
             if c == '}':
                 return
-            self.op = c + value.next()
+            elif c == ':':
+                self.op = c + value.next()
+            elif c in ('#', '%'):
+                c2 = value.next()
+                if c2 in ('#', '%'):
+                    c += c2
+                else:
+                    value.back()
+                self.op = c
+            else:
+                raise ValueError('Expecting operator')
             self.expr = Expression(value, endat='}')
         elif c == '(':
             self.name = None
@@ -111,6 +145,18 @@ class DollarExpression(object):
             return value if value else self.expr.value(variables)
         elif self.op == ':+':
             return self.expr.value(variables) if value else ''
+        elif self.op in ('#', '##', '%', '%%'):
+            match = fnmatch.translate(self.expr.value(variables))
+            if self.op == '#':
+                match = match.replace('*', '*?').replace(r'\Z', 
r'(?P<replace>.*)\Z')
+            elif self.op == '##':
+                match = match.replace(r'\Z', r'(?P<replace>.*?)\Z')
+            elif self.op == '%':
+                match = r'(?P<replace>.*)' + match.replace('*', '*?')
+            elif self.op == '%%':
+                match = r'(?P<replace>.*?)' + match
+            match = re.match(match, value)
+            return match.group('replace') if match else value
         elif self.op == 'lower':
             return self.expr.value(variables).lower()
         elif self.op == 'upper':

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=8655355b399127b7771fab6623de3bcc89984e10

commit 8655355b399127b7771fab6623de3bcc89984e10
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Sun Mar 3 15:53:08 2013 +0100

    add tests for trimming expressions

diff --git a/tests/test_expr.c b/tests/test_expr.c
index ed86a6c..3f4e157 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -2,7 +2,7 @@
    test_expr.c - simple tests for the expr module
    This file is part of the nss-pam-ldapd library.
 
-   Copyright (C) 2009, 2011, 2012 Arthur de Jong
+   Copyright (C) 2009, 2011, 2012, 2013 Arthur de Jong
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -52,6 +52,8 @@ static const char *expanderfn(const char *name, void 
UNUSED(*expander_attr))
     return "";
   if (strcmp(name, "null") == 0)
     return NULL;
+  if (strcmp(name, "userPassword") == 0)
+    return "{crypt}HASH";
   else
     return "foobar";
 }
@@ -91,6 +93,17 @@ static void test_expr_parse(void)
   assertstreq(buffer, "afoobarbfoobarec");
   assert(expr_parse("a${test1}b${test2:+${empty:-d$test4}e}c", buffer, 
sizeof(buffer), expanderfn, NULL) != NULL);
   assertstreq(buffer, "afoobarbdfoobarec");
+  /* test ${var#trim} functions */
+  assert(expr_parse("${test1#foo}", buffer, sizeof(buffer), expanderfn, NULL) 
!= NULL);
+  assertstreq(buffer, "bar");
+  assert(expr_parse("${test1#zoo}", buffer, sizeof(buffer), expanderfn, NULL) 
!= NULL);
+  assertstreq(buffer, "foobar");
+  assert(expr_parse("${test1#?oo}", buffer, sizeof(buffer), expanderfn, NULL) 
!= NULL);
+  assertstreq(buffer, "bar");
+  assert(expr_parse("${test1#f\\?o}", buffer, sizeof(buffer), expanderfn, 
NULL) != NULL);
+  assertstreq(buffer, "foobar");
+  assert(expr_parse("${userPassword#{crypt\\}}", buffer, sizeof(buffer), 
expanderfn, NULL) != NULL);
+  assertstreq(buffer, "HASH");
   /* these are errors */
   assert(expr_parse("$&", buffer, sizeof(buffer), expanderfn, NULL) == NULL);
   assert(expr_parse("${a", buffer, sizeof(buffer), expanderfn, NULL) == NULL);

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=6c05b7607294b943d8d01d9e282a8b2fec8616a9

commit 6c05b7607294b943d8d01d9e282a8b2fec8616a9
Author: Arthur de Jong <arthur@arthurdejong.org>
Date:   Fri Jan 4 23:24:33 2013 +0100

    update the trimming expressions code to follow the new coding style

diff --git a/common/expr.c b/common/expr.c
index a71a5e9..c434a14 100644
--- a/common/expr.c
+++ b/common/expr.c
@@ -2,7 +2,7 @@
    expr.c - limited shell-like expression parsing functions
    This file is part of the nss-pam-ldapd library.
 
-   Copyright (C) 2009, 2010, 2011, 2012 Arthur de Jong
+   Copyright (C) 2009, 2010, 2011, 2012, 2013 Arthur de Jong
    Copyright (c) 2012 Thorsten Glaser <t.glaser@tarent.de>
 
    This library is free software; you can redistribute it and/or
@@ -143,66 +143,48 @@ MUST_USE static const char *parse_dollar_expression(
         buffer[0] = '\0';
       }
     }
-    else if (str[*ptr]=='#')
+    else if (str[*ptr] == '#')
     {
       char c;
       const char *cp, *vp;
       int ismatch;
       size_t vallen;
-
-      (*ptr)+=1;
-      cp=str+*ptr;
-      vp=varvalue;
-      ismatch=1;
-      while ((c=*cp++) && c!='}')
+      (*ptr) += 1;
+      cp = str + *ptr;
+      vp = varvalue;
+      ismatch = 1;
+      while (((c = *cp++) != '\0') && (c != '}'))
       {
-        if (ismatch && !*vp)
-        {
-          /* varvalue shorter than trim string */
-          ismatch=0;
-        }
-        if (c=='?')
+        if (ismatch && (*vp =='\0'))
+          ismatch = 0; /* varvalue shorter than trim string */
+        if (c == '?')
         {
           /* match any one character */
-          ++vp;
+          vp++;
           continue;
         }
-        if (c=='\\')
+        if (c == '\\')
         {
-          if (!(c=*cp++))
-          {
-            /* end of input: syntax error */
-            return NULL;
-          }
+          if ((c = *cp++) == '\0')
+            return NULL; /* end of input: syntax error */
           /* escape the next character c */
         }
-        if (ismatch && *vp!=c)
-        {
-          /* they differ */
-          ismatch=0;
-        }
-        ++vp;
+        if (ismatch && (*vp != c))
+          ismatch = 0; /* they differ */
+        vp++;
       }
-      if (!c)
-      {
-        /* end of input: syntax error */
-        return NULL;
-      }
-      /*
-       * at this point, cp points to after the closing }
-       * if ismatch, vp points to the beginning of the
-       * data after trimming, otherwise vp is invalid
-       */
-      --cp;
-      (*ptr)=cp-str;
+      if (c == '\0')
+        return NULL; /* end of input: syntax error */
+      /* at this point, cp points to after the closing } */
+      (*ptr) = cp - str - 1;
+      /* if ismatch, vp points to the beginning of the
+         data after trimming, otherwise vp is invalid */
       if (!ismatch)
-      {
-        vp=varvalue;
-      }
+        vp = varvalue;
       /* now copy the (trimmed or not) value to the buffer */
-      if ((vallen=strlen(vp)+1)>buflen)
+      if ((vallen = strlen(vp) + 1) > buflen)
         return NULL;
-      memcpy(buffer,vp,vallen);
+      memcpy(buffer, vp, vallen);
     }
     else
       return NULL;

http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=373196473d567f0264a1af61f30847cbe96985ca

commit 373196473d567f0264a1af61f30847cbe96985ca
Author: Thorsten Glaser <t.glaser@tarent.de>
Date:   Mon Dec 3 16:16:52 2012 +0100

    allow trimming expressions with ${foo#bar} syntax in nslcd

diff --git a/AUTHORS b/AUTHORS
index 5debe5f..1d9f989 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -119,3 +119,4 @@ Maxim Vetrov <muxas@mail.ru>
 Matthew L. Dailey <matthew.l.dailey@dartmouth.edu>
 Chris Hiestand <chiestand@salk.edu>
 Jon Severinsson <jon@severinsson.net>
+Thorsten Glaser <t.glaser@tarent.de>
diff --git a/common/expr.c b/common/expr.c
index 97fcff8..a71a5e9 100644
--- a/common/expr.c
+++ b/common/expr.c
@@ -3,6 +3,7 @@
    This file is part of the nss-pam-ldapd library.
 
    Copyright (C) 2009, 2010, 2011, 2012 Arthur de Jong
+   Copyright (c) 2012 Thorsten Glaser <t.glaser@tarent.de>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
@@ -142,6 +143,67 @@ MUST_USE static const char *parse_dollar_expression(
         buffer[0] = '\0';
       }
     }
+    else if (str[*ptr]=='#')
+    {
+      char c;
+      const char *cp, *vp;
+      int ismatch;
+      size_t vallen;
+
+      (*ptr)+=1;
+      cp=str+*ptr;
+      vp=varvalue;
+      ismatch=1;
+      while ((c=*cp++) && c!='}')
+      {
+        if (ismatch && !*vp)
+        {
+          /* varvalue shorter than trim string */
+          ismatch=0;
+        }
+        if (c=='?')
+        {
+          /* match any one character */
+          ++vp;
+          continue;
+        }
+        if (c=='\\')
+        {
+          if (!(c=*cp++))
+          {
+            /* end of input: syntax error */
+            return NULL;
+          }
+          /* escape the next character c */
+        }
+        if (ismatch && *vp!=c)
+        {
+          /* they differ */
+          ismatch=0;
+        }
+        ++vp;
+      }
+      if (!c)
+      {
+        /* end of input: syntax error */
+        return NULL;
+      }
+      /*
+       * at this point, cp points to after the closing }
+       * if ismatch, vp points to the beginning of the
+       * data after trimming, otherwise vp is invalid
+       */
+      --cp;
+      (*ptr)=cp-str;
+      if (!ismatch)
+      {
+        vp=varvalue;
+      }
+      /* now copy the (trimmed or not) value to the buffer */
+      if ((vallen=strlen(vp)+1)>buflen)
+        return NULL;
+      memcpy(buffer,vp,vallen);
+    }
     else
       return NULL;
     (*ptr)++; /* skip closing } */

-----------------------------------------------------------------------

Summary of changes:
 AUTHORS              |    1 +
 common/expr.c        |   46 +++++++++++++++++++++++++++++++++++++++++++++-
 man/nslcd.conf.5.xml |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 pynslcd/expr.py      |   50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 tests/test_expr.c    |   15 ++++++++++++++-
 5 files changed, 153 insertions(+), 9 deletions(-)


hooks/post-receive
-- 
nss-pam-ldapd
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits/