Changeset 9163

Show
Ignore:
Timestamp:
12/15/11 12:46:53 (18 months ago)
Author:
sampson
Message:

Updated FUSE module to support new credential system.

Location:
trunk/src
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/apps/fuse/pvfs2fuse.c

    r9147 r9163  
    3434#include "pint-util.h" 
    3535#include "str-utils.h" 
     36#include "pvfs2-util.h" 
     37#include "pint-security.h" 
     38#include "security-util.h" 
    3639 
    3740typedef struct { 
    3841          PVFS_object_ref       ref; 
    39           PVFS_credentials      creds; 
     42          PVFS_credential       cred; 
    4043} pvfs_fuse_handle_t; 
    4144 
     
    7174#endif 
    7275 
    73 static void pvfs_fuse_gen_credentials( 
    74    PVFS_credentials *credentials) 
    75 { 
    76    credentials->uid = fuse_get_context()->uid; 
    77    credentials->gid = fuse_get_context()->gid; 
     76#define pvfs_fuse_cleanup_credential(cred) PINT_cleanup_credential(cred) 
     77 
     78static int pvfs_fuse_gen_credential( 
     79   PVFS_credential *credential) 
     80{ 
     81   struct fuse_context *ctx = fuse_get_context(); 
     82   PVFS_credential *new_cred; 
     83   char uid[16], gid[16]; 
     84   int ret; 
     85 
     86   /* convert uid/gid to strings */ 
     87   ret = snprintf(uid, sizeof(uid), "%u", ctx->uid); 
     88   if (ret < 0 || ret >= sizeof(uid)) 
     89   { 
     90      return -1; 
     91   } 
     92 
     93   ret = snprintf(gid, sizeof(gid), "%u", ctx->gid); 
     94   if (ret < 0 || ret >= sizeof(gid)) 
     95   { 
     96       return -1; 
     97   } 
     98 
     99   /* allocate new credential */ 
     100   new_cred = (PVFS_credential *) malloc(sizeof(PVFS_credential)); 
     101   if (!new_cred) 
     102   { 
     103       return -ENOMEM; 
     104   } 
     105   memset(new_cred, 0, sizeof(PVFS_credential)); 
     106 
     107   /* generate credential -- this process must be running as root */ 
     108   ret = PVFS_util_gen_credential(uid,  
     109                                  gid,  
     110                                  PVFS_DEFAULT_CREDENTIAL_TIMEOUT,  
     111                                  NULL, 
     112                                  new_cred); 
     113 
     114   if (ret == 0) 
     115   { 
     116       /* copy credential to provided buffer */ 
     117       ret = PINT_copy_credential(new_cred, credential);       
     118   } 
     119 
     120   /* free generated credential */ 
     121   pvfs_fuse_cleanup_credential(new_cred); 
     122   free(new_cred); 
     123 
     124   return ret; 
    78125} 
    79126 
     
    88135        */ 
    89136 
    90    pvfs_fuse_gen_credentials(&pfh->creds); 
     137   ret = pvfs_fuse_gen_credential(&pfh->cred); 
     138   if (ret < 0) 
     139   { 
     140      return ret; 
     141   } 
    91142 
    92143   memset(&lk_response, 0, sizeof(lk_response)); 
    93144   ret = PVFS_sys_lookup(pvfs2fuse.fs_id,  
    94145                                                 (char *)path, 
    95                                                  &pfh->creds,  
     146                                                 &pfh->cred,  
    96147                                                 &lk_response,  
    97148                                                 follow_link); 
    98149   if ( ret < 0 ) { 
     150      pvfs_fuse_cleanup_credential(&pfh->cred); 
    99151          return ret; 
    100152   } 
     
    117169   ret = PVFS_sys_getattr(pfhp->ref,  
    118170                          PVFS_ATTR_SYS_ALL_NOHINT, 
    119                           (PVFS_credentials *) &pfhp->creds,  
     171                          (PVFS_credential *) &pfhp->cred,  
    120172                          &getattr_response); 
    121173   if ( ret < 0 ) 
     
    248300   ret = lookup( path, &pfh, PVFS2_LOOKUP_LINK_NO_FOLLOW ); 
    249301   if ( ret < 0 ) 
    250           return PVFS_ERROR_TO_ERRNO_N( ret ); 
    251  
    252    return pvfs_fuse_getattr_pfhp( &pfh, stbuf ); 
     302   { 
     303      return PVFS_ERROR_TO_ERRNO_N( ret ); 
     304   } 
     305 
     306   ret = pvfs_fuse_getattr_pfhp( &pfh, stbuf ); 
     307 
     308   pvfs_fuse_cleanup_credential(&pfh.cred); 
     309 
     310   return ret; 
    253311} 
    254312 
     
    268326   ret = lookup( path, &pfh, PVFS2_LOOKUP_LINK_NO_FOLLOW ); 
    269327   if ( ret < 0 ) 
    270           return PVFS_ERROR_TO_ERRNO_N( ret ); 
    271     
     328   { 
     329      return PVFS_ERROR_TO_ERRNO_N( ret ); 
     330   } 
     331 
    272332   ret = PVFS_sys_getattr(pfh.ref,  
    273333                                                  PVFS_ATTR_SYS_ALL_NOHINT, 
    274                                                   (PVFS_credentials *) &pfh.creds,  
     334                                                  (PVFS_credential *) &pfh.cred,  
    275335                                                  &getattr_response); 
     336 
     337   pvfs_fuse_cleanup_credential(&pfh.cred); 
     338 
    276339   if ( ret < 0 ) 
    277340          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     
    313376   } 
    314377 
    315    lookup( parent, &parent_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); 
     378   rc = lookup( parent, &parent_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); 
     379   if (rc) 
     380   { 
     381      return PVFS_ERROR_TO_ERRNO_N( rc ); 
     382   } 
    316383 
    317384   /* Set attributes */ 
    318385   memset(&attr, 0, sizeof(PVFS_sys_attr)); 
    319    attr.owner = parent_pfh.creds.uid; 
    320    attr.group = parent_pfh.creds.gid; 
     386   attr.owner = parent_pfh.cred.userid; 
     387   attr.group = parent_pfh.cred.group_array[0]; 
    321388   attr.perms = mode; 
    322389   attr.mask = PVFS_ATTR_SYS_ALL_SETABLE; 
     
    325392                                           parent_pfh.ref, 
    326393                                           attr, 
    327                                            &parent_pfh.creds, 
     394                                           &parent_pfh.cred, 
    328395                                           &resp_mkdir); 
     396 
     397   pvfs_fuse_cleanup_credential(&parent_pfh.cred); 
     398 
    329399   if (rc) 
    330400   { 
     
    354424   } 
    355425 
    356    lookup( parent, &parent_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); 
    357  
    358    rc = PVFS_sys_remove(filename, parent_pfh.ref, &parent_pfh.creds); 
     426   rc = lookup( parent, &parent_pfh, PVFS2_LOOKUP_LINK_FOLLOW ); 
    359427   if (rc) 
    360428   { 
     429      return PVFS_ERROR_TO_ERRNO_N( rc ); 
     430   } 
     431 
     432   rc = PVFS_sys_remove(filename, parent_pfh.ref, &parent_pfh.cred); 
     433 
     434   pvfs_fuse_cleanup_credential(&parent_pfh.cred); 
     435 
     436   if (rc) 
     437   { 
    361438          return PVFS_ERROR_TO_ERRNO_N( rc ); 
    362439   } 
     
    377454static int pvfs_fuse_symlink(const char *from, const char *to) 
    378455{ 
    379    int                  ret                        = 0; 
     456   int                  ret = 0; 
    380457   PVFS_sys_attr        attr; 
    381458   PVFS_sysresp_lookup  resp_lookup; 
    382459   PVFS_object_ref      parent_ref; 
    383460   PVFS_sysresp_symlink resp_sym; 
    384    PVFS_credentials    credentials; 
     461   PVFS_credential      credential; 
    385462   pvfs_fuse_handle_t   dir_pfh; 
    386463   char *tofile, *todir, *cp; 
    387464 
    388    pvfs_fuse_gen_credentials(&credentials); 
     465   pvfs_fuse_gen_credential(&credential); 
    389466 
    390467   /* Initialize any variables */ 
     
    395472 
    396473   /* Set the attributes for the new directory */ 
    397    attr.owner = credentials.uid; 
    398    attr.group = credentials.gid; 
     474   attr.owner = credential.userid; 
     475   attr.group = credential.group_array[0]; 
    399476   attr.perms = 0777;               
    400477   attr.mask = (PVFS_ATTR_SYS_ALL_SETABLE); 
     
    435512                                                  (char *) from, 
    436513                                                  attr,  
    437                                                   &credentials,  
     514                                                  &credential,  
    438515                                                  &resp_sym); 
     516 
     517   pvfs_fuse_cleanup_credential(&credential); 
     518   pvfs_fuse_cleanup_credential(&dir_pfh.cred); 
    439519 
    440520   if (ret < 0) 
     
    491571                                                toname, 
    492572                                                todir_pfh.ref, 
    493                                                 &todir_pfh.creds); 
     573                                                &todir_pfh.cred); 
     574 
     575   pvfs_fuse_cleanup_credential(&fromdir_pfh.cred); 
     576   pvfs_fuse_cleanup_credential(&todir_pfh.cred); 
     577 
    494578   if (rc) 
    495579          return PVFS_ERROR_TO_ERRNO_N( rc ); 
     
    512596   new_attr.mask = PVFS_ATTR_SYS_PERM; 
    513597  
    514    ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.creds); 
     598   ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.cred); 
     599 
     600   pvfs_fuse_cleanup_credential(&pfh.cred); 
     601 
    515602   if (ret < 0)  
    516603          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     
    534621   new_attr.mask = PVFS_ATTR_SYS_UID | PVFS_ATTR_SYS_GID; 
    535622  
    536    ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.creds); 
     623   ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.cred); 
     624 
     625   pvfs_fuse_cleanup_credential(&pfh.cred); 
     626 
    537627   if (ret < 0)  
    538628          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     
    550640          return PVFS_ERROR_TO_ERRNO_N( ret ); 
    551641    
    552    ret = PVFS_sys_truncate(pfh.ref,size,&pfh.creds); 
     642   ret = PVFS_sys_truncate(pfh.ref,size,&pfh.cred); 
     643 
     644   pvfs_fuse_cleanup_credential(&pfh.cred); 
     645 
    553646   if (ret < 0)  
    554647          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     
    572665   new_attr.mask = PVFS_ATTR_SYS_ATIME | PVFS_ATTR_SYS_MTIME; 
    573666  
    574    ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.creds); 
     667   ret = PVFS_sys_setattr(pfh.ref,new_attr,&pfh.cred); 
     668 
     669   pvfs_fuse_cleanup_credential(&pfh.cred); 
     670 
    575671   if (ret < 0)  
    576672          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     
    615711 
    616712   ret = PVFS_sys_read(pfh->ref, file_req, offset, buf, 
    617                                            mem_req, &pfh->creds, &resp_io); 
     713                                           mem_req, &pfh->cred, &resp_io); 
     714 
    618715   if (ret == 0)  
    619716   { 
     
    639736 
    640737   ret = PVFS_sys_write(pfh->ref, file_req, offset, (char*)buf, 
    641                                                 mem_req, &pfh->creds, &resp_io); 
     738                                                mem_req, &pfh->cred, &resp_io); 
    642739   if (ret == 0)  
    643740   { 
     
    652749{ 
    653750   int                  ret; 
    654    PVFS_credentials     creds; 
     751   PVFS_credential      cred; 
    655752   PVFS_sysresp_statfs resp_statfs; 
    656753 
    657    pvfs_fuse_gen_credentials(&creds); 
     754   ret = pvfs_fuse_gen_credential(&cred); 
     755   if (ret < 0) 
     756   { 
     757       return PVFS_ERROR_TO_ERRNO_N(ret); 
     758   } 
    658759 
    659760   /* gather normal statfs statistics from system interface */ 
    660761 
    661    ret = PVFS_sys_statfs(pvfs2fuse.fs_id, &creds, &resp_statfs); 
     762   ret = PVFS_sys_statfs(pvfs2fuse.fs_id, &cred, &resp_statfs); 
     763 
     764   pvfs_fuse_cleanup_credential(&cred); 
     765 
    662766   if (ret < 0) 
    663767   { 
     
    691795   
    692796   if ( pfh != NULL ) { 
     797      pvfs_fuse_cleanup_credential(&pfh->cred); 
    693798      free( pfh ); 
    694799      SET_FUSE_HANDLE( fi, NULL ); 
     
    736841          ret = PVFS_sys_readdir( 
    737842                 pfh.ref, (!token ? PVFS_READDIR_START : token), 
    738                  pvfs_dirent_incount, &pfh.creds, &rd_response); 
     843                 pvfs_dirent_incount, &pfh.cred, &rd_response); 
    739844          if(ret < 0) 
    740                  return PVFS_ERROR_TO_ERRNO_N( ret ); 
     845      { 
     846         pvfs_fuse_cleanup_credential(&pfh.cred); 
     847         return PVFS_ERROR_TO_ERRNO_N( ret ); 
     848      } 
    741849 
    742850          for(i = 0; i < rd_response.pvfs_dirent_outcount; i++) 
     
    756864 
    757865   } while(rd_response.pvfs_dirent_outcount == pvfs_dirent_incount); 
     866 
     867   pvfs_fuse_cleanup_credential(&pfh.cred); 
    758868 
    759869   return 0; 
     
    767877   pvfs_fuse_handle_t   pfh; 
    768878   int                  in_group_flag = 0; 
     879   PVFS_uid     uid; 
     880   PVFS_gid     gid; 
    769881 
    770882   ret = lookup( path, &pfh, PVFS2_LOOKUP_LINK_FOLLOW ); 
     
    773885 
    774886   /* give root permission, no matter what */ 
    775    if ( pfh.creds.uid == 0 ) 
     887   if ( pfh.cred.userid == 0 ) 
    776888          return 0; 
    777889 
     
    782894   ret = PVFS_sys_getattr(pfh.ref,  
    783895                          PVFS_ATTR_SYS_ALL_NOHINT, 
    784                           (PVFS_credentials *) &pfh.creds,  
     896                          (PVFS_credential *) &pfh.cred,  
    785897                          &getattr_response); 
     898 
     899   /* copy uid and gid so credential can be freed */ 
     900   uid = pfh.cred.userid; 
     901   gid = pfh.cred.group_array[0]; 
     902   pvfs_fuse_cleanup_credential(&pfh.cred); 
     903 
    786904   if ( ret < 0 ) 
    787           return PVFS_ERROR_TO_ERRNO_N( ret ); 
     905   {             
     906          return PVFS_ERROR_TO_ERRNO_N( ret ); 
     907   } 
    788908 
    789909   attrs = &getattr_response.attr; 
     
    792912 
    793913   /* see if uid matches object owner */ 
    794    if ( attrs->owner == pfh.creds.uid ) 
     914   if ( attrs->owner == uid ) 
    795915   { 
    796916          /* see if object user permissions match access type */ 
     
    823943   } 
    824944 
    825    /* see if gid matches object group */ 
    826    if(attrs->group == pfh.creds.gid) 
     945   /* see if gid matches object group  
     946      TODO: check all groups */ 
     947   if(attrs->group == gid) 
    827948   { 
    828949          /* default group match */ 
     
    833954#if 0 
    834955          /* no default group match, check supplementary groups */ 
    835           ret = PINT_check_group(pfh.creds.uid, attrs->group); 
     956          ret = PINT_check_group(uid, attrs->group); 
    836957          if(ret == 0) 
    837958          { 
     
    8991020   /* Set attributes */ 
    9001021   memset(&attr, 0, sizeof(PVFS_sys_attr)); 
    901    attr.owner = dir_pfh.creds.uid; 
    902    attr.group = dir_pfh.creds.gid; 
     1022   attr.owner = dir_pfh.cred.userid; 
     1023   attr.group = dir_pfh.cred.group_array[0]; 
    9031024   attr.perms = mode; 
    9041025   attr.atime = time(NULL); 
     
    9101031                                                dir_pfh.ref, 
    9111032                                                attr, 
    912                                                 &dir_pfh.creds, 
     1033                                                &dir_pfh.cred, 
    9131034                                                NULL, 
    9141035                                                &resp_create); 
     
    9361057 
    9371058   pfhp->ref = resp_create.ref; 
    938    pfhp->creds = dir_pfh.creds; 
     1059   pfhp->cred = dir_pfh.cred; 
    9391060 
    9401061   SET_FUSE_HANDLE( fi, pfhp ); 
  • trunk/src/common/security/security-util.c

    r9133 r9163  
    222222    if (cap) 
    223223    { 
    224         free(cap->handle_array); 
    225         free(cap->signature); 
    226         free(cap->issuer); 
    227  
     224        if (cap->handle_array) 
     225        { 
     226            free(cap->handle_array); 
     227        } 
     228        if (cap->signature) 
     229        { 
     230            free(cap->signature); 
     231        } 
     232        if (cap->issuer) 
     233        { 
     234            free(cap->issuer); 
     235        } 
     236         
    228237        cap->handle_array = NULL; 
    229238        cap->signature = NULL; 
     
    366375    if (cred) 
    367376    { 
    368         free(cred->group_array); 
    369         free(cred->issuer); 
    370         free(cred->signature); 
    371  
     377        if (cred->group_array) 
     378        { 
     379            free(cred->group_array); 
     380        } 
     381        if (cred->issuer) 
     382        { 
     383            free(cred->issuer); 
     384        } 
     385        if (cred->signature) 
     386        { 
     387            free(cred->signature); 
     388        } 
     389         
    372390        cred->group_array = NULL; 
    373391        cred->issuer = NULL;