Commit Graph

145 Commits

Author SHA1 Message Date
Bill Paul
9c171de035 yp_server.c:
- Fail YPPROC_ALL requests when we hit the child process limit. This
  is a little harsh, but it helps prevent the parent from blocking
  and causing other requests to time out.

yp_dnslookup.c:
- Check for duplicate RPC transaction IDs that indicate duplicate
  requests sent due to RPC retransmissions. We don't want to send
  a second DNS request for the same data while an existing request
  is in progress.

- Fix small formatting bogon in snprintf() in yp_async_lookup_addr().
1997-01-07 06:07:21 +00:00
Bill Paul
cb73ffc8b7 Eek: the 'check for / in map names' test I added a while back detects
slashes in map names but doesn't return failure if it finds them. Add
missing return(1) to fix this.
1997-01-06 06:27:55 +00:00
Peter Wemm
ae5fc38127 Make the select() call work like the others in the system.. ie: don't
assume that the timeval will be preserved.  As the man page says:
".. it is unwise to assume that the timeout value will be unmodified
by the select() call."  This happens on Linux and on my system at least.
1996-12-30 18:51:59 +00:00
Peter Wemm
09dfbc4024 Fix harmless bug found by new pointer-to-function prototypes. 1996-12-30 15:32:43 +00:00
Bill Paul
adc4fa336b More async resolver refinements:
- yp_main.c: Always add the resolver socket to the set of fds
  monitored by select(). It can happen that pending == 0 but we
  still have some data in the socket buffer from an old query.
  This way, the data will be flushed in a timely manner.

- yp_extern.h: remove proto for yp_dns_pending() since we don't need
  it anynmore.

- yp_server.c: call yp_async_lookup_name()/yp_async_lookup_addr()
  functions with the svc_req pointer as an arg instead of the xprt.
  (The svc_req struct includes a pointer to the transport handle,
  and it also has the service version number which the async DNS
  code will need. (see below))

- yp_dnslookup.c:

   o Nuke yp_dns_pending() since we don't need it anymore.
   o In yp_run_dnsq(), swallow up and ignore replies if no requests
     are pending or the ID doesn't match any of the IDs in the queue.
   o In yp_send_dns_reply(), we assume that we will always be
     replying to an NIS v2 client. While this will probably always
     be the case, we do support the v1 'match' procedure, and it
     has a different result struct than v2. For completeness,
     support replying to both NIS v1 and v2 clients.
   o Update the queue entry structure to include a member to
     keep track of the NIS version number.
   o Have yp_async_lookup_name/addr() extract the version number
     from the svc_req structure and save it with the queue entry
     for yp_send_dns_reply() to inspect later.
   o Add some comments.
1996-12-25 18:10:35 +00:00
Bill Paul
926f037af9 Fix some bugs:
- Don't dereference a NULL hostent pointer (if T_PTR lookup fails).

- Today I asked myself: "Self, you wrote this nifty async resolver
  that does a great job handling delayed replies to clients using
  the UDP transport, and the yplib code in libc always uses UDP
  (except for yp_all()). But what if some dork makes a DNS lookup using
  TCP?" Being the only dork on hand at the time, I tried it and was
  enlightened. As I suspected, my transaction ID frobbing hacks cause
  fireworks if called on a TCP transport handle (duh: the structures
  are different). Fix: check the type of socket in xprt->xp_sock using
  getsockopt() and don't use svcudp_get_xid() and svcudp_set_xid() for
  anything except SOCK_DGRAM sockets. (Since accept() gives you a
  new socket for each connection, the transaction ID munging isn't
  needed for TCP anyway.)
1996-12-24 02:44:52 +00:00
Bill Paul
180807d214 Big round o changes:
- yp_dblookup.c: Create non-DB specific database access functions.
  Using these allows access to the underlying database functions without
  needing explicit knowledge of Berkeley DB. (These are used only
  when DB_CACHE is #defined. Other programs that use the non-caching
  functions (yp_mkdb, ypxfr, yppush, rpc.yppasswdd) shouldn't notice
  the difference.)

- yp_dnslookup: Implement async DNS lookups. We send our own DNS
  requests using UDP and put the request in a queue. When the response
  arrives, we use the ID in the header to find the corresponsing queue
  entry and then send the response to the client. We can go about our
  business and handle other YP requests in the meantime. This way, we
  can deal with time consuming DNS requests without blocking and without
  forking.

