about summary refs log tree commit diff
path: root/nss/nss_files
diff options
context:
space:
mode:
Diffstat (limited to 'nss/nss_files')
-rw-r--r--nss/nss_files/files-XXX.c2
-rw-r--r--nss/nss_files/files-ethers.c3
-rw-r--r--nss/nss_files/files-grp.c10
-rw-r--r--nss/nss_files/files-hosts.c93
-rw-r--r--nss/nss_files/files-network.c13
-rw-r--r--nss/nss_files/files-parse.c17
-rw-r--r--nss/nss_files/files-proto.c3
-rw-r--r--nss/nss_files/files-pwd.c17
-rw-r--r--nss/nss_files/files-rpc.c3
-rw-r--r--nss/nss_files/files-service.c3
10 files changed, 73 insertions, 91 deletions
diff --git a/nss/nss_files/files-XXX.c b/nss/nss_files/files-XXX.c
index 7291c75d84..b9c3579d5b 100644
--- a/nss/nss_files/files-XXX.c
+++ b/nss/nss_files/files-XXX.c
@@ -144,7 +144,7 @@ internal_getent (struct STRUCTURE *result,
   if (buflen < (int) sizeof *data + 1)
     {
       errno = ERANGE;
-      return NSS_STATUS_NOTFOUND;
+      return NSS_STATUS_TRYAGAIN;
     }
 
   do
diff --git a/nss/nss_files/files-ethers.c b/nss/nss_files/files-ethers.c
index e7579a48bc..b66a3c3d04 100644
--- a/nss/nss_files/files-ethers.c
+++ b/nss/nss_files/files-ethers.c
@@ -33,8 +33,7 @@ struct etherent_data {};
 #define DATAFILE	"/etc/ethers"
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  /* Read the ethernet address: 6 x 8bit hexadecimal number.  */
  {
    size_t cnt;
diff --git a/nss/nss_files/files-grp.c b/nss/nss_files/files-grp.c
index 6d528a6df2..580dfbe3eb 100644
--- a/nss/nss_files/files-grp.c
+++ b/nss/nss_files/files-grp.c
@@ -27,12 +27,10 @@ struct grent_data {};
 #define TRAILING_LIST_MEMBER		gr_mem
 #define TRAILING_LIST_SEPARATOR_P(c)	((c) == ',')
 #include "files-parse.c"
-LINE_PARSER
-(
- STRING_FIELD (result->gr_name, ISCOLON, 0);
- STRING_FIELD (result->gr_passwd, ISCOLON, 0);
- INT_FIELD (result->gr_gid, ISCOLON, 0, 10,);
-)
+/* Our parser function is already defined in fgetgrent.c, so use that.
+   to parse lines from the database file.  */
+extern int parse_line (char *line, struct STRUCTURE *result,
+		       void *buffer, int buflen);
 
 #include "files-XXX.c"
 
diff --git a/nss/nss_files/files-hosts.c b/nss/nss_files/files-hosts.c
index 15f00f31ce..19a0075ecf 100644
--- a/nss/nss_files/files-hosts.c
+++ b/nss/nss_files/files-hosts.c
@@ -43,52 +43,53 @@ struct hostent_data
 #define TRAILING_LIST_SEPARATOR_P	isspace
 #include "files-parse.c"
 LINE_PARSER
-({
-  char *addr;
-
-  STRING_FIELD (addr, isspace, 1);
-
-  /* Parse address.  */
-  if ((_res.options & RES_USE_INET6)
-      && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
-    {
-      result->h_addrtype = AF_INET6;
-      result->h_length = IN6ADDRSZ;
-    }
-  else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
-    {
-      if (_res.options & RES_USE_INET6)
-	{
-	  map_v4v6_address ((char *) entdata->host_addr,
-			    (char *) entdata->host_addr);
-	  result->h_addrtype = AF_INET6;
-	  result->h_length = IN6ADDRSZ;
-	}
-      else
-	{
-	  result->h_addrtype = AF_INET;
-	  result->h_length = INADDRSZ;
-	}
-    }
-  else
-    /* Illegal address: ignore line.  */
-    return 0;
-
-  /* Store a pointer to the address in the expected form.  */
-  entdata->h_addr_ptrs[0] = entdata->host_addr;
-  entdata->h_addr_ptrs[1] = NULL;
-  result->h_addr_list = entdata->h_addr_ptrs;
-
-  /* If we need the host entry in IPv6 form change it now.  */
-  if (_res.options & RES_USE_INET6)
-    {
-      char *bufptr = data->linebuffer;
-      int buflen = (char *) data + datalen - bufptr;
-      map_v4v6_hostent (result, &bufptr, &buflen);
-    }
-
-  STRING_FIELD (result->h_name, isspace, 1);
-})
+("#",
+ {
+   char *addr;
+
+   STRING_FIELD (addr, isspace, 1);
+
+   /* Parse address.  */
+   if ((_res.options & RES_USE_INET6)
+       && inet_pton (AF_INET6, addr, entdata->host_addr) > 0)
+     {
+       result->h_addrtype = AF_INET6;
+       result->h_length = IN6ADDRSZ;
+     }
+   else if (inet_pton (AF_INET, addr, entdata->host_addr) > 0)
+     {
+       if (_res.options & RES_USE_INET6)
+	 {
+	   map_v4v6_address ((char *) entdata->host_addr,
+			     (char *) entdata->host_addr);
+	   result->h_addrtype = AF_INET6;
+	   result->h_length = IN6ADDRSZ;
+	 }
+       else
+	 {
+	   result->h_addrtype = AF_INET;
+	   result->h_length = INADDRSZ;
+	 }
+     }
+   else
+     /* Illegal address: ignore line.  */
+     return 0;
+
+   /* Store a pointer to the address in the expected form.  */
+   entdata->h_addr_ptrs[0] = entdata->host_addr;
+   entdata->h_addr_ptrs[1] = NULL;
+   result->h_addr_list = entdata->h_addr_ptrs;
+
+   /* If we need the host entry in IPv6 form change it now.  */
+   if (_res.options & RES_USE_INET6)
+     {
+       char *bufptr = data->linebuffer;
+       int buflen = (char *) data + datalen - bufptr;
+       map_v4v6_hostent (result, &bufptr, &buflen);
+     }
+
+   STRING_FIELD (result->h_name, isspace, 1);
+ })
 
 #include "files-XXX.c"
 
diff --git a/nss/nss_files/files-network.c b/nss/nss_files/files-network.c
index 504c420b04..c6cd718dd2 100644
--- a/nss/nss_files/files-network.c
+++ b/nss/nss_files/files-network.c
@@ -30,15 +30,16 @@ struct netent_data {};
 #define TRAILING_LIST_SEPARATOR_P	isspace
 #include "files-parse.c"
 LINE_PARSER
-({
-  char *addr;
+("#",
+ {
+   char *addr;
 
-  STRING_FIELD (result->n_name, isspace, 1);
+   STRING_FIELD (result->n_name, isspace, 1);
 
-  STRING_FIELD (addr, isspace, 1);
-  result->n_net = inet_network (addr);
+   STRING_FIELD (addr, isspace, 1);
+   result->n_net = inet_network (addr);
 
-})
+ })
 
 #include "files-XXX.c"
 
diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
index be35ae1a8a..a9c461ef46 100644
--- a/nss/nss_files/files-parse.c
+++ b/nss/nss_files/files-parse.c
@@ -35,7 +35,7 @@ struct parser_data
   {
 #ifdef ENTDATA
     struct ENTDATA entdata;
-#define ENTDATA_DECL(data) struct ENTDATA *const entdata = &data->entdata
+#define ENTDATA_DECL(data) struct ENTDATA *const entdata = &data->entdata;
 #else
 #define ENTDATA_DECL(data)
 #endif
@@ -52,26 +52,21 @@ struct parser_data
 #define parse_line CONCAT(_nss_files_parse_,ENTNAME)
 #endif
 
-#define LINE_PARSER(BODY)						      \
+#define LINE_PARSER(EOLSET, BODY)					      \
 parser_stclass int							      \
 parse_line (char *line, struct STRUCTURE *result,			      \
 	    struct parser_data *data, int datalen)			      \
 {									      \
-  ENTDATA_DECL (data);							      \
+  ENTDATA_DECL (data)							      \
+  char *p = strpbrk (line, EOLSET "\n");				      \
+  if (p)								      \
+    *p = '\0';								      \
   BODY;									      \
   TRAILING_LIST_PARSER;							      \
   return 1;								      \
 }
 
 
-/* Comments can come mid-line; trim the line at the first # seen.  */
-#define MIDLINE_COMMENTS						      \
-  {									      \
-    char *p = strchr (line, '#');					      \
-    if (p)								      \
-      *p = '\0';							      \
-  }
-
 #define STRING_FIELD(variable, terminator_p, swallow)			      \
   {									      \
     variable = line;							      \
diff --git a/nss/nss_files/files-proto.c b/nss/nss_files/files-proto.c
index d67f8db8f6..ef5a7c2560 100644
--- a/nss/nss_files/files-proto.c
+++ b/nss/nss_files/files-proto.c
@@ -29,8 +29,7 @@ struct protoent_data {};
 #define TRAILING_LIST_SEPARATOR_P	isspace
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->p_name, isspace, 1);
  INT_FIELD (result->p_proto, isspace, 1, 10,);
  )
diff --git a/nss/nss_files/files-pwd.c b/nss/nss_files/files-pwd.c
index 4b6a4b737f..6b39116a44 100644
--- a/nss/nss_files/files-pwd.c
+++ b/nss/nss_files/files-pwd.c
@@ -25,19 +25,10 @@ Cambridge, MA 02139, USA.  */
 struct pwent_data {};
 
 #include "files-parse.c"
-LINE_PARSER
-({
-  STRING_FIELD (result->pw_name, ISCOLON, 0);
-  STRING_FIELD (result->pw_passwd, ISCOLON, 0);
-  INT_FIELD (result->pw_uid, ISCOLON, 0, 10,);
-  INT_FIELD (result->pw_gid, ISCOLON, 0, 10,);
-  STRING_FIELD (result->pw_gecos, ISCOLON, 0);
-  STRING_FIELD (result->pw_dir, ISCOLON, 0);
-  result->pw_shell = line;
-  line = strchr (line, '\n');
-  if (line)
-    *line = '\0';
-})
+/* Our parser function is already defined in fgetpwent.c, so use that.
+   to parse lines from the database file.  */
+extern int parse_line (char *line, struct STRUCTURE *result,
+		       void *buffer, int buflen);
 
 #include "files-XXX.c"
 
diff --git a/nss/nss_files/files-rpc.c b/nss/nss_files/files-rpc.c
index fef0ff88b1..f8bef451fa 100644
--- a/nss/nss_files/files-rpc.c
+++ b/nss/nss_files/files-rpc.c
@@ -29,8 +29,7 @@ struct rpcent_data {};
 #define TRAILING_LIST_SEPARATOR_P	isspace
 #include "files-parse.c"
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->r_name, isspace, 1);
  INT_FIELD (result->r_number, isspace, 1, 10,);
  )
diff --git a/nss/nss_files/files-service.c b/nss/nss_files/files-service.c
index 3bcb48787a..f0dba50fe6 100644
--- a/nss/nss_files/files-service.c
+++ b/nss/nss_files/files-service.c
@@ -31,8 +31,7 @@ struct servent_data {};
 #include "files-parse.c"
 #define ISSLASH(c) ((c) == '/')
 LINE_PARSER
-(
- MIDLINE_COMMENTS;
+("#",
  STRING_FIELD (result->s_name, isspace, 1);
  INT_FIELD (result->s_port, ISSLASH, 10, 0, htons);
  STRING_FIELD (result->s_proto, isspace, 1);