summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1995-03-20 07:29:55 +0000
committerwpaul <wpaul@FreeBSD.org>1995-03-20 07:29:55 +0000
commit48d35b4b93ee64793453e193c884843832ebfd94 (patch)
treec7ae5b6ff764ee7e69dc9af9fa576792d3fefdf6 /lib
parentcb5993b7342c271424b26519ee5aee983b1c9aa7 (diff)
downloadFreeBSD-src-48d35b4b93ee64793453e193c884843832ebfd94.zip
FreeBSD-src-48d35b4b93ee64793453e193c884843832ebfd94.tar.gz
At last! Modified __ivaliduser() to do the same kind of user/host validation
that everyone else does: you can now use +host/-host, +user,-user and +@netgroup/-@netgroup in /etc/hosts.equiv, /.rhosts, /etc/hosts.lpd and ~/.rhosts. Previously, __ivaliduser would only do host/user matches, which was lame. This affects all the r-commands, lpd, and any other program/service that uses ruserok(). An example of the usefullness of this feature would be a hosts.equiv file that looks like this: +@equiv-hosts Since the netgroup database can now be accessed via NIS, this lets you set up client machines once and then never have to worry about them again: all hosts.equiv changes can now be done through NIS. Once I finish with getpwent.c, we'll be able to do similar wacky things with login authentication too. (Our password field substitution will finally be on par with everyone else's, and I'll finally be able to fully integrate my FreeBSD machine into my network without having to worry about the grad students sneaking into it when I'm not looking. :) Danger Will Robinson! I tested this thing every which way I could, but Murphy's Law applies! If anybody spots a potential security problem with the way my matching algorithm works, tell me immediately! I don't want crackers snickering and calling me names behind my back. :)
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/rcmd.c72
1 files changed, 69 insertions, 3 deletions
diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c
index 40f1c19..01ceac9 100644
--- a/lib/libc/net/rcmd.c
+++ b/lib/libc/net/rcmd.c
@@ -356,6 +356,14 @@ __ivaliduser(hostf, raddr, luser, ruser)
register char *user, *p;
int ch;
char buf[MAXHOSTNAMELEN + 128]; /* host + login */
+ struct hostent *hp;
+ /* Presumed guilty until proven innocent. */
+ int userok = 0, hostok = 0;
+
+ /* We need to get the damn hostname back for netgroup matching. */
+ if ((hp = gethostbyaddr((char *)&raddr, sizeof(u_long),
+ AF_INET)) == NULL)
+ return (-1);
while (fgets(buf, sizeof(buf), hostf)) {
p = buf;
@@ -379,10 +387,68 @@ __ivaliduser(hostf, raddr, luser, ruser)
} else
user = p;
*p = '\0';
- if (__icheckhost(raddr, buf) &&
- strcmp(ruser, *user ? user : luser) == 0) {
- return (0);
+ /*
+ * Do +/- and +@/-@ checking. This looks really nasty,
+ * but it matches SunOS's behavior so far as I can tell.
+ */
+ switch(buf[0]) {
+ case '+':
+ if (!buf[1]) { /* '+' matches all hosts */
+ hostok = 1;
+ break;
+ }
+ if (buf[1] == '@') /* match a host by netgroup */
+ hostok = innetgr((char *)&buf[2], hp->h_name,
+ NULL, NULL);
+ else /* match a host by addr */
+ hostok = __icheckhost(raddr,(char *)&buf[1]);
+ break;
+ case '-': /* reject '-' hosts and all their users */
+ if (buf[1] == '@') {
+ if (innetgr((char *)&buf[2],
+ hp->h_name, NULL, NULL))
+ return(-1);
+ } else {
+ if (__icheckhost(raddr,(char *)&buf[1]))
+ return(-1);
+ }
+ break;
+ default: /* if no '+' or '-', do a simple match */
+ hostok = __icheckhost(raddr, buf);
+ break;
+ }
+ switch(*user) {
+ case '+':
+ if (!*(user+1)) { /* '+' matches all users */
+ userok = 1;
+ break;
+ }
+ if (*(user+1) == '@') /* match a user by netgroup */
+ userok = innetgr(user+2, NULL, ruser, NULL);
+ else /* match a user by direct specification */
+ userok = !(strcmp(ruser, user+1));
+ break;
+ case '-': /* if we matched a hostname, */
+ if (hostok) { /* check for user field rejections */
+ if (!*(user+1))
+ return(-1);
+ if (*(user+1) == '@') {
+ if (innetgr(user+2, NULL,
+ ruser, NULL))
+ return(-1);
+ } else {
+ if (!strcmp(ruser, user+1))
+ return(-1);
+ }
+ }
+ break;
+ default: /* no rejections: try to match the user */
+ if (hostok)
+ userok = !(strcmp(ruser,*user ? user : luser));
+ break;
}
+ if (hostok && userok)
+ return(0);
}
return (-1);
}
OpenPOWER on IntegriCloud