~ken-vandine/ubuntu/natty/nfs-utils/1.2.2-4ubuntu1

« back to all changes in this revision

Viewing changes to utils/mountd/cache.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar, Anibal Monsalve Salazar, Ben Hutchings
  • Date: 2010-04-06 16:11:22 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20100406161122-x7erw0q8xiitoyp6
Tags: 1:1.2.2-1
[ Anibal Monsalve Salazar ]
* New upstream release 
  Build depend on libcap-dev
  Set configure option --enable-nfsv41
* X-ref nfsd({7,8})
  02-524255-manpages.patch by Cyril Brulebois
  Closes: 524255

[ Ben Hutchings ]
* Change maintainer to Debian kernel team; move Aníbal to uploaders and
  add myself to uploaders
* Check for nfsd in /proc/filesystems rather than looking for signs of it in
  /proc/kallsyms (Closes: #563104, #572736)
* Document the -n option to svcgssd, thanks to Alberto Gonzalez Iniesta
  (Closes: #451402, #550270)
* Replace upstream reference in package descriptions with Homepage fields,
  and do not refer to the obsolete CVS repository
* Update policy version to 3.8.4; no changes required
* Override lintian error 'init.d-script-missing-dependency-on-remote_fs';
  the init script does work without /usr mounted

Show diffs side-by-side

added added

removed removed

Lines of Context:
614
614
        return qword_eol(f);
615
615
}
616
616
 
617
 
void nfsd_export(FILE *f)
618
 
{
619
 
        /* requests are:
620
 
         *  domain path
621
 
         * determine export options and return:
622
 
         *  domain path expiry flags anonuid anongid fsid
623
 
         */
624
 
 
625
 
        char *cp;
626
 
        int i;
627
 
        char *dom, *path;
628
 
        nfs_export *exp, *found = NULL;
 
617
static int is_subdirectory(char *subpath, char *path)
 
618
{
 
619
        int l = strlen(path);
 
620
 
 
621
        return strcmp(subpath, path) == 0
 
622
                || (strncmp(subpath, path, l) == 0 && path[l] == '/');
 
623
}
 
624
 
 
625
static int path_matches(nfs_export *exp, char *path)
 
626
{
 
627
        if (exp->m_export.e_flags & NFSEXP_CROSSMOUNT)
 
628
                return is_subdirectory(path, exp->m_export.e_path);
 
629
        return strcmp(path, exp->m_export.e_path) == 0;
 
630
}
 
631
 
 
632
static int client_matches(nfs_export *exp, char *dom, struct hostent *he)
 
633
{
 
634
        if (use_ipaddr)
 
635
                return client_check(exp->m_client, he);
 
636
        return client_member(dom, exp->m_client->m_hostname);
 
637
}
 
638
 
 
639
static int export_matches(nfs_export *exp, char *dom, char *path, struct hostent *he)
 
640
{
 
641
        return path_matches(exp, path) && client_matches(exp, dom, he);
 
642
}
 
643
 
 
644
static nfs_export *lookup_export(char *dom, char *path, struct hostent *he)
 
645
{
 
646
        nfs_export *exp;
 
647
        nfs_export *found = NULL;
629
648
        int found_type = 0;
630
 
        struct in_addr addr;
631
 
        struct hostent *he = NULL;
632
 
 
633
 
 
634
 
        if (readline(fileno(f), &lbuf, &lbuflen) != 1)
635
 
                return;
636
 
 
637
 
        xlog(D_CALL, "nfsd_export: inbuf '%s'", lbuf);
638
 
 
639
 
        cp = lbuf;
640
 
        dom = malloc(strlen(cp));
641
 
        path = malloc(strlen(cp));
642
 
 
643
 
        if (!dom || !path)
644
 
                goto out;
645
 
 
646
 
        if (qword_get(&cp, dom, strlen(lbuf)) <= 0)
647
 
                goto out;
648
 
        if (qword_get(&cp, path, strlen(lbuf)) <= 0)
649
 
                goto out;
650
 
 
651
 
        auth_reload();
652
 
 
653
 
        /* now find flags for this export point in this domain */
 
649
        int i;
 
650
 
654
651
        for (i=0 ; i < MCL_MAXTYPES; i++) {
655
652
                for (exp = exportlist[i].p_head; exp; exp = exp->m_next) {
656
 
                        if (!use_ipaddr && !client_member(dom, exp->m_client->m_hostname))
657
 
                                continue;
658
 
                        if (exp->m_export.e_flags & NFSEXP_CROSSMOUNT) {
659
 
                                /* if path is a mountpoint below e_path, then OK */
660
 
                                int l = strlen(exp->m_export.e_path);
661
 
                                if (strcmp(path, exp->m_export.e_path) == 0 ||
662
 
                                    (strncmp(path, exp->m_export.e_path, l) == 0 &&
663
 
                                     path[l] == '/' &&
664
 
                                     is_mountpoint(path)))
665
 
                                        /* ok */;
666
 
                                else
667
 
                                        continue;
668
 
                        } else if (strcmp(path, exp->m_export.e_path) != 0)
669
 
                                continue;
670
 
                        if (use_ipaddr) {
671
 
                                if (he == NULL) {
672
 
                                        if (!inet_aton(dom, &addr))
673
 
                                                goto out;
674
 
                                        he = client_resolve(addr);
675
 
                                }
676
 
                                if (!client_check(exp->m_client, he))
677
 
                                        continue;
678
 
                        }
 
653
                        if (!export_matches(exp, dom, path, he))
 
654
                                continue;
679
655
                        if (!found) {
680
656
                                found = exp;
681
657
                                found_type = i;
682
658
                                continue;
683
659
                        }
 
660
 
 
661
                        /* Always prefer non-V4ROOT mounts */
 
662
                        if (found->m_export.e_flags & NFSEXP_V4ROOT)
 
663
                                continue;
 
664
 
684
665
                        /* If one is a CROSSMOUNT, then prefer the longest path */
685
666
                        if (((found->m_export.e_flags & NFSEXP_CROSSMOUNT) ||
686
667
                             (exp->m_export.e_flags & NFSEXP_CROSSMOUNT)) &&
703
684
                        }
704
685
                }
705
686
        }
 
687
        return found;
 
688
}
 
689
 
 
690
void nfsd_export(FILE *f)
 
691
{
 
692
        /* requests are:
 
693
         *  domain path
 
694
         * determine export options and return:
 
695
         *  domain path expiry flags anonuid anongid fsid
 
696
         */
 
697
 
 
698
        char *cp;
 
699
        char *dom, *path;
 
700
        nfs_export *found = NULL;
 
701
        struct in_addr addr;
 
702
        struct hostent *he = NULL;
 
703
 
 
704
 
 
705
        if (readline(fileno(f), &lbuf, &lbuflen) != 1)
 
706
                return;
 
707
 
 
708
        xlog(D_CALL, "nfsd_export: inbuf '%s'", lbuf);
 
709
 
 
710
        cp = lbuf;
 
711
        dom = malloc(strlen(cp));
 
712
        path = malloc(strlen(cp));
 
713
 
 
714
        if (!dom || !path)
 
715
                goto out;
 
716
 
 
717
        if (qword_get(&cp, dom, strlen(lbuf)) <= 0)
 
718
                goto out;
 
719
        if (qword_get(&cp, path, strlen(lbuf)) <= 0)
 
720
                goto out;
 
721
 
 
722
        auth_reload();
 
723
 
 
724
        if (use_ipaddr) {
 
725
                if (!inet_aton(dom, &addr))
 
726
                        goto out;
 
727
                he = client_resolve(addr);
 
728
        }
 
729
 
 
730
        found = lookup_export(dom, path, he);
706
731
 
707
732
        if (found) {
708
733
                if (dump_to_cache(f, dom, path, &found->m_export) < 0) {