- yp_server.c: Convert to using new non-DB-specific database access
  functions. This simplifies the code a bit and removes the need for
  this module to know anything about Berkeley DB. Also convert the
  ypproc_match_2_svc() function to use the async DNS lookup routines.

- yp_main.c: tweak yp_svc_run() to add the resolver socket to the
  set of descriptors monitored in the select() loop. Also add a
  timeout to select(); we may get stale DNS requests stuck in the
  queue which we want to invalidate after a while. If the timeout
  hits, we decrement the ttl on all pending DNS requests and nuke
  those requests that aren't handled before ttl hits zero.

- yp_extern.h: Add prototypes for new stuff.

- yp_svc_udp.c (new file): The async resolver code needs to be able
  to rummage around inside the RPC UDP transport handle in order to
  work correcty. There's basically one transport handle, and each time
  a request comes in, the transaction ID in the handle is changed.
  This means that if we queue a DNS request, then we handle some other
  unrelated requests, we will be unable to send the DNS response because
  the transaction ID and remote address of the client that made the DNS
  request will have been lost. What we need to do is save the client
  address and transaction ID in the queue entry for the DNS request,
  then put the transaction ID and address back in the transport handle
  when we're ready to reply. (And then we have to undo the change so
  as not to confuse any other part of the server.) The trouble is that
  the transaction ID is hidden in an opaque part of the transport handle,
  and only the code in the svc_udp module in the RPC library knows how
  to handle it. This file contains a couple of functions that let us
  read and set the transaction ID in spite of this. This is really a
  dirty trick and I should be taken out and shot for even thinking about
  it, but there's no other way to get this stuff to work.

- Makefile: add yp_svc_udp.c to SRCS.
1996-12-22 22:30:58 +00:00
Bill Paul
4c69e7b9d5 Back out the non-forking YPPROC_ALL stuff. Whatever drugs I was doing
when I came up with this idea weren't strong enough to help me see it
through. If this was a self-contained application and I had complete
control over what data got sent through what socket and when, I might
be able to get everything to work right without blocking, but instead
I have RPC/XDR in between me and the socket layer, and they have their
own ideas about what to do.

Maybe one day I'll go totally mad and figure out the right way to do
this; in the meantime this mess goes on the back burner.
1996-12-03 02:37:39 +00:00
Bill Paul
faf215c7ad This commit changes the YPPROC_ALL procecdure so that it handles requests
_without_ using fork().

The problem with YPPROC_ALL is that it transmits an entire map through
a TCP pipe as the result of a single RPC call. First of all, this requires
certain hackery in the XDR filter. Second, if the map being sent is
large, the server can end up spending lots of time in the XDR filter
sending to just the one client, while requests for other clients will
go unanswered.

My original solution for this was to fork() the request into a child
process which terminates after the map has been transmitted (or the
transfer is interrupted due to an error). This leaves the parent free
to handle other requests. But this solution is kind of lame: fork()
is relatively expensive, and we have to keep a cap on the number of
child processes to keep from swamping the system.

What we do now is grab control of the service transport handle and XDR
handle from the RPC library and send the records one at a time ourselves
instead of letting the RPC library do it. We send a record, then go
back to the svc_run() loop and select() on the socket. If select() says
we can still write data, we send the next record. Then we call
svc_getreqset() and handle other RPCs and loop around again. This way,
we can handle other RPCs between records.

We manage multiple YPPROC_ALL requests using a circular queue. When a
request is done, we dequeue it and destroy the handle. We also tag
each request with a ttl which is decremented whevever we run the queue
and a handle isn't serviced. This lets us nuke requests that have sat
idle for too long (if we didn't do this, we might run out of socket
descriptors.)

Now all I have to do is come up with an async resolver, and ypserv
won't need to fork() at all. :)

Note: these changes should not go into 2.2 unless they get a very
throrough shakedown before the final cutoff date.
1996-11-30 22:38:44 +00:00
Bill Paul
58dc15740f Eek! When I added the YP_INTERDOMAIN and YP_SECURE support, I documented
and set the B and S variables here, but I forgot to actually add them to
the master.passwd and hosts.* targets. In other words, they weren't being
passed to yp_mkdb as needed.

