Adapt to new RPC interface. Use getaddrinfo(), not gethostbyname().

This commit is contained in:
fvdl 2000-06-20 00:45:24 +00:00
parent 6cf4b35f71
commit d65482091f
1 changed files with 66 additions and 44 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: umount.c,v 1.27 2000/06/06 07:09:15 chs Exp $ */
/* $NetBSD: umount.c,v 1.28 2000/06/20 00:45:24 fvdl Exp $ */
/*-
* Copyright (c) 1980, 1989, 1993
@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1989, 1993\n\
#if 0
static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95";
#else
__RCSID("$NetBSD: umount.c,v 1.27 2000/06/06 07:09:15 chs Exp $");
__RCSID("$NetBSD: umount.c,v 1.28 2000/06/20 00:45:24 fvdl Exp $");
#endif
#endif /* not lint */
@ -70,12 +70,14 @@ typedef enum { MNTANY, MNTON, MNTFROM } mntwhat;
int fake, fflag, verbose, raw;
char *nfshost;
struct addrinfo *nfshost_ai = NULL;
int checkvfsname __P((const char *, char **));
char *getmntname __P((char *, mntwhat, char **));
char **makevfslist __P((char *));
int main __P((int, char *[]));
int namematch __P((struct hostent *));
int namematch __P((struct addrinfo *));
int sacmp __P((struct sockaddr *, struct sockaddr *));
int selected __P((int));
int umountfs __P((char *, char **));
void usage __P((void));
@ -89,6 +91,7 @@ main(argc, argv)
int all, ch, errs, mnts;
char **typelist = NULL;
struct statfs *mntbuf;
struct addrinfo hints;
/* Start disks transferring immediately. */
sync();
@ -134,6 +137,11 @@ main(argc, argv)
/* -h implies "-t nfs" if no -t flag. */
if ((nfshost != NULL) && (typelist == NULL))
typelist = makevfslist("nfs");
if (nfshost != NULL) {
memset(&hints, 0, sizeof hints);
getaddrinfo(nfshost, NULL, &hints, &nfshost_ai);
}
errs = 0;
if (all) {
@ -161,16 +169,13 @@ umountfs(name, typelist)
char **typelist;
{
enum clnt_stat clnt_stat;
struct hostent *hp;
struct sockaddr_in saddr;
struct stat sb;
struct timeval pertry, try;
struct timeval try;
CLIENT *clp;
int so;
char *type, *delimp, *hostp, *mntpt, rname[MAXPATHLEN];
mntwhat what;
struct addrinfo *ai, hints;
hp = NULL;
delimp = NULL;
if (raw) {
@ -218,23 +223,24 @@ umountfs(name, typelist)
if (checkvfsname(type, typelist))
return (1);
hp = NULL;
memset(&hints, 0, sizeof hints);
ai = NULL;
if (!strncmp(type, MOUNT_NFS, MFSNAMELEN)) {
if ((delimp = strchr(name, '@')) != NULL) {
hostp = delimp + 1;
*delimp = '\0';
hp = gethostbyname(hostp);
getaddrinfo(hostp, NULL, &hints, &ai);
*delimp = '@';
} else if ((delimp = strchr(name, ':')) != NULL) {
} else if ((delimp = strrchr(name, ':')) != NULL) {
*delimp = '\0';
hostp = name;
hp = gethostbyname(hostp);
getaddrinfo(hostp, NULL, &hints, &ai);
name = delimp + 1;
*delimp = ':';
}
}
if (!namematch(hp))
if (!namematch(ai))
return (1);
}
@ -249,21 +255,14 @@ umountfs(name, typelist)
}
if (!raw && !strncmp(type, MOUNT_NFS, MFSNAMELEN) &&
(hp != NULL) && !(fflag & MNT_FORCE)) {
(ai != NULL) && !(fflag & MNT_FORCE)) {
*delimp = '\0';
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = 0;
memmove(&saddr.sin_addr, hp->h_addr, hp->h_length);
pertry.tv_sec = 3;
pertry.tv_usec = 0;
so = RPC_ANYSOCK;
if ((clp = clntudp_create(&saddr,
RPCPROG_MNT, RPCMNT_VER1, pertry, &so)) == NULL) {
clp = clnt_create(hostp, RPCPROG_MNT, RPCMNT_VER1, "udp");
if (clp == NULL) {
clnt_pcreateerror("Cannot MNT PRC");
return (1);
}
clp->cl_auth = authunix_create_default();
clp->cl_auth = authsys_create_default();
try.tv_sec = 20;
try.tv_usec = 0;
clnt_stat = clnt_call(clp,
@ -309,32 +308,55 @@ getmntname(name, what, type)
}
int
namematch(hp)
struct hostent *hp;
sacmp(struct sockaddr *sa1, struct sockaddr *sa2)
{
char *cp, **np;
void *p1, *p2;
int len;
if ((hp == NULL) || (nfshost == NULL))
return (1);
if (sa1->sa_family != sa2->sa_family)
return 1;
if (strcasecmp(nfshost, hp->h_name) == 0)
return (1);
if ((cp = strchr(hp->h_name, '.')) != NULL) {
*cp = '\0';
if (strcasecmp(nfshost, hp->h_name) == 0)
return (1);
switch (sa1->sa_family) {
case AF_INET:
p1 = &((struct sockaddr_in *)sa1)->sin_addr;
p2 = &((struct sockaddr_in *)sa2)->sin_addr;
len = 4;
break;
case AF_INET6:
p1 = &((struct sockaddr_in6 *)sa1)->sin6_addr;
p2 = &((struct sockaddr_in6 *)sa2)->sin6_addr;
len = 16;
if (((struct sockaddr_in6 *)sa1)->sin6_scope_id !=
((struct sockaddr_in6 *)sa2)->sin6_scope_id)
return 1;
break;
default:
return 1;
}
for (np = hp->h_aliases; *np; np++) {
if (strcasecmp(nfshost, *np) == 0)
return (1);
if ((cp = strchr(*np, '.')) != NULL) {
*cp = '\0';
if (strcasecmp(nfshost, *np) == 0)
return (1);
return memcmp(p1, p2, len);
}
int
namematch(ai)
struct addrinfo *ai;
{
struct addrinfo *aip;
if (nfshost == NULL || nfshost_ai == NULL)
return (1);
while (ai != NULL) {
aip = nfshost_ai;
while (aip != NULL) {
if (sacmp(ai->ai_addr, aip->ai_addr) == 0)
return 1;
aip = aip->ai_next;
}
ai = ai->ai_next;
}
return (0);
return 0;
}
/*