I’m trying to use RPC calls to perform a NFS mount on a Rocky 8 distro, running in VirtualBox on a Windows host.
I have the following set in my /etc/exports:
/nfstest *(rw,sync,no_root_squash,no_subtree_check)
And I verified I can mount when using mount command:
sudo mount -t nfs 10.0.2.15:/nfstest /mnt/nfs
However, I need to do this programmatically using direct RPC calls.
Here is my code sample:
struct sockaddr_in server_addr;
struct timeval timeout;
int mountprog;
int mountvers;
int nfsprog;
int nfsvers;
int mountport = 0;
timeout.tv_sec = 30; /* set default timeout to 30.00 seconds */
timeout.tv_usec = 0;
/* Convert NAS IP to binary */
int rc = inet_pton(AF_INET, "10.0.2.15", &server_addr.sin_addr);
server_addr.sin_family = AF_INET;
server_addr.sin_port = 0;
mountprog = MOUNTPROG;
mountvers = MOUNTVERS3;
nfsprog = NFS_PROGRAM;
nfsvers = NFS_V3;
/* Get the NFS remote file handler */
CLIENT *clnt; /* pointer to client handle */
int sock = RPC_ANYSOCK;
clnt = clntudp_create(&server_addr, mountprog, mountvers,
timeout, &sock);
if (clnt != NULL)
{
clnt->cl_auth = authunix_create_default();
printf("Successfully created client with clntudp_create()n");
struct fhstatus mount_res;
/* directory */
char *rootpath = "/nfstest";
dirpath path = rootpath;
enum clnt_stat retval;
retval = clnt_call(clnt, MOUNTPROC_MNT, (xdrproc_t)xdr_dirpath, &path, (xdrproc_t)xdr_fhstatus, &mount_res, timeout);
if (retval != RPC_SUCCESS)
{
clnt_perror(clnt, "Mount request failed");
return -1;
}
if (mount_res.fhs_status == 0)
{
printf("Mount successful, file handled obtained: %s n", mount_res.fhstatus_u.fhs_fhandle);
}
else
{
printf("Mount failed, error code: %dn", mount_res.fhs_status);
}
}
clntudp_create() returns a valid client.
clnt_call() returns RPC_SUCCESS.
However, mount_res.fhs_status is set to 13 (EACESS).
Things I’ve tried:
-
Verified firewall is not running
-
Verified exportfs -v returns valid data:
/nfstest (sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
-
Ran sudo setenforce 0 to set SELinux to permissive mode
Anything I might be missing here?
The one thing that stands out odd to me is the “hide” flag set when I run exportfs -v. I do not see this “hide” flag in my /etc/exports, so not sure where it’s getting that from, or if that’s the reason for my issues.
I did try adding “nohide” to my /etc/exports, but I still get the errno 13.
Thank you.
EDIT: This is the result of rpcinfo | grep nfs
100003 3 tcp 0.0.0.0.8.1 nfs superuser
100003 4 tcp 0.0.0.0.8.1 nfs superuser
100227 3 tcp 0.0.0.0.8.1 nfs_acl superuser
100003 3 udp 0.0.0.0.8.1 nfs superuser
100227 3 udp 0.0.0.0.8.1 nfs_acl superuser
100003 3 tcp6 ::.8.1 nfs superuser
100003 4 tcp6 ::.8.1 nfs superuser
100227 3 tcp6 ::.8.1 nfs_acl superuser
100003 3 udp6 ::.8.1 nfs superuser
100227 3 udp6 ::.8.1 nfs_acl superuser
EDIT 2: I was able to get it to work if I ran my C app as “sudo”… so now just have to figure out how to allow nfs mount without sudo.
1