]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mountd/v4root.c
mountd: make local functions in v4root.c static
[nfs-utils.git] / utils / mountd / v4root.c
index d890181b5f2fab86ce60c26978884aab25e624fb..34d098ad28d18ee3441f2a068b6acdae8122ea5d 100644 (file)
@@ -46,6 +46,7 @@ static nfs_export pseudo_root = {
                .e_nsqgids = 0,
                .e_fsid = 0,
                .e_mountpoint = NULL,
+               .e_ttl = DEFAULT_TTL,
        },
        .m_exported = 0,
        .m_xtabent = 1,
@@ -54,13 +55,16 @@ static nfs_export pseudo_root = {
        .m_warned = 0,
 };
 
-void set_pseudofs_security(struct exportent *pseudo, struct exportent *source)
+static void
+set_pseudofs_security(struct exportent *pseudo, struct exportent *source)
 {
        struct sec_entry *se;
        int i;
 
        if (source->e_flags & NFSEXP_INSECURE_PORT)
                pseudo->e_flags |= NFSEXP_INSECURE_PORT;
+       if ((source->e_flags & NFSEXP_ROOTSQUASH) == 0)
+               pseudo->e_flags &= ~NFSEXP_ROOTSQUASH;
        for (se = source->e_secinfo; se->flav; se++) {
                struct sec_entry *new;
 
@@ -83,7 +87,7 @@ v4root_create(char *path, nfs_export *export)
        struct exportent *curexp = &export->m_export;
 
        dupexportent(&eep, &pseudo_root.m_export);
-       eep.e_hostname = strdup(curexp->e_hostname);
+       eep.e_hostname = curexp->e_hostname;
        strncpy(eep.e_path, path, sizeof(eep.e_path));
        if (strcmp(path, "/") != 0)
                eep.e_flags &= ~NFSEXP_FSID;
@@ -91,7 +95,8 @@ v4root_create(char *path, nfs_export *export)
        exp = export_create(&eep, 0);
        if (exp == NULL)
                return NULL;
-       xlog(D_CALL, "v4root_create: path '%s'", exp->m_export.e_path);
+       xlog(D_CALL, "v4root_create: path '%s' flags 0x%x", 
+               exp->m_export.e_path, exp->m_export.e_flags);
        return &exp->m_export;
 }
 
@@ -117,7 +122,8 @@ v4root_support(void)
        return 0;
 }
 
-int pseudofs_update(char *hostname, char *path, nfs_export *source)
+static int
+pseudofs_update(char *hostname, char *path, nfs_export *source)
 {
        nfs_export *exp;
 
@@ -137,6 +143,34 @@ int pseudofs_update(char *hostname, char *path, nfs_export *source)
        return 0;
 }
 
+static int v4root_add_parents(nfs_export *exp)
+{
+       char *hostname = exp->m_export.e_hostname;
+       char *path;
+       char *ptr;
+
+       path = strdup(exp->m_export.e_path);
+       if (!path) {
+               xlog(L_WARNING, "v4root_add_parents: Unable to create "
+                               "pseudo export for '%s'", exp->m_export.e_path);
+               return -ENOMEM;
+       }
+       for (ptr = path; ptr; ptr = strchr(ptr, '/')) {
+               int ret;
+               char saved;
+
+               saved = *ptr;
+               *ptr = '\0';
+               ret = pseudofs_update(hostname, *path ? path : "/", exp);
+               if (ret)
+                       return ret;
+               *ptr = saved;
+               ptr++;
+       }
+       free(path);
+       return 0;
+}
+
 /*
  * Create pseudo exports by running through the real export
  * looking at the components of the path that make up the export.
@@ -147,10 +181,8 @@ int pseudofs_update(char *hostname, char *path, nfs_export *source)
 void
 v4root_set()
 {
-       nfs_export      *exp, *nxt;
+       nfs_export      *exp;
        int     i;
-       char *path, *ptr;
-       char *hostname;
 
        if (!v4root_needed)
                return;
@@ -158,23 +190,23 @@ v4root_set()
                return;
 
        for (i = 0; i < MCL_MAXTYPES; i++) {
-               for (exp = exportlist[i].p_head; exp; exp = nxt) {
-                       nxt = exp->m_next;
-                       hostname = exp->m_export.e_hostname;
-
-                       path = strdup(exp->m_export.e_path);
-                       for (ptr = path + 1; ptr; ptr = strchr(ptr, '/')) {
-                               int ret;
-                               char saved;
-
-                               saved = *ptr;
-                               *ptr = '\0';
-                               ret = pseudofs_update(hostname, path, exp);
-                               /* XXX: error handling */
-                               *ptr = saved;
-                               ptr++;
+               for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
+                       if (exp->m_export.e_flags & NFSEXP_V4ROOT)
+                               /*
+                                * We just added this one, so its
+                                * parents are already dealt with!
+                                */
+                               continue;
+
+                       if (strcmp(exp->m_export.e_path, "/") == 0 &&
+                           !(exp->m_export.e_flags & NFSEXP_FSID)) {
+                               /* Force '/' to be exported as fsid == 0*/
+                               exp->m_export.e_flags |= NFSEXP_FSID;
+                               exp->m_export.e_fsid = 0;
                        }
-                       free(path);
+
+                       v4root_add_parents(exp);
+                       /* XXX: error handling! */
                }
        }
 }