~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201207201942

« back to all changes in this revision

Viewing changes to lib/hgfsServerPolicyGuest/hgfsServerPolicyGuest.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-10-18 12:28:19 UTC
  • mfrom: (1.1.7 upstream) (2.4.9 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091018122819-00vqew6m0ztpqcqp
Tags: 2009.10.15-201664-1
MergingĀ upstreamĀ versionĀ 2009.10.15-201664.

Show diffs side-by-side

added added

removed removed

Lines of Context:
484
484
/*
485
485
 *-----------------------------------------------------------------------------
486
486
 *
 
487
 * HgfsServerPolicy_ProcessCPName --
 
488
 *
 
489
 *    Get the local path for a share name by looking at the requested
 
490
 *    name, finding the matching share (if any) and returning the share's
 
491
 *    local path local path and permissions.
 
492
 *
 
493
 * Results:
 
494
 *    An HgfsNameStatus value indicating the result is returned.
 
495
 *
 
496
 *    The local path for the shareName is also returned if a match is found.
 
497
 *
 
498
 * Side effects:
 
499
 *    None
 
500
 *
 
501
 *-----------------------------------------------------------------------------
 
502
 */
 
503
 
 
504
HgfsNameStatus
 
505
HgfsServerPolicy_ProcessCPName(char const *nameIn,         // IN: name in CPName form
 
506
                               size_t nameInLen,           // IN: length of the name
 
507
                               Bool *readAccess,           // OUT: Read permissions
 
508
                               Bool *writeAccess,          // OUT: Write permissions
 
509
                               char const **shareBaseDir)  // OUT: Shared directory
 
510
{
 
511
   HgfsSharedFolder *myShare;
 
512
 
 
513
   ASSERT(nameIn);
 
514
   ASSERT(shareBaseDir);
 
515
 
 
516
   myShare = HgfsServerPolicyGetShare(&myState, nameIn, nameInLen);
 
517
   if (!myShare) {
 
518
      LOG(4, ("%s: No matching share name\n", __FUNCTION__));
 
519
      return HGFS_NAME_STATUS_DOES_NOT_EXIST;
 
520
   }
 
521
 
 
522
   *readAccess = myShare->readAccess;
 
523
   *writeAccess = myShare->writeAccess;
 
524
   *shareBaseDir = myShare->path;
 
525
   return HGFS_NAME_STATUS_COMPLETE;
 
526
}
 
527
 
 
528
 
 
529
/*
 
530
 *-----------------------------------------------------------------------------
 
531
 *
487
532
 * HgfsServerPolicy_GetShareOptions --
488
533
 *
489
534
 *    Get the HGFS share config options by looking at the requested name,
608
653
 
609
654
   return HGFS_NAME_STATUS_COMPLETE;
610
655
}
 
656
 
 
657
 
 
658
/*
 
659
 *-----------------------------------------------------------------------------
 
660
 *
 
661
 * HgfsServerPolicy_CheckMode --
 
662
 *
 
663
 *    Checks if the requested mode may be granted depending on read/write permissions.
 
664
 *
 
665
 * Results:
 
666
 *    TRUE if the requested mode can be granted, FALSE otherwise.
 
667
 *
 
668
 * Side effects:
 
669
 *    None
 
670
 *
 
671
 *-----------------------------------------------------------------------------
 
672
 */
 
673
 
 
674
Bool
 
675
HgfsServerPolicy_CheckMode(HgfsOpenMode mode,          // IN: mode to check
 
676
                           Bool writePermissions,      // IN: callers write permissions
 
677
                           Bool readPermissions)       // IN: callers read permissions
 
678
{
 
679
   /*
 
680
    * See if access is allowed in the requested mode.
 
681
    *
 
682
    * XXX Yeah, this is retarded. We should be using bits instead of
 
683
    * an enum for HgfsOpenMode. Add it to the todo list. [bac]
 
684
    */
 
685
   switch (HGFS_OPEN_MODE_ACCMODE(mode)) {
 
686
   case HGFS_OPEN_MODE_READ_ONLY:
 
687
      if (!readPermissions) {
 
688
         LOG(4, ("HgfsServerPolicyCheckMode: Read access denied\n"));
 
689
         return FALSE;
 
690
      }
 
691
      break;
 
692
 
 
693
   case HGFS_OPEN_MODE_WRITE_ONLY:
 
694
      if (!writePermissions) {
 
695
         LOG(4, ("HgfsServerPolicyCheckMode: Write access denied\n"));
 
696
         return FALSE;
 
697
      }
 
698
      break;
 
699
 
 
700
   case HGFS_OPEN_MODE_READ_WRITE:
 
701
      if (!readPermissions || !writePermissions) {
 
702
         LOG(4, ("HgfsServerPolicyCheckMode: Read/write access denied\n"));
 
703
         return FALSE;
 
704
      }
 
705
      break;
 
706
 
 
707
   default:
 
708
      LOG(0, ("HgfsServerPolicyCheckMode: Invalid mode\n"));
 
709
      ASSERT(FALSE);
 
710
      return FALSE;
 
711
   }
 
712
 
 
713
   return TRUE;
 
714
}