2 * support/export/nfsctl.c
4 * Communicate export information to knfsd.
6 * Copyright (C) 1995 Olaf Kirch <okir@monad.swb.de>
22 static int expsetup(struct nfsctl_export *exparg, nfs_export *exp, int unexport);
23 static int cltsetup(struct nfsctl_client *cltarg, nfs_client *clp);
26 export_export(nfs_export *exp)
28 nfs_client * clp = exp->m_client;
29 struct nfsctl_export exparg;
30 struct nfsctl_client cltarg;
32 if (!clp->m_exported && (clp->m_type != MCL_GSS)) {
33 if (!cltsetup(&cltarg, clp))
35 if (nfsaddclient(&cltarg) < 0)
39 if (!expsetup(&exparg, exp, 0))
41 if (nfsexport(&exparg) < 0)
48 export_unexport(nfs_export *exp)
50 struct nfsctl_export exparg;
52 if (!expsetup(&exparg, exp, 1) || nfsunexport(&exparg) < 0)
67 cltsetup(struct nfsctl_client *cltarg, nfs_client *clp)
71 if (clp->m_type != MCL_FQDN) {
72 xlog(L_ERROR, "internal: can't export non-FQDN host");
75 memset(cltarg, 0, sizeof(*cltarg));
76 strncpy(cltarg->cl_ident, clp->m_hostname,
77 sizeof (cltarg->cl_ident) - 1);
78 str_tolower(cltarg->cl_ident);
81 for (i = 0; i < clp->m_naddr && i < NFSCLNT_ADDRMAX; i++) {
82 const struct sockaddr_in *sin = get_addrlist_in(clp, i);
83 if (sin->sin_family == AF_INET)
84 cltarg->cl_addrlist[j++] = sin->sin_addr;
87 xlog(L_ERROR, "internal: no supported addresses in nfs_client");
96 expsetup(struct nfsctl_export *exparg, nfs_export *exp, int unexport)
98 nfs_client *clp = exp->m_client;
101 if (stat(exp->m_export.e_path, &stb) < 0)
104 memset(exparg, 0, sizeof(*exparg));
105 strncpy(exparg->ex_path, exp->m_export.e_path,
106 sizeof (exparg->ex_path) - 1);
107 strncpy(exparg->ex_client, clp->m_hostname,
108 sizeof (exparg->ex_client) - 1);
109 str_tolower(exparg->ex_client);
110 exparg->ex_flags = exp->m_export.e_flags;
111 exparg->ex_dev = (!unexport && (exp->m_export.e_flags & NFSEXP_FSID)) ?
112 (__nfsd_dev_t)exp->m_export.e_fsid : stb.st_dev;
113 exparg->ex_ino = stb.st_ino;
114 exparg->ex_anon_uid = exp->m_export.e_anonuid;
115 exparg->ex_anon_gid = exp->m_export.e_anongid;