From 51fec467c4b771db8ffc6a10a07dbf781a905482 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Tue, 30 Jan 2001 00:38:45 +0000 Subject: 2000-12-26 Neal H Walfield * cache.c: Change cache/hash table size to 509, a prime. Use memcpy/memcmp not bcopy/bcmp. Verify return value from malloc and check the result of rpc transaction _and_ do not act if failed. * main.c: Correct the wording of the help messages. Do not bother initializing global variable to 0. Use memcpy/memcmp not bcopy/bcmp. Verify return value from malloc and check the result of rpc transaction _and_ do not act if failed. * mount.c: Check return values of initialize_rpc. Use memcpy/memcmp not bcopy/bcmp. Verify return value from malloc and strdup. Correct comments. (mount_root): Check result of connect. Handle errors consistently. Reverse loops that are if (! c) {} else when appropriate. * mount.h: Protect header with #ifdef. * name-cache.c: Correct dangerous NPARTIALS macro. Use memcpy/memcmp not bcopy/bcmp. (find_cache): Use PARTIAL_THRESH, not the constant. * nfs-spec.h: Protect header with #ifdef. * nfs.c: Use memcpy/memcmp not bcopy/bcmp. * nfs.h: Likewise. * ops.c (netfs_attempt_mkdir): Check return values of initialize_rpc. Use memcpy/memcmp not bcopy/bcmp. Verify return value from malloc and check the result of rpc transaction _and_ do not act if failed. (netfs_attempt_link): Unlock the directory before the rpc transaction. Check the result of rpc transaction _and_ do not act if failed. * pager.c: Remove, we do not use it. * rpc.c: Use memcpy/memcmp not bcopy/bcmp. Verify return value from malloc and check the result of rpc transaction _and_ do not act if failed. (initialize_rpc): Use AUTH_NONE, not the depreciated AUTH_NULL. Return sane values on failure. (generate_xid): Make inline. (link_rpc): New function. Complements unlink_rpc. (conduct_rpc): Use link_rpc. (rpc_receive_thread): Reroll to a single loop. --- nfs/mount.c | 103 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 30 deletions(-) (limited to 'nfs/mount.c') diff --git a/nfs/mount.c b/nfs/mount.c index 92af75f8..a3a6887e 100644 --- a/nfs/mount.c +++ b/nfs/mount.c @@ -87,13 +87,13 @@ mount_initialize_rpc (int procnum, void **buf) } /* Using the mount protocol, lookup NAME at host HOST. - Return a node for it or null for an error. */ + Return a node for it or null for an error. If an + error occurs, a message is automatically sent to stderr. */ struct node * mount_root (char *name, char *host) { struct sockaddr_in addr; struct hostent *h; - struct servent *s; int *p; void *rpcbuf; int port; @@ -103,6 +103,14 @@ mount_root (char *name, char *host) /* Lookup the portmapper port number */ if (pmap_service_name) { + struct servent *s; + + /* XXX This will always fail! pmap_service_name will always be "sunrpc" + What should pmap_service_name really be? By definition the second + argument is either "tcp" or "udp" Thus, is this backwards + (as service_name suggests)? If so, should it read: + s = getservbyname (pmap_service_name, "udp"); + or is there something I am missing here? */ s = getservbyname ("sunrpc", pmap_service_name); if (s) pmapport = s->s_port; @@ -121,17 +129,29 @@ mount_root (char *name, char *host) } addr.sin_family = h->h_addrtype; - bcopy (h->h_addr_list[0], &addr.sin_addr, h->h_length); + memcpy (&addr.sin_addr, h->h_addr_list[0], h->h_length); addr.sin_port = pmapport; - connect (main_udp_socket, - (struct sockaddr *)&addr, sizeof (struct sockaddr_in)); - - if (!mount_port_override) + if (mount_port_override) + addr.sin_port = htons (mount_port); + else { /* Formulate and send a PMAPPROC_GETPORT request to lookup the mount program on the server. */ + if (connect (main_udp_socket, (struct sockaddr *)&addr, + sizeof (struct sockaddr_in)) == -1) + { + perror ("server mount program"); + return 0; + } + p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf); + if (! p) + { + perror ("creating rpc packet"); + return 0; + } + *p++ = htonl (MOUNTPROG); *p++ = htonl (MOUNTVERS); *p++ = htonl (IPPROTO_UDP); @@ -146,38 +166,43 @@ mount_root (char *name, char *host) addr.sin_port = htons (mount_port); else { - free (rpcbuf); perror ("portmap of mount"); - return 0; + goto error_with_rpcbuf; } free (rpcbuf); } - else - addr.sin_port = htons (mount_port); - - /* Now talking to the mount program, fetch the file handle + /* Now, talking to the mount program, fetch a file handle for the root. */ - connect (main_udp_socket, - (struct sockaddr *) &addr, sizeof (struct sockaddr_in)); + if (connect (main_udp_socket, (struct sockaddr *) &addr, + sizeof (struct sockaddr_in)) == -1) + { + perror ("connect"); + goto error_with_rpcbuf; + } + p = mount_initialize_rpc (MOUNTPROC_MNT, &rpcbuf); + if (! p) + { + perror ("rpc"); + goto error_with_rpcbuf; + } + p = xdr_encode_string (p, name); errno = conduct_rpc (&rpcbuf, &p); if (errno) { - free (rpcbuf); perror (name); - return 0; + goto error_with_rpcbuf; } /* XXX Protocol spec says this should be a "unix error code"; we'll - pretend that an NFS error code is what's meant, the numbers match + pretend that an NFS error code is what's meant; the numbers match anyhow. */ errno = nfs_error_trans (htonl (*p++)); if (errno) { - free (rpcbuf); perror (name); - return 0; + goto error_with_rpcbuf; } /* Create the node for root */ @@ -185,13 +210,25 @@ mount_root (char *name, char *host) free (rpcbuf); mutex_unlock (&np->lock); - if (!nfs_port_override) + if (nfs_port_override) + port = nfs_port; + else { - /* Now send another PMAPPROC_GETPORT request to lookup the nfs server. */ + /* Send another PMAPPROC_GETPORT request to lookup the nfs server. */ addr.sin_port = pmapport; - connect (main_udp_socket, - (struct sockaddr *) &addr, sizeof (struct sockaddr_in)); + if (connect (main_udp_socket, (struct sockaddr *) &addr, + sizeof (struct sockaddr_in)) == -1) + { + perror ("connect"); + return 0; + } + p = pmap_initialize_rpc (PMAPPROC_GETPORT, &rpcbuf); + if (! p) + { + perror ("rpc"); + goto error_with_rpcbuf; + } *p++ = htonl (NFS_PROGRAM); *p++ = htonl (NFS_VERSION); *p++ = htonl (IPPROTO_UDP); @@ -203,18 +240,24 @@ mount_root (char *name, char *host) port = nfs_port; else { - free (rpcbuf); perror ("portmap of nfs server"); - return 0; + goto error_with_rpcbuf; } free (rpcbuf); } - else - port = nfs_port; addr.sin_port = htons (port); - connect (main_udp_socket, - (struct sockaddr *) &addr, sizeof (struct sockaddr_in)); + if (connect (main_udp_socket, (struct sockaddr *) &addr, + sizeof (struct sockaddr_in)) == -1) + { + perror ("connect"); + return 0; + } return np; + +error_with_rpcbuf: + free (rpcbuf); + + return 0; } -- cgit v1.2.3