nss-pam-ldapd branch master updated. 0.9.6-25-g7eb1d69
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
nss-pam-ldapd branch master updated. 0.9.6-25-g7eb1d69
- From: Commits of the nss-pam-ldapd project <nss-pam-ldapd-commits [at] lists.arthurdejong.org>
- To: nss-pam-ldapd-commits [at] lists.arthurdejong.org
- Reply-to: nss-pam-ldapd-users [at] lists.arthurdejong.org
- Subject: nss-pam-ldapd branch master updated. 0.9.6-25-g7eb1d69
- Date: Fri, 3 Jun 2016 11:25:31 +0200 (CEST)
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 7eb1d693504a7923cff75e64278af8b3b7bf4ca3 (commit)
via c90a537983f025b7054b48b8be2d3752cbb3d389 (commit)
via fd61bb665b285a51ced803e6ab3164671054c694 (commit)
via 2ba95606dd95f68d423942b51e0e5b8d3d9ec145 (commit)
from 3a4860cd1d7175e7723307c31aeda68c24ef2309 (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=7eb1d693504a7923cff75e64278af8b3b7bf4ca3
commit 7eb1d693504a7923cff75e64278af8b3b7bf4ca3
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Fri Jun 3 00:02:09 2016 +0200
Support ${var:offset:length} in pynslcd
diff --git a/pynslcd/expr.py b/pynslcd/expr.py
index 24728cc..eec505b 100644
--- a/pynslcd/expr.py
+++ b/pynslcd/expr.py
@@ -48,6 +48,22 @@
'this is a '
>>> Expression('${var%%t*st}').value(dict(var='this is a test'))
''
+
+>>> Expression('${test1:0:6}').value(dict(test1='foobar'))
+'foobar'
+>>> Expression('${test1:0:10}').value(dict(test1='foobar'))
+'foobar'
+>>> Expression('${test1:0:3}').value(dict(test1='foobar'))
+'foo'
+>>> Expression('${test1:3:0}').value(dict(test1='foobar'))
+''
+>>> Expression('${test1:3:6}').value(dict(test1='foobar'))
+'bar'
+>>> Expression('${test1:7:0}').value(dict(test1='foobar'))
+''
+>>> Expression('${test1:7:3}').value(dict(test1='foobar'))
+''
+
"""
import fnmatch
@@ -75,6 +91,9 @@ class MyIter(object):
except IndexError:
return None
+ def startswith(self, value):
+ return self.value[self.pos].startswith(value)
+
def back(self):
self.pos -= 1
@@ -107,7 +126,12 @@ class DollarExpression(object):
if c == '}':
return
elif c == ':':
- self.op = c + value.next()
+ if value.startswith('-') or value.startswith('+'):
+ # ${attr:-word} or ${attr:+word}
+ self.op = c + value.next()
+ else:
+ # ${attr:offset:length}
+ self.op = c
elif c in ('#', '%'):
c2 = value.next()
if c2 in ('#', '%'):
@@ -145,6 +169,10 @@ 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 == ':':
+ offset, length = self.expr.value(variables).split(':')
+ offset, length = int(offset), int(length)
+ return value[offset:offset + length]
elif self.op in ('#', '##', '%', '%%'):
match = fnmatch.translate(self.expr.value(variables))
if self.op == '#':
http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=c90a537983f025b7054b48b8be2d3752cbb3d389
commit c90a537983f025b7054b48b8be2d3752cbb3d389
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Thu Jun 2 23:38:08 2016 +0200
Fix pynslcd expression representation
The problem was that the ExpressionMapping string value did not include
the quotes which will cause problems when printing the expression (e.g.
when logging or dumping config, etc.).
diff --git a/pynslcd/attmap.py b/pynslcd/attmap.py
index b64a048..6012d39 100644
--- a/pynslcd/attmap.py
+++ b/pynslcd/attmap.py
@@ -77,7 +77,7 @@ class ExpressionMapping(str):
def __init__(self, value):
"""Parse the expression as a string."""
- self.expression = Expression(value)
+ self.expression = Expression(value[1:-1])
super(ExpressionMapping, self).__init__(value)
def values(self, variables):
@@ -127,7 +127,7 @@ class Attributes(dict):
def __setitem__(self, attribute, mapping):
# translate the mapping into a mapping object
if mapping[0] == '"' and mapping[-1] == '"':
- mapping = ExpressionMapping(mapping[1:-1])
+ mapping = ExpressionMapping(mapping)
elif '(' in mapping:
mapping = FunctionMapping(mapping)
else:
http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=fd61bb665b285a51ced803e6ab3164671054c694
commit fd61bb665b285a51ced803e6ab3164671054c694
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Thu Jun 2 23:22:47 2016 +0200
Add test for running doctests
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 49e9d81..0914e76 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,7 +22,7 @@ TESTS = test_dict test_set test_tio test_expr
test_getpeercred test_cfg \
test_attmap test_myldap.sh test_common test_nsscmds.sh \
test_pamcmds.sh test_manpages.sh test_clock test_tio_timeout
if HAVE_PYTHON
- TESTS += test_pycompile.sh test_pylint.sh
+ TESTS += test_pycompile.sh test_pylint.sh test_doctest.sh
endif
if ENABLE_PYNSLCD
TESTS += test_pynslcd_cache.py
@@ -39,7 +39,8 @@ check_PROGRAMS = test_dict test_set test_tio test_expr
test_getpeercred \
EXTRA_DIST = README nslcd-test.conf usernames.txt testenv.sh test_myldap.sh \
test_nsscmds.sh test_pamcmds.sh test_pamcmds.expect \
test_manpages.sh \
- test_pycompile.sh test_pylint.sh pylint.rc test_pynslcd_cache.py \
+ test_pycompile.sh test_pylint.sh pylint.rc test_doctest.sh \
+ test_pynslcd_cache.py \
setup_slapd.sh config.ldif test.ldif
CLEANFILES = $(EXTRA_PROGRAMS)
diff --git a/tests/test_doctest.sh b/tests/test_doctest.sh
new file mode 100755
index 0000000..eb2613d
--- /dev/null
+++ b/tests/test_doctest.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# test_doctest.sh - run Python doctests
+#
+# Copyright (C) 2016 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
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+set -e
+
+# find source directory
+srcdir="${srcdir-`dirname "$0"`}"
+top_srcdir="${top_srcdir-${srcdir}/..}"
+python="${PYTHON-python}"
+
+# if Python is missing, ignore
+if ! ${python} --version > /dev/null 2> /dev/null
+then
+ echo "Python (${python}) not found"
+ exit 77
+fi
+
+# run doctests
+for dir in "$top_srcdir"/pynslcd "$top_srcdir"/utils
+do
+ echo "Running doctests in `basename $dir`..."
+ (cd "$dir"; ${python} -m doctest -v *.py)
+done
http://arthurdejong.org/git/nss-pam-ldapd/commit/?id=2ba95606dd95f68d423942b51e0e5b8d3d9ec145
commit 2ba95606dd95f68d423942b51e0e5b8d3d9ec145
Author: Giovanni Mascellani <mascellani@poisson.phc.unipi.it>
Date: Mon May 30 13:33:10 2016 +0200
Support substituting expresions of type ${var:offset:length}
diff --git a/common/expr.c b/common/expr.c
index 2b12e74..a5691b5 100644
--- a/common/expr.c
+++ b/common/expr.c
@@ -4,6 +4,7 @@
Copyright (C) 2009-2016 Arthur de Jong
Copyright (c) 2012 Thorsten Glaser <t.glaser@tarent.de>
+ Copyright (c) 2016 Giovanni Mascellani <gio@debian.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -26,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <errno.h>
#include "expr.h"
#include "compat/attrs.h"
@@ -38,6 +40,11 @@ static inline int my_isalpha(const char c)
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
}
+static inline int my_isdigit(const char c)
+{
+ return (c >= '0') && (c <= '9');
+}
+
static inline int my_isalphanum(const char c)
{
return my_isalpha(c) || ((c >= '0') && (c <= '9'));
@@ -127,6 +134,43 @@ MUST_USE static const char *parse_dollar_alternative(
return buffer;
}
+/* handle ${attr:offset:length} expressions */
+MUST_USE static const char *parse_dollar_substring(
+ const char *str, int *ptr, char *buffer, size_t buflen,
+ const char *varvalue)
+{
+ char *tmp;
+ unsigned long int offset, length;
+ size_t varlen;
+ /* parse input */
+ tmp = (char *)str + *ptr;
+ if (!my_isdigit(*tmp))
+ return NULL;
+ errno = 0;
+ offset = strtoul(tmp, &tmp, 10);
+ if ((*tmp != ':') || (errno != 0))
+ return NULL;
+ tmp += 1;
+ errno = 0;
+ length = strtoul(tmp, &tmp, 10);
+ if ((*tmp != '}') || (errno != 0))
+ return NULL;
+ /* don't skip closing '}' here, because it will be skipped later */
+ *ptr += tmp - (str + *ptr);
+ varlen = strlen(varvalue);
+ if (offset > varlen)
+ offset = varlen;
+ if (offset + length > varlen)
+ length = varlen - offset;
+ if (length >= buflen)
+ return NULL;
+ /* everything's ok, copy data; we use memcpy instead of strncpy
+ because we already know the exact lenght in play */
+ memcpy(buffer, varvalue + offset, length);
+ buffer[length] = '\0';
+ return buffer;
+}
+
/* handle ${attr#word} expressions */
MUST_USE static const char *parse_dollar_match(
const char *str, int *ptr, char *buffer, size_t buflen,
@@ -212,6 +256,13 @@ MUST_USE static const char *parse_dollar_expression(
if (parse_dollar_alternative(str, ptr, buffer, buflen, expander,
expander_arg, varvalue) == NULL)
return NULL;
}
+ else if (str[*ptr] == ':')
+ {
+ /* substitute substring of variable */
+ (*ptr) += 1;
+ if (parse_dollar_substring(str, ptr, buffer, buflen, varvalue) == NULL)
+ return NULL;
+ }
else if (str[*ptr] == '#')
{
/* try to strip the remainder value from variable beginning */
diff --git a/man/nslcd.conf.5.xml b/man/nslcd.conf.5.xml
index 0bcdd2d..d221675 100644
--- a/man/nslcd.conf.5.xml
+++ b/man/nslcd.conf.5.xml
@@ -1031,6 +1031,17 @@
is set, otherwise substitute the empty string
</para></listitem>
</varlistentry>
+ <varlistentry> <!-- since 0.9.7 -->
+ <term><literal>${attr:offset:length}</literal></term>
+ <listitem><para>
+ will substitute <literal>length</literal> characters (actually
+ bytes) starting from position <literal>offset</literal> (which
+ is counted starting at zero); the substituted string is
+ truncated if it is too long; in particular, it can be of length
+ zero (if <literal>length</literal> is zero or
+ <literal>offset</literal> falls out of the original string)
+ </para></listitem>
+ </varlistentry>
<varlistentry> <!-- since 0.9.0 -->
<term><literal>${attr#word}</literal></term>
<listitem><para>
diff --git a/tests/test_expr.c b/tests/test_expr.c
index 3f4e157..536341a 100644
--- a/tests/test_expr.c
+++ b/tests/test_expr.c
@@ -3,6 +3,7 @@
This file is part of the nss-pam-ldapd library.
Copyright (C) 2009, 2011, 2012, 2013 Arthur de Jong
+ Copyright (c) 2016 Giovanni Mascellani
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -104,6 +105,21 @@ static void test_expr_parse(void)
assertstreq(buffer, "foobar");
assert(expr_parse("${userPassword#{crypt\\}}", buffer, sizeof(buffer),
expanderfn, NULL) != NULL);
assertstreq(buffer, "HASH");
+ /* test ${var:offset:length} */
+ assert(expr_parse("${test1:0:6}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${test1:0:10}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "foobar");
+ assert(expr_parse("${test1:0:3}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "foo");
+ assert(expr_parse("${test1:3:0}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "");
+ assert(expr_parse("${test1:3:6}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "bar");
+ assert(expr_parse("${test1:7:0}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "");
+ assert(expr_parse("${test1:7:3}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "");
/* these are errors */
assert(expr_parse("$&", buffer, sizeof(buffer), expanderfn, NULL) == NULL);
assert(expr_parse("${a", buffer, sizeof(buffer), expanderfn, NULL) == NULL);
-----------------------------------------------------------------------
Summary of changes:
common/expr.c | 51 ++++++++++++++++++++++++++++++
man/nslcd.conf.5.xml | 11 +++++++
pynslcd/attmap.py | 4 +--
pynslcd/expr.py | 30 +++++++++++++++++-
tests/Makefile.am | 5 +--
tests/{test_pamcmds.sh => test_doctest.sh} | 26 +++++++--------
tests/test_expr.c | 16 ++++++++++
7 files changed, 125 insertions(+), 18 deletions(-)
copy tests/{test_pamcmds.sh => test_doctest.sh} (65%)
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/
- nss-pam-ldapd branch master updated. 0.9.6-25-g7eb1d69,
Commits of the nss-pam-ldapd project