Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nss
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-24 12:03:17 +0100
committerArthur de Jong <arthur@arthurdejong.org>2006-11-24 12:03:17 +0100
commit693dd91108ec97ff9c69095f454ef68d530774fd (patch)
tree2726bb8c93ed75af1db617dd09a79dac50faa743 /nss
parentb713912c29b01568c6ddee3f6c135d20bda2b4ad (diff)
fix problem with allocated array for storing addresses, properly set h_errnop and check empty address (only addresses of other address family) in nss functions, not in read_hostent()
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@114 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nss')
-rw-r--r--nss/hosts.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/nss/hosts.c b/nss/hosts.c
index 5513838..2015488 100644
--- a/nss/hosts.c
+++ b/nss/hosts.c
@@ -50,14 +50,14 @@
/* read a single host entry from the stream, filtering on the
specified address family, result is stored in result
- it will return NSS_STATUS_NOTFOUND if an empty entry was read
- (no addresses in the address family) */
+ it will an empty entry if no addresses in the address family
+ were available */
static enum nss_status read_hostent(
FILE *fp,int af,struct hostent *result,
char *buffer,size_t buflen,int *errnop,int *h_errnop)
{
int32_t tmpint32,tmp2int32,tmp3int32;
- int32_t numaddr,i;
+ int numaddr,i;
int readaf;
size_t bufptr=0;
/* read the host entry */
@@ -66,13 +66,14 @@ static enum nss_status read_hostent(
result->h_addrtype=af;
result->h_length=0;
/* read number of addresses to follow */
- READ_TYPE(fp,numaddr,int32_t);
+ READ_INT32(fp,numaddr);
/* allocate memory for array */
/* Note: this may allocate too much memory (e.g. also for
address records of other address families) but
this is an easy way to do it */
BUF_CHECK(fp,(numaddr+1)*sizeof(char *));
result->h_addr_list=(char **)BUF_CUR;
+ BUF_SKIP((numaddr+1)*sizeof(char *));
/* go through the address list and filter on af */
i=0;
while (--numaddr>=0)
@@ -85,7 +86,7 @@ static enum nss_status read_hostent(
result->h_length=tmp2int32;
/* allocate room in buffer */
BUF_CHECK(fp,tmp2int32);
- READ(fp,BUF_CUR,tmp2int32);
+ READ(fp,BUF_CUR,(size_t)tmp2int32);
result->h_addr_list[i++]=BUF_CUR;
BUF_SKIP(tmp2int32);
}
@@ -96,9 +97,6 @@ static enum nss_status read_hostent(
}
/* null-terminate address list */
result->h_addr_list[i]=NULL;
- /* check read result */
- if (result->h_addr_list[0]==NULL)
- return NSS_STATUS_NOTFOUND;
return NSS_STATUS_SUCCESS;
}
@@ -127,15 +125,17 @@ enum nss_status _nss_ldap_gethostbyname2_r(
READ_RESPONSEHEADER(fp,NSLCD_ACTION_HOST_BYNAME);
READ_RESPONSE_CODE(fp);
retv=read_hostent(fp,af,result,buffer,buflen,errnop,h_errnop);
- /* check read result */
- if (retv==NSS_STATUS_NOTFOUND)
+ /* check result */
+ if (retv!=NSS_STATUS_SUCCESS)
+ return retv;
+ /* check empty address list */
+ if (result->h_addr_list[0]==NULL)
{
+ *errnop=ENOENT;
*h_errnop=NO_ADDRESS;
fclose(fp);
return NSS_STATUS_NOTFOUND;
}
- else if (retv!=NSS_STATUS_SUCCESS)
- return retv;
/* close socket and we're done */
fclose(fp);
return NSS_STATUS_SUCCESS;
@@ -181,14 +181,16 @@ enum nss_status _nss_ldap_gethostbyaddr_r(
READ_RESPONSE_CODE(fp);
retv=read_hostent(fp,af,result,buffer,buflen,errnop,h_errnop);
/* check read result */
- if (retv==NSS_STATUS_NOTFOUND)
+ if (retv!=NSS_STATUS_SUCCESS)
+ return retv;
+ /* check empty address list */
+ if (result->h_addr_list[0]==NULL)
{
+ *errnop=ENOENT;
*h_errnop=NO_ADDRESS;
fclose(fp);
return NSS_STATUS_NOTFOUND;
}
- else if (retv!=NSS_STATUS_SUCCESS)
- return retv;
/* close socket and we're done */
fclose(fp);
return NSS_STATUS_SUCCESS;
@@ -209,6 +211,8 @@ enum nss_status _nss_ldap_gethostent_r(
{
int32_t tmpint32;
enum nss_status retv=NSS_STATUS_NOTFOUND;
+ /* set to NO_RECOVERY in case some error is caught */
+ *h_errnop=NO_RECOVERY;
/* check that we have a valid file descriptor */
if (hostentfp==NULL)
{
@@ -221,9 +225,11 @@ enum nss_status _nss_ldap_gethostent_r(
/* read a response */
READ_RESPONSE_CODE(hostentfp);
retv=read_hostent(hostentfp,AF_INET,result,buffer,buflen,errnop,h_errnop);
- /* do another loop run if we read an ok address or */
+ /* do another loop run if we read an empty address */
}
- while ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_NOTFOUND));
+ while ((retv==NSS_STATUS_SUCCESS)&&(result->h_addr_list[0]==NULL));
+ if (retv==NSS_STATUS_NOTFOUND)
+ *h_errnop=NO_ADDRESS;
return retv;
}