summaryrefslogtreecommitdiffstats
path: root/support/export/rmtab.c
diff options
context:
space:
mode:
authorhjl <hjl>1999-10-18 23:21:12 +0000
committerhjl <hjl>1999-10-18 23:21:12 +0000
commit8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9 (patch)
tree0904ef8554ed680fe3244fa618685e1fb7ea148b /support/export/rmtab.c
downloadnfs-utils-8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9.tar.gz
nfs-utils-8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9.tar.xz
nfs-utils-8b7ad01b14df1e7529b9ba8a1ea17df0d6004ef9.zip
Initial revision
Diffstat (limited to 'support/export/rmtab.c')
-rw-r--r--support/export/rmtab.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/support/export/rmtab.c b/support/export/rmtab.c
new file mode 100644
index 0000000..44a0edc
--- /dev/null
+++ b/support/export/rmtab.c
@@ -0,0 +1,79 @@
+/*
+ * support/export/rmntab.c
+ *
+ * Interface to the rmnt file.
+ *
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "xmalloc.h"
+#include "misc.h"
+#include "nfslib.h"
+#include "exportfs.h"
+#include "xio.h"
+#include "xlog.h"
+
+int
+rmtab_read(void)
+{
+ struct rmtabent *rep;
+ nfs_export *exp;
+
+ setrmtabent("r");
+ while ((rep = getrmtabent(1)) != NULL) {
+ exp = export_lookup(rep->r_client, rep->r_path);
+ if (!exp) {
+ struct exportent *xp;
+ struct hostent *hp;
+ int htype;
+
+ htype = client_gettype(rep->r_client);
+ if (htype == MCL_FQDN
+ && (hp = gethostbyname (rep->r_client), hp)
+ && (hp = hostent_dup (hp),
+ xp = export_allowed (hp, rep->r_path))) {
+ strncpy (xp->e_hostname, rep->r_client,
+ sizeof (xp->e_hostname) - 1);
+ xp->e_hostname[sizeof (xp->e_hostname) -1] = '\0';
+ exp = export_create(xp);
+ free (hp);
+ }
+
+ if (!exp)
+ continue;
+ exp->m_mayexport = 1;
+ }
+ }
+ if (errno == EINVAL) {
+ /* Something goes wrong. We need to fix the rmtab
+ file. */
+ int lockid;
+ FILE *fp;
+ if ((lockid = xflock(_PATH_RMTAB, "w")) < 0)
+ return -1;
+ rewindrmtabent();
+ if (!(fp = fsetrmtabent(_PATH_RMTABTMP, "w"))) {
+ endrmtabent ();
+ xfunlock(lockid);
+ return -1;
+ }
+ while ((rep = getrmtabent(0)) != NULL) {
+ fputrmtabent(fp, rep);
+ }
+ if (rename(_PATH_RMTABTMP, _PATH_RMTAB) < 0) {
+ xlog(L_ERROR, "couldn't rename %s to %s",
+ _PATH_RMTABTMP, _PATH_RMTAB);
+ }
+ endrmtabent();
+ fendrmtabent(fp);
+ xfunlock(lockid);
+ }
+ else {
+ endrmtabent();
+ }
+ return 0;
+}