"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "common/expr.c" between
nss-pam-ldapd-0.9.11.tar.gz and nss-pam-ldapd-0.9.12.tar.gz

About: nss-pam-ldapd is a Name Service Switch (NSS) module and Pluggable Authentication Module (PAM) that allows your LDAP server to provide user account, group, host name, alias, netgroup, and basically any other information that you would normally get from /etc flat files or NIS. It also allows you to do authentication to an LDAP server.

expr.c  (nss-pam-ldapd-0.9.11):expr.c  (nss-pam-ldapd-0.9.12)
/* /*
expr.c - limited shell-like expression parsing functions expr.c - limited shell-like expression parsing functions
This file is part of the nss-pam-ldapd library. 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) 2012 Thorsten Glaser <t.glaser@tarent.de>
Copyright (c) 2016 Giovanni Mascellani <gio@debian.org> Copyright (c) 2016 Giovanni Mascellani <gio@debian.org>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. 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, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
skipping to change at line 50 skipping to change at line 50
return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')); return ((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z'));
} }
static inline int my_isdigit(const char c) static inline int my_isdigit(const char c)
{ {
return (c >= '0') && (c <= '9'); return (c >= '0') && (c <= '9');
} }
static inline int my_isalphanum(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 */ /* return the part of the string that is a valid name */
MUST_USE static const char *parse_name(const char *str, int *ptr, MUST_USE static const char *parse_name(const char *str, int *ptr,
char *buffer, size_t buflen) char *buffer, size_t buflen, int extra_ch ars)
{ {
int i = 0; int i = 0;
/* clear the buffer */ /* clear the buffer */
buffer[i] = '\0'; buffer[i] = '\0';
/* look for an alpha + alphanumeric* string */ /* look for an alpha + alphanumeric* string */
if (!my_isalpha(str[*ptr])) if (!my_isalpha(str[*ptr]))
return NULL; 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) if ((size_t)i >= buflen)
return NULL; return NULL;
buffer[i++] = str[(*ptr)++]; buffer[i++] = str[(*ptr)++];
} }
/* NULL-terminate the string */ /* NULL-terminate the string */
if ((size_t)i >= buflen) if ((size_t)i >= buflen)
return NULL; return NULL;
buffer[i++] = '\0'; buffer[i++] = '\0';
return buffer; return buffer;
skipping to change at line 233 skipping to change at line 233
expr_expander_func expander, void *expander_arg) expr_expander_func expander, void *expander_arg)
{ {
char varname[MAXVARLENGTH]; char varname[MAXVARLENGTH];
const char *varvalue; const char *varvalue;
if ((buflen <= 0) || (buffer == NULL) || (str == NULL) || (ptr == NULL)) if ((buflen <= 0) || (buffer == NULL) || (str == NULL) || (ptr == NULL))
return NULL; return NULL;
if (str[*ptr] == '{') if (str[*ptr] == '{')
{ {
(*ptr)++; (*ptr)++;
/* the first part is always a variable name */ /* 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; return NULL;
varvalue = expander(varname, expander_arg); varvalue = expander(varname, expander_arg);
if (varvalue == NULL) if (varvalue == NULL)
varvalue = ""; varvalue = "";
if (str[*ptr] == '}') if (str[*ptr] == '}')
{ {
/* simple substitute */ /* simple substitute */
if (strlen(varvalue) >= buflen) if (strlen(varvalue) >= buflen)
return NULL; return NULL;
strcpy(buffer, varvalue); strcpy(buffer, varvalue);
skipping to change at line 280 skipping to change at line 280
if (parse_dollar_match(str, ptr, buffer, buflen, varvalue) == NULL) if (parse_dollar_match(str, ptr, buffer, buflen, varvalue) == NULL)
return NULL; return NULL;
} }
else else
return NULL; return NULL;
(*ptr)++; /* skip closing } */ (*ptr)++; /* skip closing } */
} }
else else
{ {
/* it is a simple reference to a variable, like $uidNumber */ /* 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; return NULL;
varvalue = expander(varname, expander_arg); varvalue = expander(varname, expander_arg);
if (varvalue == NULL) if (varvalue == NULL)
varvalue = ""; varvalue = "";
if (strlen(varvalue) >= buflen) if (strlen(varvalue) >= buflen)
return NULL; return NULL;
strcpy(buffer, varvalue); strcpy(buffer, varvalue);
} }
return buffer; return buffer;
} }
skipping to change at line 355 skipping to change at line 355
/* go over string */ /* go over string */
while (str[i] != '\0') while (str[i] != '\0')
{ {
switch (str[i]) switch (str[i])
{ {
case '$': /* beginning of a $-expression */ case '$': /* beginning of a $-expression */
i++; i++;
if (str[i] == '{') if (str[i] == '{')
i++; i++;
/* the rest should start with a variable name */ /* 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); set_add(set, varname);
break; break;
case '\\': /* escaped character, unescape */ case '\\': /* escaped character, unescape */
i++; i++;
FALLTHROUGH; /* no break needed here */ FALLTHROUGH; /* no break needed here */
default: /* just skip */ default: /* just skip */
i++; i++;
} }
} }
return set; return set;
 End of changes. 7 change blocks. 
7 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)