]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/exportfs/exportfs.c
mountd: Replace "struct hostent" with "struct addrinfo"
[nfs-utils.git] / utils / exportfs / exportfs.c
index 18dfe5ad8046c124b7e2cb8fb76da6800eeb8dba..0070b544d654400f9dbafa1127423e55609c5ea0 100644 (file)
@@ -12,6 +12,8 @@
 #include <config.h>
 #endif
 
+#include <sys/vfs.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
@@ -110,7 +112,6 @@ main(int argc, char **argv)
                        return 0;
                }
        }
-
        if (f_export && ! f_ignore)
                export_read(_PATH_EXPORTS);
        if (f_export) {
@@ -192,10 +193,10 @@ exports_update(int verbose)
 {
        nfs_export      *exp;
 
-       for (exp = exportlist[MCL_FQDN]; exp; exp=exp->m_next) {
+       for (exp = exportlist[MCL_FQDN].p_head; exp; exp=exp->m_next) {
                exports_update_one(exp, verbose);
        }
-       for (exp = exportlist[MCL_GSS]; exp; exp=exp->m_next) {
+       for (exp = exportlist[MCL_GSS].p_head; exp; exp=exp->m_next) {
                exports_update_one(exp, verbose);
        }
 }
@@ -211,7 +212,7 @@ export_all(int verbose)
        int             i;
 
        for (i = 0; i < MCL_MAXTYPES; i++) {
-               for (exp = exportlist[i]; exp; exp = exp->m_next) {
+               for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
                        if (verbose)
                                printf("exporting %s:%s\n",
                                       exp->m_client->m_hostname, 
@@ -231,7 +232,7 @@ exportfs(char *arg, char *options, int verbose)
 {
        struct exportent *eep;
        nfs_export      *exp;
-       struct hostent  *hp = NULL;
+       struct addrinfo *ai = NULL;
        char            *path;
        char            *hname = arg;
        int             htype;
@@ -244,32 +245,21 @@ exportfs(char *arg, char *options, int verbose)
                return;
        }
 
-       if ((htype = client_gettype(hname)) == MCL_FQDN &&
-           (hp = gethostbyname(hname)) != NULL) {
-               struct hostent *hp2 = hostent_dup (hp);
-               hp = gethostbyaddr(hp2->h_addr, hp2->h_length,
-                                  hp2->h_addrtype);
-               if (hp) {
-                       free(hp2);
-                       hp = hostent_dup(hp);
-               } else
-                       hp = hp2;
-               exp = export_find(hp, path);
-               hname = hp->h_name;
-       } else {
+       if ((htype = client_gettype(hname)) == MCL_FQDN) {
+               ai = host_addrinfo(hname);
+               if (ai != NULL) {
+                       exp = export_find(ai, path);
+                       hname = ai->ai_canonname;
+               }
+       } else
                exp = export_lookup(hname, path, 0);
-       }
 
        if (!exp) {
                if (!(eep = mkexportent(hname, path, options)) ||
-                   !(exp = export_create(eep, 0))) {
-                       if (hp) free (hp);
-                       return;
-               }
-       } else if (!updateexportent(&exp->m_export, options)) {
-               if (hp) free (hp);
-               return;
-       }
+                   !(exp = export_create(eep, 0)))
+                       goto out;
+       } else if (!updateexportent(&exp->m_export, options))
+               goto out;
 
        if (verbose)
                printf("exporting %s:%s\n", exp->m_client->m_hostname, 
@@ -279,14 +269,16 @@ exportfs(char *arg, char *options, int verbose)
        exp->m_changed = 1;
        exp->m_warned = 0;
        validate_export(exp);
-       if (hp) free (hp);
+
+out:
+       freeaddrinfo(ai);
 }
 
 static void
 unexportfs(char *arg, int verbose)
 {
        nfs_export      *exp;
-       struct hostent  *hp = NULL;
+       struct addrinfo *ai = NULL;
        char            *path;
        char            *hname = arg;
        int             htype;
@@ -301,13 +293,12 @@ unexportfs(char *arg, int verbose)
        }
 
        if ((htype = client_gettype(hname)) == MCL_FQDN) {
-               if ((hp = gethostbyname(hname)) != 0) {
-                       hp = hostent_dup (hp);
-                       hname = (char *) hp->h_name;
-               }
+               ai = host_addrinfo(hname);
+               if (ai)
+                       hname = ai->ai_canonname;
        }
 
-       for (exp = exportlist[htype]; exp; exp = exp->m_next) {
+       for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
                if (path && strcmp(path, exp->m_export.e_path))
                        continue;
                if (htype != exp->m_client->m_type)
@@ -340,7 +331,7 @@ unexportfs(char *arg, int verbose)
                exp->m_mayexport = 0;
        }
 
-       if (hp) free (hp);
+       freeaddrinfo(ai);
 }
 
 static int can_test(void)
@@ -388,6 +379,8 @@ validate_export(nfs_export *exp)
         */
        struct stat stb;
        char *path = exp->m_export.e_path;
+       struct statfs64 stf;
+       int fs_has_fsid = 0;
 
        if (stat(path, &stb) < 0) {
                fprintf(stderr, "exportfs: Warning: %s does not exist\n",
@@ -403,7 +396,12 @@ validate_export(nfs_export *exp)
        if (!can_test())
                return;
 
-       if ((exp->m_export.e_flags & NFSEXP_FSID) || exp->m_export.e_uuid) {
+       if (!statfs64(path, &stf) &&
+           (stf.f_fsid.__val[0] || stf.f_fsid.__val[1]))
+               fs_has_fsid = 1;
+
+       if ((exp->m_export.e_flags & NFSEXP_FSID) || exp->m_export.e_uuid ||
+           fs_has_fsid) {
                if ( !test_export(path, 1)) {
                        fprintf(stderr, "exportfs: Warning: %s does not "
                                "support NFS export.\n",
@@ -445,7 +443,7 @@ dump(int verbose)
        char            *hname, c;
 
        for (htype = 0; htype < MCL_MAXTYPES; htype++) {
-               for (exp = exportlist[htype]; exp; exp = exp->m_next) {
+               for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
                        ep = &exp->m_export;
                        if (!exp->m_xtabent)
                            continue; /* neilb */