This needs to go into 2.2; it doesn't break things a lot, but it leaves
your master.passwd maps available to unprivileged users without you
realizing it.
1996-11-15 18:01:59 +00:00
Bill Paul
4451976029 Add support for handling the YP_SECURE and YP_INTERDOMAIN keys from
any maps that may have them. If the YP_SECURE key is present, ypserv
will only allow access to the map from clients on reserved ports.
If the YP_INTERDOMAIN key is present, the server will do DNS lookups
for hostnames that it can't find in hosts.byname or hosts.byaddr.
This is the same as the -d flag (which is retained for backwards
compatibility) but it can be set on a per-map/per-domain basis.

Also modified /var/yp/Makefile to add YP_INTERDOMAIN to the hosts.*
maps and YP_SECURE to master.passwd.* maps by default.
1996-10-24 18:58:26 +00:00
Bill Paul
746c49fb53 In ypxfr_callback(), the failure to create an RPC CLIENT * handle for
the callback is a fatal error for this function; return immediatlely if
this happens. Also make the "failed to establish callback handle" error
mesaage print the IP address of the target callback host.
1996-10-23 15:49:22 +00:00
Bill Paul
42c703633d Close a potential security hole: if yp_access() is passed a map name,
have it check to see that it doesn't contain any '/' characters. This
prevents possible silliness like ypcat "../../../kernel". We already
test the domain name for this in yp_validdomain(), and ypserv itself
tests the map name in yp_open_db(), but it doesn't hurt to be paranoid
and test for it in the generic access routine too. rpc.ypxfrd does not
test the map name for slashes, but it does call yp_access() with the
map name, so this removes a potential vulnerability from there.

Also make the tests for IPPORT_RESERVED a little more selective: make
sure it trips when map == master.passwd.*, prog == YPPROC and proc ==
YPPROC_XFR, and prog == YPXFRD_FREEBSD_PROG and proc == YPXFRD_GETMAP.
Also use IPPORT_RESERVED instead of hard-coded value.
1996-09-30 22:27:00 +00:00
Bill Paul
616b87f978 Toss the mkaliases script into the attic and remove its install
target from the Makefile. We don't need it anymore, and it was
broken anyway.
1996-09-15 00:39:20 +00:00
Peter Wemm
f1c72c4c70 Hmm, well, whaddya know? ypserv was making calls to the undocumented
private internal _gethostbydnsname() resolver functions..
1996-08-30 01:17:47 +00:00
Mike Pritchard
85cf659a76 Use the .Fx macro where appropriate. 1996-08-23 00:57:08 +00:00
Adam David
d91013b58d was missing @ 1996-08-09 17:55:18 +00:00
Peter Wemm
88b4ff3c6c Fix the services.byname target so that it creates search keys for the
aliases of the "official" names as well, because now that getportbyname()
does a yp match, it no longer found the entries under the alias.
This broke rsh(1), because it looks up "shell/tcp" while the official
name in /etc/services is "cmd/tcp".
1996-07-25 19:32:37 +00:00
Peter Wemm
a6dbeb65a1 Fix typo in last commit, it seems that a hash comments out a \ at the end
of line.

Also, fix existing bug in ethers.byname, it was passing an unknown option
to yppush.  This appears to have been a cut/paste slip intended for a
$(DBLOAD) command above it.
1996-07-24 14:04:57 +00:00
Peter Wemm
57948c0b54 Add sample rules for amd.host, mostly from the AMD docs, but tweaked to fit
the FreeBSD Makefile.yp structure by me.  This allows you to have a single
amd map for all machines in a cluster.

In /etc/sysconfig, it would look something like:
  amdflags="-p -a /net -c 1800 -l syslog /host amd.host"
1996-07-24 10:48:07 +00:00
Adam David
de88f1607c 'mkaliases' is broken (strips spaces) so don't use it,
perhaps it can be removed altogether.
corrected typos
1996-07-18 23:48:13 +00:00
Bill Paul
79acf67fce Re-implement the DB handle cache using a circular queue and manage
it with the CIRCLEQ macros. This simplifies the code a little, makes
it somewhat easier to read, and may be a little faster. (Actually I think
the performace is about the same.)

