summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2010-05-15 15:41:23 +0000
committerArthur de Jong <arthur@arthurdejong.org>2010-05-15 15:41:23 +0000
commit361faebcf6bdf30cac386b44fe9c30ea9490554e (patch)
tree8bbf64147606399fc009d23d71f1fb5a59bff5c9
parent5c11f057d90a09e30eaa9a4f321874fb58da036d (diff)
always clear returned buffer when performing attribute mapping (based on a patch by Nalin Dahyabhai <nalin@redhat.com>)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1111 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--nslcd/attmap.c9
-rw-r--r--nslcd/attmap.h6
2 files changed, 10 insertions, 5 deletions
diff --git a/nslcd/attmap.c b/nslcd/attmap.c
index f703345..09b02bb 100644
--- a/nslcd/attmap.c
+++ b/nslcd/attmap.c
@@ -251,20 +251,25 @@ static const char *entry_expand(const char *name,void *expander_attr)
return values[0];
}
-MUST_USE const char *attmap_get_value(MYLDAP_ENTRY *entry,const char *attr,char *buffer,size_t buflen)
+const char *attmap_get_value(MYLDAP_ENTRY *entry,const char *attr,char *buffer,size_t buflen)
{
const char **values;
+ /* check and clear buffer */
+ if ((buffer==NULL)||(buflen<=0))
+ return NULL;
+ buffer[0]='\0';
/* for simple values just return the attribute */
if (attr[0]!='"')
{
values=myldap_get_values(entry,attr);
- if (values==NULL)
+ if ((values==NULL)||(values[0]==NULL))
return NULL;
strncpy(buffer,values[0],buflen);
buffer[buflen-1]='\0';
return buffer;
/* TODO: maybe warn when multiple values are found */
}
+ /* we have an expression, try to parse */
if ( (attr[strlen(attr)-1]!='"') ||
(expr_parse(attr+1,buffer,buflen,entry_expand,(void *)entry)==NULL) )
{
diff --git a/nslcd/attmap.h b/nslcd/attmap.h
index 48578c1..baa6a9a 100644
--- a/nslcd/attmap.h
+++ b/nslcd/attmap.h
@@ -86,11 +86,11 @@ const char **attmap_get_var(enum ldap_map_selector map,const char *name);
/* Set the attribute mapping of the variable to the value specified.
Returns the new value on success. */
-
-const char *attmap_set_mapping(const char **var,const char *value);
+MUST_USE const char *attmap_set_mapping(const char **var,const char *value);
/* Return a value for the attribute, handling the case where attr
- is an expression. */
+ is an expression. On error (e.g. problem parsing expression, attribute
+ value not found) it returns NULL and the buffer is made empty. */
const char *attmap_get_value(MYLDAP_ENTRY *entry,const char *attr,char *buffer,size_t buflen);
/* Add the attributes from attr to the set. The attr argumenent