Lines 108-113
static u_char *fh = NULL;
Link Here
|
108 |
static int fhsize = 0; |
108 |
static int fhsize = 0; |
109 |
static int secflavor = -1; |
109 |
static int secflavor = -1; |
110 |
static int got_principal = 0; |
110 |
static int got_principal = 0; |
|
|
111 |
static in_port_t mntproto_port = 0; |
111 |
|
112 |
|
112 |
static enum mountmode { |
113 |
static enum mountmode { |
113 |
ANY, |
114 |
ANY, |
Lines 360-365
main(int argc, char *argv[])
Link Here
|
360 |
softintr = true; |
361 |
softintr = true; |
361 |
} else if (strcmp(opt, "intr") == 0) { |
362 |
} else if (strcmp(opt, "intr") == 0) { |
362 |
softintr = true; |
363 |
softintr = true; |
|
|
364 |
} else if (strcmp(opt, "mountport") == 0) { |
365 |
num = strtol(val, &p, 10); |
366 |
if (*p || num <= 0) |
367 |
errx(1, "illegal port num -- " |
368 |
"%s", val); |
369 |
mntproto_port = num; |
370 |
pass_flag_to_nmount=0; |
363 |
} |
371 |
} |
364 |
if (pass_flag_to_nmount) { |
372 |
if (pass_flag_to_nmount) { |
365 |
build_iovec(&iov, &iovlen, opt, |
373 |
build_iovec(&iov, &iovlen, opt, |
Lines 900-910
tryagain:
Link Here
|
900 |
return (TRYRET_SUCCESS); |
908 |
return (TRYRET_SUCCESS); |
901 |
} |
909 |
} |
902 |
|
910 |
|
|
|
911 |
/* |
912 |
* malloc() and copy the address, so that it can be used for |
913 |
* nfsargs below. |
914 |
*/ |
915 |
addrlen = nfs_nb.len; |
916 |
addr = malloc(addrlen); |
917 |
if (addr == NULL) |
918 |
err(1, "malloc"); |
919 |
bcopy(nfs_nb.buf, addr, addrlen); |
920 |
|
903 |
/* Send the MOUNTPROC_MNT RPC to get the root filehandle. */ |
921 |
/* Send the MOUNTPROC_MNT RPC to get the root filehandle. */ |
904 |
try.tv_sec = 10; |
922 |
try.tv_sec = 10; |
905 |
try.tv_usec = 0; |
923 |
try.tv_usec = 0; |
906 |
clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt); |
924 |
if (mntproto_port != 0) { |
|
|
925 |
struct sockaddr *sad; |
926 |
struct sockaddr_in *sin; |
927 |
struct sockaddr_in6 *sin6; |
928 |
|
929 |
sad = (struct sockaddr *)nfs_nb.buf; |
930 |
switch (sad->sa_family) { |
931 |
case AF_INET: |
932 |
sin = (struct sockaddr_in *)nfs_nb.buf; |
933 |
sin->sin_port = htons(mntproto_port); |
934 |
break; |
935 |
case AF_INET6: |
936 |
sin6 = (struct sockaddr_in6 *)nfs_nb.buf; |
937 |
sin6->sin6_port = htons(mntproto_port); |
938 |
break; |
939 |
default: |
940 |
snprintf(errbuf, sizeof(errbuf), |
941 |
"Mnt port bad addr family %d\n", sad->sa_family); |
942 |
return (TRYRET_LOCALERR); |
943 |
} |
944 |
clp = clnt_tli_create(RPC_ANYFD, nconf_mnt, &nfs_nb, MOUNTPROG, |
945 |
mntvers, 0, 0); |
946 |
} else { |
947 |
/* Get the Mount protocol port# via rpcbind. */ |
948 |
clp = clnt_tp_create(hostp, MOUNTPROG, mntvers, nconf_mnt); |
949 |
} |
907 |
if (clp == NULL) { |
950 |
if (clp == NULL) { |
|
|
951 |
free(addr); |
908 |
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, |
952 |
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, |
909 |
hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create")); |
953 |
hostp, spec, clnt_spcreateerror("RPCMNT: clnt_create")); |
910 |
return (returncode(rpc_createerr.cf_stat, |
954 |
return (returncode(rpc_createerr.cf_stat, |
Lines 914-923
tryagain:
Link Here
|
914 |
nfhret.auth = secflavor; |
958 |
nfhret.auth = secflavor; |
915 |
nfhret.vers = mntvers; |
959 |
nfhret.vers = mntvers; |
916 |
clntstat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec, |
960 |
clntstat = clnt_call(clp, MOUNTPROC_MNT, (xdrproc_t)xdr_dir, spec, |
917 |
(xdrproc_t)xdr_fh, &nfhret, |
961 |
(xdrproc_t)xdr_fh, &nfhret, try); |
918 |
try); |
|
|
919 |
auth_destroy(clp->cl_auth); |
962 |
auth_destroy(clp->cl_auth); |
920 |
if (clntstat != RPC_SUCCESS) { |
963 |
if (clntstat != RPC_SUCCESS) { |
|
|
964 |
free(addr); |
921 |
if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) { |
965 |
if (clntstat == RPC_PROGVERSMISMATCH && trymntmode == ANY) { |
922 |
clnt_destroy(clp); |
966 |
clnt_destroy(clp); |
923 |
trymntmode = V2; |
967 |
trymntmode = V2; |
Lines 932-937
tryagain:
Link Here
|
932 |
clnt_destroy(clp); |
976 |
clnt_destroy(clp); |
933 |
|
977 |
|
934 |
if (nfhret.stat != 0) { |
978 |
if (nfhret.stat != 0) { |
|
|
979 |
free(addr); |
935 |
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, |
980 |
snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s", netid_mnt, |
936 |
hostp, spec, strerror(nfhret.stat)); |
981 |
hostp, spec, strerror(nfhret.stat)); |
937 |
return (TRYRET_REMOTEERR); |
982 |
return (TRYRET_REMOTEERR); |
Lines 941-953
tryagain:
Link Here
|
941 |
* Store the filehandle and server address in nfsargsp, making |
986 |
* Store the filehandle and server address in nfsargsp, making |
942 |
* sure to copy any locally allocated structures. |
987 |
* sure to copy any locally allocated structures. |
943 |
*/ |
988 |
*/ |
944 |
addrlen = nfs_nb.len; |
|
|
945 |
addr = malloc(addrlen); |
946 |
fhsize = nfhret.fhsize; |
989 |
fhsize = nfhret.fhsize; |
947 |
fh = malloc(fhsize); |
990 |
fh = malloc(fhsize); |
948 |
if (addr == NULL || fh == NULL) |
991 |
if (fh == NULL) |
949 |
err(1, "malloc"); |
992 |
err(1, "malloc"); |
950 |
bcopy(nfs_nb.buf, addr, addrlen); |
|
|
951 |
bcopy(nfhret.nfh, fh, fhsize); |
993 |
bcopy(nfhret.nfh, fh, fhsize); |
952 |
|
994 |
|
953 |
build_iovec(iov, iovlen, "addr", addr, addrlen); |
995 |
build_iovec(iov, iovlen, "addr", addr, addrlen); |