nss-pam-ldapd branch master updated. 0.9.11-14-g7d81616
[
Date Prev][
Date Next]
[
Thread Prev][
Thread Next]
nss-pam-ldapd branch master updated. 0.9.11-14-g7d81616
- 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, nss-pam-ldapd-commits [at] lists.arthurdejong.org
- Subject: nss-pam-ldapd branch master updated. 0.9.11-14-g7d81616
- Date: Sun, 17 Oct 2021 21:13:13 +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 7d81616a991cf2a7f4ca12ae9d420baf54b116ff (commit)
from 6d5a2eb0ed9f9090c354852c520c3504b365cf7d (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 -----------------------------------------------------------------
https://arthurdejong.org/git/nss-pam-ldapd/commit/?id=7d81616a991cf2a7f4ca12ae9d420baf54b116ff
commit 7d81616a991cf2a7f4ca12ae9d420baf54b116ff
Author: Arthur de Jong <arthur@arthurdejong.org>
Date: Sun Oct 17 20:56:44 2021 +0200
Support minus character in attribute expressions
This requires the attribute name is contained within a ${var-name}
expression.
diff --git a/common/expr.c b/common/expr.c
index 545828b..ce10f67 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-2016 Arthur de Jong
+ Copyright (C) 2009-2021 Arthur de Jong
Copyright (c) 2012 Thorsten Glaser <t.glaser@tarent.de>
Copyright (c) 2016 Giovanni Mascellani <gio@debian.org>
@@ -47,12 +47,12 @@ static inline int my_isdigit(const char c)
static inline int my_isalphanum(const char c)
{
- return my_isalpha(c) || ((c >= '0') && (c <= '9'));
+ return my_isalpha(c) || my_isdigit(c);
}
/* return the part of the string that is a valid name */
MUST_USE static const char *parse_name(const char *str, int *ptr,
- char *buffer, size_t buflen)
+ char *buffer, size_t buflen, int
extra_chars)
{
int i = 0;
/* clear the buffer */
@@ -60,7 +60,7 @@ MUST_USE static const char *parse_name(const char *str, int
*ptr,
/* look for an alpha + alphanumeric* string */
if (!my_isalpha(str[*ptr]))
return NULL;
- while (my_isalphanum(str[*ptr]) || (str[*ptr] == ';'))
+ while (my_isalphanum(str[*ptr]) || (str[*ptr] == ';') || (extra_chars &&
((str[*ptr] == '-') || (str[*ptr] == '.'))))
{
if ((size_t)i >= buflen)
return NULL;
@@ -230,7 +230,7 @@ MUST_USE static const char *parse_dollar_expression(
{
(*ptr)++;
/* the first part is always a variable name */
- if (parse_name(str, ptr, varname, sizeof(varname)) == NULL)
+ if (parse_name(str, ptr, varname, sizeof(varname), 1) == NULL)
return NULL;
varvalue = expander(varname, expander_arg);
if (varvalue == NULL)
@@ -277,7 +277,7 @@ MUST_USE static const char *parse_dollar_expression(
else
{
/* it is a simple reference to a variable, like $uidNumber */
- if (parse_name(str, ptr, varname, sizeof(varname)) == NULL)
+ if (parse_name(str, ptr, varname, sizeof(varname), 0) == NULL)
return NULL;
varvalue = expander(varname, expander_arg);
if (varvalue == NULL)
@@ -352,7 +352,7 @@ SET *expr_vars(const char *str, SET *set)
if (str[i] == '{')
i++;
/* the rest should start with a variable name */
- if (parse_name(str, &i, varname, sizeof(varname)) != NULL)
+ if (parse_name(str, &i, varname, sizeof(varname), 0) != NULL)
set_add(set, varname);
break;
case '\\': /* escaped character, unescape */
diff --git a/tests/test_expr.c b/tests/test_expr.c
index 536341a..e0f1581 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, 2013 Arthur de Jong
+ Copyright (C) 2009-2021 Arthur de Jong
Copyright (c) 2016 Giovanni Mascellani
This library is free software; you can redistribute it and/or
@@ -37,14 +37,22 @@ static void test_parse_name(void)
char buffer[20];
int i;
i = 0;
- assert(parse_name("fooBar", &i, buffer, sizeof(buffer)) != NULL);
+ assert(parse_name("fooBar", &i, buffer, sizeof(buffer), 0) != NULL);
assert(i == 6);
i = 0;
- assert(parse_name("nameThatWillNotFitInBuffer", &i, buffer, sizeof(buffer))
== NULL);
+ assert(parse_name("nameThatWillNotFitInBuffer", &i, buffer, sizeof(buffer),
0) == NULL);
i = 0;
- assert(parse_name("foo Bar", &i, buffer, sizeof(buffer)) != NULL);
+ assert(parse_name("foo Bar", &i, buffer, sizeof(buffer), 0) != NULL);
assert(i == 3);
assertstreq(buffer, "foo");
+ i = 0;
+ assert(parse_name("foo-Bar", &i, buffer, sizeof(buffer), 0) != NULL);
+ assert(i == 3);
+ assertstreq(buffer, "foo");
+ i = 0;
+ assert(parse_name("foo-Bar", &i, buffer, sizeof(buffer), 1) != NULL);
+ assert(i == 7);
+ assertstreq(buffer, "foo-Bar");
}
static const char *expanderfn(const char *name, void UNUSED(*expander_attr))
@@ -70,6 +78,10 @@ static void test_expr_parse(void)
assertstreq(buffer, "");
assert(expr_parse("$foo1$empty-$foo2", buffer, sizeof(buffer), expanderfn,
NULL) != NULL);
assertstreq(buffer, "foobar-foobar");
+ assert(expr_parse("$test-var", buffer, sizeof(buffer), expanderfn, NULL) !=
NULL);
+ assertstreq(buffer, "foobar-var");
+ assert(expr_parse("${test-var}", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
+ assertstreq(buffer, "foobar");
assert(expr_parse("$foo1+$null+$foo2", buffer, sizeof(buffer), expanderfn,
NULL) != NULL);
assertstreq(buffer, "foobar++foobar");
assert(expr_parse("${test1}\\$", buffer, sizeof(buffer), expanderfn, NULL)
!= NULL);
-----------------------------------------------------------------------
Summary of changes:
common/expr.c | 14 +++++++-------
tests/test_expr.c | 20 ++++++++++++++++----
2 files changed, 23 insertions(+), 11 deletions(-)
hooks/post-receive
--
nss-pam-ldapd
- nss-pam-ldapd branch master updated. 0.9.11-14-g7d81616,
Commits of the nss-pam-ldapd project