* [PATCH] Do getservbyname{,_r} with NULL protocol differently
@ 2004-04-01 8:34 Jakub Jelinek
2004-04-01 9:04 ` Ulrich Drepper
2004-04-01 9:16 ` Thorsten Kukuk
0 siblings, 2 replies; 3+ messages in thread
From: Jakub Jelinek @ 2004-04-01 8:34 UTC (permalink / raw)
To: Ulrich Drepper, Thorsten Kukuk; +Cc: Glibc hackers
[-- Attachment #1: Type: text/plain, Size: 486 bytes --]
Hi!
It seems at least some Solaris ypserv's put records with name (without
/proto) as keys into services.byservicename map, which is obviously better
than trying /tcp, /udp and fallback. Fallback is still needed, as aliases
are not put into the database without /proto (and for Linux ypserv
which doesn't put them in).
Attached is a glibc patch plus ypserv patch to make Linux ypserv behave like
Solaris (and fix a bug in it which would trim any digits from protocol's
name).
Jakub
[-- Attachment #2: glibc-getservbyname.patch --]
[-- Type: text/plain, Size: 3350 bytes --]
2004-04-01 Jakub Jelinek <jakub@redhat.com>
* nis/nss_nis/nis-service.c (_nss_nis_getservbyname_r): If protocol
is NULL, instead of trying yp_match (name/tcp), yp_match (name/udp),
yp_all, try yp_match (name), yp_all.
--- libc/nis/nss_nis/nis-service.c.jj 2004-04-01 10:09:30.000000000 +0200
+++ libc/nis/nss_nis/nis-service.c 2004-04-01 10:20:36.583954739 +0200
@@ -279,60 +279,56 @@ _nss_nis_getservbyname_r (const char *na
return NSS_STATUS_UNAVAIL;
/* If the protocol is given, we could try if our NIS server knows
- about services.byservicename map. If yes, we only need one query.
- If the protocol is not given, try first name/tcp, then name/udp
- and then fallback to sequential scanning of services.byname map. */
- const char *proto = protocol != NULL ? protocol : "tcp";
- do
+ about services.byservicename map. If yes, we only need one query. */
+ char key[strlen (name) + (protocol ? strlen (protocol) : 0) + 2];
+ char *cp, *result;
+ size_t keylen, len;
+ int int_len;
+
+ /* key is: "name/proto" */
+ cp = stpcpy (key, name);
+ if (protocol)
{
- char key[strlen (name) + strlen (proto) + 2];
- char *cp, *result;
- size_t keylen, len;
- int int_len;
-
- /* key is: "name/proto" */
- cp = stpcpy (key, name);
*cp++ = '/';
- stpcpy (cp, proto);
- keylen = strlen (key);
- status = yperr2nss (yp_match (domain, "services.byservicename", key,
- keylen, &result, &int_len));
- len = int_len;
+ strcpy (cp, protocol);
+ }
+ keylen = strlen (key);
+ status = yperr2nss (yp_match (domain, "services.byservicename", key,
+ keylen, &result, &int_len));
+ len = int_len;
+
+ /* If we found the key, it's ok and parse the result. If not,
+ fall through and parse the complete table. */
+ if (status == NSS_STATUS_SUCCESS)
+ {
+ struct parser_data *pdata = (void *) buffer;
+ int parse_res;
+ char *p;
- /* If we found the key, it's ok and parse the result. If not,
- fall through and parse the complete table. */
- if (status == NSS_STATUS_SUCCESS)
+ if ((size_t) (len + 1) > buflen)
{
- struct parser_data *pdata = (void *) buffer;
- int parse_res;
- char *p;
-
- if ((size_t) (len + 1) > buflen)
- {
- free (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- p = strncpy (buffer, result, len);
- buffer[len] = '\0';
- while (isspace (*p))
- ++p;
free (result);
- parse_res = _nss_files_parse_servent (p, serv, pdata,
- buflen, errnop);
- if (parse_res < 0)
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
+ while (isspace (*p))
+ ++p;
+ free (result);
+ parse_res = _nss_files_parse_servent (p, serv, pdata,
+ buflen, errnop);
+ if (parse_res < 0)
+ {
+ if (parse_res == -1)
+ return NSS_STATUS_TRYAGAIN;
else
- return NSS_STATUS_SUCCESS;
+ return NSS_STATUS_NOTFOUND;
}
+ else
+ return NSS_STATUS_SUCCESS;
}
- while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL));
struct ypall_callback ypcb;
struct search_t req;
[-- Attachment #3: ypserv-servicesbyname.patch --]
[-- Type: text/plain, Size: 630 bytes --]
--- ypserv-2.12.1/scripts/ypMakefile.in.jj 2004-01-20 10:44:54.000000000 +0100
+++ ypserv-2.12.1/scripts/ypMakefile.in 2004-04-01 10:08:27.055695702 +0200
@@ -274,8 +274,9 @@ services.byname: $(SERVICES) $(YPDIR)/Ma
services.byservicename: $(SERVICES) $(YPDIR)/Makefile
@echo "Updating $@..."
@$(AWK) '{ if ($$1 !~ "#" && $$1 != "") { \
- TMP = $$2 ; gsub("[0-9]+","",TMP) ; \
+ split($$2,A,"/") ; TMP = "/" A[2] ; \
print $$1 TMP"\t"$$0 ; \
+ if (! seen[$$1]) { seen[$$1] = 1 ; print $$1"\t"$$0 ; } \
for (N = 3; N <= NF && $$N !~ "#" ; N++) { \
if ($$N !~ "#" && $$N != "") print $$N TMP"\t"$$0 \
} } } ' \
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do getservbyname{,_r} with NULL protocol differently
2004-04-01 8:34 [PATCH] Do getservbyname{,_r} with NULL protocol differently Jakub Jelinek
@ 2004-04-01 9:04 ` Ulrich Drepper
2004-04-01 9:16 ` Thorsten Kukuk
1 sibling, 0 replies; 3+ messages in thread
From: Ulrich Drepper @ 2004-04-01 9:04 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
Applied.
--
⧠Ulrich Drepper ⧠Red Hat, Inc. ⧠444 Castro St ⧠Mountain View, CA â
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Do getservbyname{,_r} with NULL protocol differently
2004-04-01 8:34 [PATCH] Do getservbyname{,_r} with NULL protocol differently Jakub Jelinek
2004-04-01 9:04 ` Ulrich Drepper
@ 2004-04-01 9:16 ` Thorsten Kukuk
1 sibling, 0 replies; 3+ messages in thread
From: Thorsten Kukuk @ 2004-04-01 9:16 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Glibc hackers
On Thu, Apr 01, Jakub Jelinek wrote:
> Hi!
>
> It seems at least some Solaris ypserv's put records with name (without
> /proto) as keys into services.byservicename map, which is obviously better
> than trying /tcp, /udp and fallback. Fallback is still needed, as aliases
> are not put into the database without /proto (and for Linux ypserv
> which doesn't put them in).
> Attached is a glibc patch plus ypserv patch to make Linux ypserv behave like
> Solaris (and fix a bug in it which would trim any digits from protocol's
> name).
Thanks, I applied this to ypserv.
Thorsten
--
Thorsten Kukuk http://www.suse.de/~kukuk/ kukuk@suse.de
SuSE Linux AG Maxfeldstr. 5 D-90409 Nuernberg
--------------------------------------------------------------------
Key fingerprint = A368 676B 5E1B 3E46 CFCE 2D97 F8FD 4E23 56C6 FB4B
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-04-01 9:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-01 8:34 [PATCH] Do getservbyname{,_r} with NULL protocol differently Jakub Jelinek
2004-04-01 9:04 ` Ulrich Drepper
2004-04-01 9:16 ` Thorsten Kukuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).