[Libsysio-commit] HEAD: libsysio/src access.c
Brought to you by:
lward
From: Lee W. <lw...@us...> - 2009-08-03 19:48:29
|
Update of /cvsroot/libsysio/libsysio/src In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv29518/src Modified Files: access.c Log Message: Two changes: 1) Fixed bug in access; It was using effective IDs instead of real. 2) Created new _sysio_epermitted routine that allows caller to specify which IDs to use. The old routine _sysio_permitted still uses effective. Index: access.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/access.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- access.c 5 May 2009 16:30:18 -0000 1.20 +++ access.c 3 Aug 2009 19:48:19 -0000 1.21 @@ -82,7 +82,7 @@ static struct user_credentials { * Check given access type on given inode. */ static int -check_permission(struct pnode *pno, struct creds *crp, int amode) +check_permission(struct pnode *pno, struct creds *cr, int amode) { mode_t mask; struct inode *ino; @@ -111,8 +111,9 @@ check_permission(struct pnode *pno, stru if (amode & X_OK) mask |= S_IXUSR; + assert(P_ISLOCKED(pno) && PB_ISLOCKED(pno->p_base)); ino = pno->p_base->pb_ino; - assert(ino); + assert(ino && I_ISLOCKED(ino)); err = -EACCES; /* assume error */ stat = &ino->i_stbuf; @@ -121,7 +122,7 @@ check_permission(struct pnode *pno, stru /* * Root? */ - if (_sysio_is_root(crp)) { + if (_sysio_is_root(cr)) { err = 0; break; } @@ -130,7 +131,7 @@ check_permission(struct pnode *pno, stru /* * Owner? */ - if (stat->st_uid == crp->creds_uid) { + if (stat->st_uid == cr->creds_uid) { if ((stat->st_mode & mask) == mask) err = 0; break; @@ -141,8 +142,8 @@ check_permission(struct pnode *pno, stru */ mask >>= 3; group_matched = 0; - gids = crp->creds_gids; - ngids = crp->creds_ngids; + gids = cr->creds_gids; + ngids = cr->creds_ngids; while (ngids) { ngids--; if (stat->st_gid == *gids++) { @@ -320,6 +321,9 @@ _sysio_p_generic_perms_check(struct pnod cr = NULL; break; } + assert(P_ISLOCKED(pno) && + PB_ISLOCKED(pno->p_base) && + pno->p_base->pb_ino && I_ISLOCKED(pno->p_base->pb_ino)); err = (*_sysio_check_permission)(pno, cr, amode); } while (0); if (cr) @@ -327,8 +331,8 @@ _sysio_p_generic_perms_check(struct pnod return err; } -static int -permitted(struct pnode *pno, int amode, int effective) +int +_sysio_epermitted(struct pnode *pno, int amode, int effective) { return PNOP_PERMS_CHECK(pno, amode, effective); @@ -341,7 +345,7 @@ int _sysio_permitted(struct pnode *pno, int amode) { - return permitted(pno, amode, 0); + return _sysio_epermitted(pno, amode, 1); } #ifdef ZERO_SUM_MEMORY @@ -377,7 +381,10 @@ SYSIO_INTERFACE_NAME(access)(const char pno = NULL; break; } - err = permitted(pno, amode, 1); + /* + * Check, using real IDs. + */ + err = _sysio_epermitted(pno, amode, 0); } while (0); if (pno) P_PUT(pno); |