aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorBill Paul <wpaul@FreeBSD.org>1995-11-04 19:07:27 +0000
committerBill Paul <wpaul@FreeBSD.org>1995-11-04 19:07:27 +0000
commit215032be8c9f4ecd8344497ee87264dc5232d912 (patch)
treeda8c30759bbe1a24d7b734ca381a4b2edf5f0a64 /lib/libc
parent722fb3ef2c8e6212b22940b14039f55d2fd5346c (diff)
downloadsrc-215032be8c9f4ecd8344497ee87264dc5232d912.tar.gz
src-215032be8c9f4ecd8344497ee87264dc5232d912.zip
Add NIS support to getservent(3) functions (getservbyport() and getservbyname()
both call getservent() to do most of the work, so we only need to modify this file to take care of everybody). Note that there is only one NIS services map (services.byname) even though there are getservbyname() and getservbyport() library functions.
Notes
Notes: svn path=/head/; revision=12082
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/getservent.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c
index 6bee5d3a8beb..9fb47b61a616 100644
--- a/lib/libc/net/getservent.c
+++ b/lib/libc/net/getservent.c
@@ -41,6 +41,12 @@ static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#ifdef YP
+#include <rpc/rpc.h>
+#include <rpcsvc/yp_prot.h>
+#include <rpcsvc/ypclnt.h>
+static int serv_stepping_yp = 0;
+#endif
#define MAXALIASES 35
@@ -50,6 +56,54 @@ static struct servent serv;
static char *serv_aliases[MAXALIASES];
int _serv_stayopen;
+#ifdef YP
+static int
+_getypservent(line)
+ char *line;
+{
+ static char *key = NULL;
+ static int keylen;
+ static char *yp_domain = NULL;
+ char *lastkey, *result;
+ int resultlen;
+ int rv;
+
+ if(!yp_domain) {
+ if(yp_get_default_domain(&yp_domain))
+ return (0);
+ }
+
+ if (!serv_stepping_yp) {
+ if (key)
+ free(key);
+ if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
+ &result, &resultlen))) {
+ free(result);
+ serv_stepping_yp = 0;
+ return(0);
+ }
+ serv_stepping_yp = 1;
+ } else {
+ lastkey = key;
+ rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
+ &keylen, &result, &resultlen);
+ free(lastkey);
+ if (rv) {
+ serv_stepping_yp = 0;
+ return (0);
+ }
+ }
+
+ strncpy(line, result, BUFSIZ - 1);
+ /* getservent() expects lines terminated with \n -- make it happy */
+ strcat(line, "\n");
+
+ free(result);
+
+ return(1);
+}
+#endif
+
void
setservent(f)
int f;
@@ -77,11 +131,25 @@ getservent()
char *p;
register char *cp, **q;
+#ifdef YP
+ if (serv_stepping_yp && _getypservent(line)) {
+ p = (char *)&line;
+ goto unpack;
+ }
+tryagain:
+#endif
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
return (NULL);
again:
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
return (NULL);
+#ifdef YP
+ if (*p == '+') {
+ if (!_getypservent(&line))
+ goto tryagain;
+ }
+unpack:
+#endif
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");