1 | /* Services file parser in nss_files module. |
2 | Copyright (C) 1996-2021 Free Software Foundation, Inc. |
3 | This file is part of the GNU C Library. |
4 | |
5 | The GNU C Library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. |
9 | |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with the GNU C Library; if not, see |
17 | <https://www.gnu.org/licenses/>. */ |
18 | |
19 | #include <netinet/in.h> |
20 | #include <netdb.h> |
21 | #include <nss.h> |
22 | |
23 | NSS_DECLARE_MODULE_FUNCTIONS (files) |
24 | |
25 | #define ENTNAME servent |
26 | #define DATABASE "services" |
27 | |
28 | struct servent_data {}; |
29 | |
30 | #define TRAILING_LIST_MEMBER s_aliases |
31 | #define TRAILING_LIST_SEPARATOR_P isspace |
32 | #include "files-parse.c" |
33 | #define ISSLASH(c) ((c) == '/') |
34 | LINE_PARSER |
35 | ("#" , |
36 | STRING_FIELD (result->s_name, isspace, 1); |
37 | INT_FIELD (result->s_port, ISSLASH, 10, 0, htons); |
38 | STRING_FIELD (result->s_proto, isspace, 1); |
39 | ) |
40 | |
41 | #include GENERIC |
42 | |
43 | DB_LOOKUP (servbyname, ':', |
44 | strlen (name) + 2 + (proto == NULL ? 0 : strlen (proto)), |
45 | ("%s/%s" , name, proto ?: "" ), |
46 | { |
47 | /* Must match both protocol (if specified) and name. */ |
48 | if (proto != NULL && strcmp (result->s_proto, proto)) |
49 | /* A continue statement here breaks nss_db, because it |
50 | bypasses advancing to the next db entry, and it |
51 | doesn't make nss_files any more efficient. */; |
52 | else |
53 | LOOKUP_NAME (s_name, s_aliases) |
54 | }, |
55 | const char *name, const char *proto) |
56 | |
57 | DB_LOOKUP (servbyport, '=', 21 + (proto ? strlen (proto) : 0), |
58 | ("%zd/%s" , (ssize_t) ntohs (port), proto ?: "" ), |
59 | { |
60 | /* Must match both port and protocol. */ |
61 | if (result->s_port == port |
62 | && (proto == NULL |
63 | || strcmp (result->s_proto, proto) == 0)) |
64 | break; |
65 | }, int port, const char *proto) |
66 | |