Also, in the non DB_CACHE case, save copies of data returned from
the database library in a static buffer, just in case we decide to use
it after the database has been closed. Technically, the memory that the
data pointers refer to belongs to the DB package and we can't count on
it being there after the database has been closed -- the DB package
frees its buffers. (With DB_CACHE #defined the databases are held
open so the buffers remain valid.) I don't think any of the utilities
that use the dblookup module have had any problems with this yet, but
there's no sense in taking any chances.
1996-07-07 23:02:41 +00:00
Bill Paul
1fe3e67a3f Toss old mknetid script into the attic.
Adjust things slightly to support the new mknetid program.
1996-06-25 20:28:07 +00:00
Bill Paul
b3e932340d Makefile.yp:
- Add a 'pushpw' target that only yppushes the various passwd maps
  and sends a YPPROC_CLEAR to the local ypserv. This will be used by
  rpc.yppasswdd once I merge in the in-place update changes.

yp_access.c:

- Make the yp_access() function print RPC program and procedure numbers
  that it doesn't know about in literal form. This will allow it to work
  with other prgrams that it doesn't know about, like rpc.ypxfrd I'm going
  to import shortly.

yp_dblookup.c:

- Take out the __inline keywords. They weren't really helping me anyway.

- Somehow I broke yp_next() when DB_CACHE wasn't #defined. Fix it.

- Also fix potential case where yp_next() might loop forever; make sure
  it checks the return values of all the (dbp->seq)()/R_NEXT calls that
  it does as well as comparing keys.
1996-06-05 02:01:31 +00:00
Bill Paul
1fbdac93d9 Small touch-ups -- no functional changes.
Fix some comments to reflect reality (in some cases I made changes
to code but not to the comments).

Change some instances of 'inline' to '__inline' to pacify
gcc -ansi -pedantic.

Use rcsid strings more consistently.

Make 'oldaddr' static in yp_access().

Use strcpy()/strcat() in yp_open_db_cache() instead of snprintf().
(Seems to be a little faster this way.)
1996-05-31 16:01:51 +00:00
Bill Paul
b2264be812 Performance enhancements (I hope) and new stuff:
yp_dblookup.c:

