home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / nfsd / src / mount_functions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-30  |  3.0 KB  |  110 lines

  1. /*  The actual code behind mountd
  2.  
  3.     ©1998,1999 Joseph Walton
  4.  
  5.     This software is distributed under the terms of the GNU General Public
  6.     License; either version 2 of the License, or (at your option) any
  7.     later version.
  8. */
  9.  
  10. /*
  11.     This is a *very* simple mountd implementation - some would call
  12.      it deficient.
  13. */
  14.  
  15. /*
  16.     30-Nov-1999 - Changes to support new RPC code.
  17. */
  18.  
  19. #include "mount.h"
  20. #include "nfsd.h"
  21.  
  22. #include "handle_list.h"
  23. #include "config.h"
  24. #include "auth.h"
  25. #include "nfs_utils.h"
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29.  
  30. extern struct List cfg_list; /* in config.c */
  31.  
  32. /* Give out a handle to a mountpoint */
  33. nfsstat mountproc_mnt(struct Call *call, STRPTR dirpath, int32 *fh)
  34. {
  35.     struct ConfigEntry *ce;
  36.  
  37.     /* A mount is a fairly important operation. We always log it. */
  38.     print_auth_once(call);
  39.     printf("Mounting '%s'\n", dirpath);
  40.  
  41.     /* Authentication is quite important here, but not critical.
  42.         Checks are made on each use - knowing a handle does not
  43.         itself grant privilege.
  44.      */
  45.  
  46.     /* We traverse the list, and stop at the first match.
  47.         If we may export this, we do so. Otherwise we
  48.         return an error. We will not search for further matches.
  49.  
  50.      A linear search isn't terribly elegant, but neither is
  51.         this a frequent operation */
  52.  
  53.     ce = cfg_list.lh_Head;
  54.  
  55.     while (ce->ce_Node.mln_Succ) {
  56.         if (!stricmp(dirpath, ce->ce_ExportAs)) {
  57.  
  58.             /* Let's check that they're allowed to mount that..
  59.                Remember, ce_ExportAs is what they ask for, but
  60.                 we give them ce_Path */
  61.  
  62.             nfsstat stat = does_mount_permit(call, ce->ce_Path, ALLOW_READ);
  63.  
  64.             if (stat != NFS_OK) {
  65.                 printf("Mount failed - %s\n", reason(stat));
  66.                 return stat;
  67.             }
  68.  
  69.             /* The mountpoint does not necessarily exist, but since
  70.                 it's in the configuration file the user clearly wants
  71.                 it to be mountable
  72.             */
  73.  
  74.             struct LocalFile *lf = get_namedlocalfile(ce->ce_Path);
  75.  
  76.             /* Copy the new file handle into the response */
  77.             if (lf) {
  78.                 fh_copy(lf, fh);
  79.  
  80.                 lf->lf_IsMount = TRUE; /* So it won't be flushed */
  81.  
  82.                 lf->lf_ForcedUID = ce->ce_UID;
  83.                 lf->lf_ForcedGID = ce->ce_GID;
  84.                 lf->lf_ForcedProtection = ce->ce_Protection;
  85.  
  86.                 release_lf(lf);
  87.                 /* It will be given an inode when it's asked
  88.                     for its attributes */
  89.  
  90.                 return NFS_OK;
  91.             } else
  92.                 return NFSERR_IO; /* Out of memory, I guess... */
  93.         }
  94.         ce = ce->ce_Node.mln_Succ;
  95.     }
  96.         
  97.     puts("Mount failed - path not exported");
  98.  
  99.     /* If we fall through to here, we have failed */
  100.     return NFSERR_ACCES;
  101. }
  102.  
  103.  
  104. /* Just log what happened - no action is taken */
  105. void mountproc_umnt(struct Call *call, STRPTR dirpath)
  106. {
  107.     print_auth_once(call);
  108.     printf("Unmounting '%s'\n", dirpath);
  109. }
  110.