fs/nfs: Add the simplest RPCAUTH_UNIX support

Since most NFS server disable RPCAUTH_NULL to improve the security
This commit is contained in:
Xiang Xiao 2020-03-02 20:07:09 +08:00 committed by Gregory Nutt
parent 7794214a7d
commit de480b01b6
3 changed files with 15 additions and 6 deletions

View File

@ -302,7 +302,7 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
/* Set the group ID to one */
*ptr++ = nfs_true; /* True: Gid value follows */
*ptr++ = HTONL(1); /* GID = 1 (nogroup) */
*ptr++ = 0; /* GID = 0 (nogroup) */
reqlen += 2*sizeof(uint32_t);
/* Set the size to zero */
@ -2287,7 +2287,7 @@ static int nfs_mkdir(FAR struct inode *mountpt, FAR const char *relpath, mode_t
/* Set the group ID to one */
*ptr++ = nfs_true; /* True: Gid value follows */
*ptr++ = HTONL(1); /* GID = 1 (nogroup) */
*ptr++ = 0; /* GID = 0 (nogroup) */
reqlen += 2*sizeof(uint32_t);
/* No size */

View File

@ -218,7 +218,7 @@ struct rpc_auth_info
uint32_t authlen; /* auth length */
};
struct auth_unix
struct rpc_auth_unix
{
uint32_t stamp;
uint32_t hostname; /* null */
@ -236,6 +236,7 @@ struct rpc_call_header
uint32_t rp_vers; /* version */
uint32_t rp_proc; /* procedure */
struct rpc_auth_info rpc_auth;
struct rpc_auth_unix rpc_unix;
struct rpc_auth_info rpc_verf;
};

View File

@ -129,6 +129,7 @@ static uint32_t rpc_reply;
static uint32_t rpc_call;
static uint32_t rpc_vers;
static uint32_t rpc_auth_null;
static uint32_t rpc_auth_unix;
/* Global statics for all client instances. Cleared by NuttX on boot-up. */
@ -444,10 +445,16 @@ static void rpcclnt_fmtheader(FAR struct rpc_call_header *ch,
ch->rp_vers = txdr_unsigned(vers);
ch->rp_proc = txdr_unsigned(procid);
/* rpc_auth part (auth_null) */
/* rpc_auth part (auth_unix) */
ch->rpc_auth.authtype = rpc_auth_null;
ch->rpc_auth.authlen = 0;
ch->rpc_auth.authtype = rpc_auth_unix;
ch->rpc_auth.authlen = txdr_unsigned(sizeof(ch->rpc_unix));
ch->rpc_unix.stamp = 0;
ch->rpc_unix.hostname = 0;
ch->rpc_unix.uid = 0;
ch->rpc_unix.gid = 0;
ch->rpc_unix.gidlist = 0;
/* rpc_verf part (auth_null) */
@ -475,6 +482,7 @@ void rpcclnt_init(void)
rpc_vers = txdr_unsigned(RPC_VER2);
rpc_call = txdr_unsigned(RPC_CALL);
rpc_auth_null = txdr_unsigned(RPCAUTH_NULL);
rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
finfo("RPC initialized\n");
}