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

« back to all changes in this revision

Viewing changes to utils/idmapd/idmapd.c

  • Committer: Bazaar Package Importer
  • Author(s): Steinar H. Gunderson
  • Date: 2007-01-05 13:38:07 UTC
  • mfrom: (1.2.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20070105133807-0nvljb85umz1gfwu
Tags: 1:1.0.11~git-20060105-2
08-dont-build-getkversion.patch: We missed tools/Makefile.in on last
refresh, so it ended up in the .diff.gz. Fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
626
626
                snprintf(buf1, sizeof(buf1), "%lu",
627
627
                         time(NULL) + cache_entry_expiration);
628
628
                addfield(&bp, &bsiz, buf1);
629
 
                /* ID */
630
 
                snprintf(buf1, sizeof(buf1), "%u", im.im_id);
631
 
                addfield(&bp, &bsiz, buf1);
 
629
                /* Note that we don't want to write the id if the mapping
 
630
                 * failed; instead, by leaving it off, we write a negative
 
631
                 * cache entry which will result in an error returned to
 
632
                 * the client.  We don't want a chown or setacl referring
 
633
                 * to an unknown user to result in giving permissions to
 
634
                 * "nobody"! */
 
635
                if (im.im_status == IDMAP_STATUS_SUCCESS) {
 
636
                        /* ID */
 
637
                        snprintf(buf1, sizeof(buf1), "%u", im.im_id);
 
638
                        addfield(&bp, &bsiz, buf1);
632
639
 
 
640
                }
633
641
                //if (bsiz == sizeof(buf)) /* XXX */
634
642
 
635
643
                bp[-1] = '\n';
646
654
                snprintf(buf1, sizeof(buf1), "%lu",
647
655
                         time(NULL) + cache_entry_expiration);
648
656
                addfield(&bp, &bsiz, buf1);
 
657
                /* Note we're ignoring the status field in this case; we'll
 
658
                 * just map to nobody instead. */
649
659
                /* Name */
650
660
                addfield(&bp, &bsiz, im.im_name);
651
661
 
718
728
 
719
729
        imconv(ic, &im);
720
730
 
 
731
        /* XXX: I don't like ignoring this error in the id->name case,
 
732
         * but we've never returned it, and I need to check that the client
 
733
         * can handle it gracefully before starting to return it now. */
 
734
 
 
735
        if (im.im_status == IDMAP_STATUS_LOOKUPFAIL)
 
736
                im.im_status = IDMAP_STATUS_SUCCESS;
 
737
 
721
738
        if (atomicio(write, ic->ic_fd, &im, sizeof(im)) != sizeof(im))
722
739
                idmapd_warn("nfscb: write(%s)", ic->ic_path);
723
740
out:
837
854
                }
838
855
                break;
839
856
        }
840
 
        /* XXX Hack? */
841
 
        im->im_status = IDMAP_STATUS_SUCCESS;
 
857
        if (ret)
 
858
                im->im_status = IDMAP_STATUS_LOOKUPFAIL;
 
859
        else
 
860
                im->im_status = IDMAP_STATUS_SUCCESS;
842
861
}
843
862
 
844
863
static void
848
867
        gid_t gid;
849
868
        int ret = 0;
850
869
 
851
 
        /* XXX: nobody fallbacks shouldn't always happen:
852
 
         *      server id -> name should be OK
853
 
         *      client name -> id should be OK
854
 
         * but not otherwise */
855
870
        /* XXX: move nobody stuff to library calls
856
871
         * (nfs4_get_nobody_user(domain), nfs4_get_nobody_group(domain)) */
857
 
        /* XXX: should make this call higher up in the call chain (so we'd
858
 
         * have a chance on looking up server/whatever. */
 
872
 
 
873
        im->im_status = IDMAP_STATUS_SUCCESS;
 
874
 
859
875
        switch (im->im_type) {
860
876
        case IDMAP_TYPE_USER:
861
877
                ret = nfs4_name_to_uid(im->im_name, &uid);
862
878
                im->im_id = (u_int32_t) uid;
863
 
                if (ret)
 
879
                if (ret) {
 
880
                        im->im_status = IDMAP_STATUS_LOOKUPFAIL;
864
881
                        im->im_id = nobodyuid;
865
 
                break;
 
882
                }
 
883
                return;
866
884
        case IDMAP_TYPE_GROUP:
867
885
                ret = nfs4_name_to_gid(im->im_name, &gid);
868
886
                im->im_id = (u_int32_t) gid;
869
 
                if (ret)
 
887
                if (ret) {
 
888
                        im->im_status = IDMAP_STATUS_LOOKUPFAIL;
870
889
                        im->im_id = nobodygid;
871
 
                break;
 
890
                }
 
891
                return;
872
892
        }
873
 
        /* XXX? */
874
 
        im->im_status = IDMAP_STATUS_SUCCESS;
875
893
}
876
894
 
877
895
static int