- Implement database handle caching. What this means is that instead
  of opening and closing map databases for each request, we open a
  database and save the handle (and, if requested, the key index)
  in an array. This saves a bit of overhead on things like repeated
  YPPROC_NEXT calls, such as you'd get from getpwent(). Normally,
  each YPPROC_NEXT would require open()ing the database, seeking
  to the location supplied by the caller (which is time consuming with
  hash databases as the R_CURSOR flag doesn't work), reading the
  data, close()ing the database and then shipping the data off to
  the caller. The system call overhead is prohibitive, especially
  with very large maps. By caching the handle to an open database,
  we elimitate at least the open()/close() system calls, as well
  as the associated DB setup and tear-down operations, for a large
  percentage of the time. This improves performance substantially at
  the cost of consuming a little more memory than before.

  Note that all the caching support is surrounded by #ifdef DB_CACHE
  so that this same source module can still be used by other programs
  that don't need it.

- Make yp_open_db() call yp_validdomain(). Doing it here saves cycles
  when caching is enabled since a hit on the map cache list by
  definition means that the domain being referenced is valid.

- Also make yp_open_db() check for exhaustion of file descriptors,
  just in case.

yp_server.c:

- Reorganize things a little to take advantage of the database
  handle caching. Add a call to yp_flush_all() in ypproc_clear_2_svc().

- Remove calls to yp_validdomain() from some of the service procedures.
  yp_validdomain() is called inside yp_open_db() now, so procedures that
  call into the database package don't need to use yp_validdomain()
  themselves.

- Fix a bogosity in ypproc_maplist_2_svc(): don't summarily initiallize
  the result.maps pointer to NULL. This causes yp_maplist_free()
  to fail and leaks memory.

- Make ypproc_master_2_svc() copy the string it gets from the database
  package into a private static buffer before trying to NUL terminate it.
  This is necessary with the DB handle caching: stuffing a NUL into the
  data returned by DB package will goof it up internally.

yp_main.c:

- Stuff for DB handle caching: call yp_init_dbs() to clear the
  handle array and add call to yp_flush_all() to the SIGHUP
  signal handler.

Makefile.yp:

- Reorganize to deal with database caching. yp_mkdb(8) can now be used
  to send a YPPROC_CLEAR signal to ypserv(8). Call it after each map
  is created to refresh ypserv's cache.

- Add support for mail.alias map.
  Contributed by Mike Murphy (mrm@sceard.com).

- Make default location for the netgroups source file be /var/yp/netgroup
  instead of /etc/netgroup.

mkaliases:

- New file: script to generate mail.alias map.
  Contributed by Mike Murphy (mrm@sceard.com).

Makefile:

- Install Makefile.yp as /var/yp/Makefile.dist and link it to
  /var/yp/Makefile only if /var/yp/Makefile doesn't already exist.
  Suggested by Peter Wemm.

- Install new mkaliases script in /usr/libexec along with mknetid.

- Use somewhat saner approach to generating rpcgen-dependent files
  as suggested by Garrett Wollman.
1996-04-28 04:38:52 +00:00
Bill Paul
5fe4681564 Fix for memory leak: specify NULL as openinfo parameter when calling
dbopen() to open an NIS map.

Testing with very large maps (e.g. a sample password database with 31,000+
entries) has shown that ypserv will leak memory (ps shows RSS and VSZ
growing to 4000 pages or more) when performing repeated yp_next()s or
a yp_all(). The problem with yp_all() is not immediately obvious since
the ypproc_all service is handled in a child process which exits once
the transfer is finished, but with repeated yp_next()s (like what you
get when you use getpwent() to scroll through the password database),
the parent ypserv grows to enormous size and never shrinks again.

It seems this is related to the HASHINFO parameters I used in yp_dblookup.c,
which I actually stole from pwd_mkdb. Calling dbopen() with the default
parameters (specifying openinfo as NULL) fixes the problem.

I still need to see how this impacts the other NIS tools. I'm also
considering changing from hash to btree databases: the hash database
method doesn't support R_CURSOR, which means yp_next_record() has to
do a lot of ugly work in order to reach an arbitrary location in the
database.
1996-04-11 20:54:15 +00:00
Mike Pritchard
906c1e27fc Correct some man page cross references and file location references. 1996-04-07 00:06:21 +00:00
Bill Paul
11504a40aa Initialize a few more 'result' members in a few places (both in the v2
and v2 service procedures). Also fixed the formatting in a few places
to keep everything under 80 columns.
1996-03-01 03:49:47 +00:00
Bill Paul
45da6d16c1 In ypproc_master_2_svc(), don't leave result.peer uninitialized when
returning an error.
1996-02-29 23:10:38 +00:00
Adam David
6dc00a94a6 sense of 'mask' was reversed in default case of no securenets file. 1996-02-29 18:29:24 +00:00
Guido van Rooij
9abcd27118 Typo (vi -> v1). 1996-02-26 20:09:22 +00:00
Bill Paul
9573c1f163 Add support for NIS v1 client procedures. The following procedures
are currently implemented:

YPOLDPROC_NULL
YPOLDPROC_DOMAIN
YPOLDPROC_DOMAIN_NONACK
YPOLDPROC_FIRST
YPOLDPROC_NEXT
YPOLDPROC_MATCH
YPOLDPROC_POLL

These are all implemented as wrappers around their v2 counterparts.

The YPOLDPROC_PUSH, PULL and GET procedures are not implemented since
a) I couldn't figure out exactly what to have them do, and b) I
suspect they're used for doing map transfers between master and
slave servers, which we already do using the v2 protocol anyway.
This means we can server NIS v1 clients but can't be a master or
slave with NIS v1-only servers. I think I'll get over it. :)

The -k (sunos_4_kludge) flag and associated code has been removed
since it is no longer needed.

Also tweaked yp_access() to handle both sets of procedures and
updated the man page.
1996-02-26 02:34:27 +00:00
Bill Paul
66c201eaba Duh: remember to #include <stdlib.h> to pick up declarations for
malloc() and free().
1996-02-25 19:25:23 +00:00
Bill Paul
f7f470a811 Add real securenets support. By default, ypserv now uses /var/yp/securenets
in the same was as the SunOS ypserv (same format, described in ypserv man
page). If the user wants tcpwrapper style access control, they can
recompile ypserv to use that instead. This way we get securenets without
having to ship libwrap.a and tcpd.h with core FreeBSD distribution.

