e354a5
From 9980bf0b307368959cb29f3ca3f7446ad92347f1 Mon Sep 17 00:00:00 2001
e354a5
From: Florian Weimer <fweimer@redhat.com>
e354a5
Date: Thu, 16 Jul 2020 16:55:45 +0200
e354a5
Subject: [PATCH 04/11] nss_files: Use generic result pointer in parse_line
e354a5
e354a5
As a result, all parse_line functions have the same prototype, except
e354a5
for that producing struct hostent.  This change is ABI-compatible, so
e354a5
it does not alter the internal GLIBC_PRIVATE ABI (otherwise we should
e354a5
probably have renamed the exported functions).
e354a5
e354a5
A future change will use this to implement a generict fget*ent_r
e354a5
function.
e354a5
e354a5
Tested-by: Carlos O'Donell <carlos@redhat.com>
e354a5
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
e354a5
---
e354a5
 include/nss_files.h         | 48 ++++++++++++---------------------------------
e354a5
 nss/nss_files/files-parse.c |  5 +++--
e354a5
 2 files changed, 15 insertions(+), 38 deletions(-)
e354a5
e354a5
diff --git a/include/nss_files.h b/include/nss_files.h
e354a5
index 54b354a..d0f2681 100644
e354a5
--- a/include/nss_files.h
e354a5
+++ b/include/nss_files.h
e354a5
@@ -26,45 +26,21 @@ FILE *__nss_files_fopen (const char *path);
e354a5
 libc_hidden_proto (__nss_files_fopen)
e354a5
 
e354a5
 struct parser_data;
e354a5
-struct etherent;
e354a5
-struct group;
e354a5
-struct netent;
e354a5
-struct passwd;
e354a5
-struct protoent;
e354a5
-struct rpcent;
e354a5
-struct servent;
e354a5
-struct sgrp;
e354a5
-struct spwd;
e354a5
 
e354a5
 /* Instances of the parse_line function from
e354a5
    nss/nss_files/files-parse.c.  */
e354a5
-extern int _nss_files_parse_etherent (char *line, struct etherent *result,
e354a5
-                                      struct parser_data *data,
e354a5
-                                      size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_grent (char *line, struct group *result,
e354a5
-                                   struct parser_data *data,
e354a5
-                                   size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_netent (char *line, struct netent *result,
e354a5
-                                    struct parser_data *data,
e354a5
-                                    size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_protoent (char *line, struct protoent *result,
e354a5
-                                      struct parser_data *data,
e354a5
-                                      size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_pwent (char *line, struct passwd *result,
e354a5
-                                   struct parser_data *data,
e354a5
-                                   size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_rpcent (char *line, struct rpcent *result,
e354a5
-                                    struct parser_data *data,
e354a5
-                                    size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_servent (char *line, struct servent *result,
e354a5
-                                     struct parser_data *data,
e354a5
-                                     size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_sgent (char *line, struct sgrp *result,
e354a5
-                                   struct parser_data *data,
e354a5
-                                   size_t datalen, int *errnop);
e354a5
-extern int _nss_files_parse_spent (char *line, struct spwd *result,
e354a5
-                                   struct parser_data *data,
e354a5
-                                   size_t datalen, int *errnop);
e354a5
+typedef int nss_files_parse_line (char *line, void *result,
e354a5
+                                  struct parser_data *data,
e354a5
+                                  size_t datalen, int *errnop);
e354a5
+extern nss_files_parse_line _nss_files_parse_etherent;
e354a5
+extern nss_files_parse_line _nss_files_parse_grent;
e354a5
+extern nss_files_parse_line _nss_files_parse_netent;
e354a5
+extern nss_files_parse_line _nss_files_parse_protoent;
e354a5
+extern nss_files_parse_line _nss_files_parse_pwent;
e354a5
+extern nss_files_parse_line _nss_files_parse_rpcent;
e354a5
+extern nss_files_parse_line _nss_files_parse_servent;
e354a5
+extern nss_files_parse_line _nss_files_parse_sgent;
e354a5
+extern nss_files_parse_line _nss_files_parse_spent;
e354a5
 
e354a5
 libnss_files_hidden_proto (_nss_files_parse_etherent)
e354a5
 libc_hidden_proto (_nss_files_parse_grent)
e354a5
diff --git a/nss/nss_files/files-parse.c b/nss/nss_files/files-parse.c
e354a5
index 3820287..c6cd43b 100644
e354a5
--- a/nss/nss_files/files-parse.c
e354a5
+++ b/nss/nss_files/files-parse.c
e354a5
@@ -87,7 +87,7 @@ struct parser_data
e354a5
 #ifdef EXTERN_PARSER
e354a5
 
e354a5
 /* The parser is defined in a different module.  */
e354a5
-extern int parse_line (char *line, struct STRUCTURE *result,
e354a5
+extern int parse_line (char *line, void *result,
e354a5
 		       struct parser_data *data, size_t datalen, int *errnop
e354a5
 		       EXTRA_ARGS_DECL);
e354a5
 
e354a5
@@ -99,10 +99,11 @@ extern int parse_line (char *line, struct STRUCTURE *result,
e354a5
 
e354a5
 # define LINE_PARSER(EOLSET, BODY)					      \
e354a5
 parser_stclass int							      \
e354a5
-parse_line (char *line, struct STRUCTURE *result,			      \
e354a5
+parse_line (char *line, void *generic_result,				      \
e354a5
 	    struct parser_data *data, size_t datalen, int *errnop	      \
e354a5
 	    EXTRA_ARGS_DECL)						      \
e354a5
 {									      \
e354a5
+  struct STRUCTURE *result = generic_result;				      \
e354a5
   ENTDATA_DECL (data)							      \
e354a5
   BUFFER_PREPARE							      \
e354a5
   char *p = strpbrk (line, EOLSET "\n");				      \
e354a5
-- 
e354a5
1.8.3.1
e354a5