If /var/yp/securenets doesn't exist, ypserv allows all connections.
1996-02-24 22:01:48 +00:00
Mike Pritchard
78b0b234eb Correct a bunch of man page cross references and generally
try and silence "manck".

ncurses, rpc, and some of the gnu stuff are still a big mess, however.
1996-02-11 22:38:05 +00:00
Bill Paul
920491cf83 Makefile.yp:
- Improve support for multiple domains. (In preparation for new rpc.yppasswdd.)

yp_dblookup.c:
- Improve error reporting: be more selective as to what error code
  we return when a (dbp->get) fails.
1996-02-04 05:39:35 +00:00
Bill Paul
c0b36ac20f Found an instance of yp_error() in yp_maplist_create() that had two %s
tokens but only one argument; fixed by putting in missing argument.
1996-01-31 15:21:56 +00:00
Mike Pritchard
4a8d02835c Fix a bunch of spelling errors in a bunch of man pages. 1996-01-30 13:52:50 +00:00
Bill Paul
ce5b7be823 Change private version of verr() to __verr() and make it static to
avoid potential clash with library function of the same name.
1996-01-26 18:20:56 +00:00
Bill Paul
1fff226dba Update pointer to yppush.
(And now, on to rpc.yppasswdd...)
1996-01-12 07:07:18 +00:00
Bill Paul
009790d136 More changes brought about by testing of yppush (which is almost finished):
In yp_server.c:

- Modify ypproc_xfr_2_svc() so that it sends both a return status and
  a yppush callback (if necessary: normally ypxfr is supposed to send the
  callback once it's done transfering a map, but if we can't get ypxfr
  off the ground for some reason, we have to send it here instead) and
  do it in the right order: have to send the reply to the ypproc_xfr
  request first, then send callback. This requires us to cheat a bit:
  you're supposed to just return() and let the RPC dispatcher send
  the reply for you, but we wouldn't be able to send the callback message
  if we did that, so we have to call svc_sendreply() ourselves, then
  send the callback, and then return NULL so that the RPC dispatcher
  won't call svc_sendreply() itself.

- Also modify ypproc_xfr_2_svc() so that it doesn't invoke ypxfr with
  the -f flag: this overrides the order number checks, which prevents
  us from ever refusing maps that aren't newer than then ones we already
  have.

In yp_access.c:

- Fix a typo in the TCP_WRAPPER support code (which is #ifdef'ed out
  by default): a close paren somehow vanished into the ether.
1996-01-10 16:07:39 +00:00
Bill Paul
77732bc551 A few small tweaks related to ypxfr:
- Add a ypxfr_callback() function that we can use to signal failure to
  yppush(8) in the event that we can't fork()/exec() ypxfr(8). yppush
  only checks the return status from YPPROC_XFR enough to determine
  that the RPC succeded: it relies on its callback service to figure
  out whether or not the transfer actually worked.

- Give yp_dblookup.c its own debug variable (ypdb_debug) so that DB
  access debugging messages can be turned on or off independent of the
  program's global debug messages.

- Have the Makefile rpcgen the ypushresp_xfr_1() client stub for us and
  nuke the unneeded rule for yp_xdr.c that I left in by mistake (the XDR
  filters live in libc now).
1995-12-23 21:35:35 +00:00
Bruce Evans
e7e4345bbf Fixed building in obj directory. 1995-12-16 23:01:04 +00:00
Bill Paul
778c7b1c1c Import the new, non-GPL ypserv, written by yours truly. Functionally
equivalent to the old ypserv, except that it doesn't support the
-p [port] option to force the server to use a particular port.

The server stubs and yp.h header file are auto-generated from the yp.x
protocol definition file. The auto-generated XDR routines in libc/yp
are also used. The database access code has been broken out into a
seperate module so that other NIS utilities (ypxfr in particular)
can use it.

Note that the old mknetid script is being temporarily moved here; it
will be replaced by an mknetid program which will eventually have
a home under /usr/src/libexec. (The existing script is actually
somewhat broken -- it doesn't handle hosts -- but this isn't a big
deal at this point since the netid.byname map is really only useful
fopr Secure RPC, which we don't have yet.)
1995-12-16 20:54:17 +00:00