libsysio-commit Mailing List for libsysio (Page 15)
Brought to you by:
lward
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
(25) |
May
(28) |
Jun
(25) |
Jul
(30) |
Aug
(60) |
Sep
(52) |
Oct
(100) |
Nov
(15) |
Dec
(34) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(89) |
Feb
(48) |
Mar
(22) |
Apr
(59) |
May
(16) |
Jun
(15) |
Jul
(50) |
Aug
(26) |
Sep
(40) |
Oct
(27) |
Nov
(12) |
Dec
|
2005 |
Jan
(24) |
Feb
(11) |
Mar
|
Apr
|
May
(3) |
Jun
(6) |
Jul
|
Aug
(14) |
Sep
(21) |
Oct
(10) |
Nov
|
Dec
|
2006 |
Jan
(8) |
Feb
(5) |
Mar
(2) |
Apr
(6) |
May
(11) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(3) |
2007 |
Jan
(3) |
Feb
(5) |
Mar
(20) |
Apr
(41) |
May
(21) |
Jun
(3) |
Jul
(5) |
Aug
(12) |
Sep
(21) |
Oct
(5) |
Nov
(16) |
Dec
|
2008 |
Jan
|
Feb
(2) |
Mar
(4) |
Apr
(23) |
May
|
Jun
(22) |
Jul
(13) |
Aug
|
Sep
|
Oct
(9) |
Nov
(3) |
Dec
(13) |
2009 |
Jan
(14) |
Feb
(10) |
Mar
(2) |
Apr
(11) |
May
(7) |
Jun
(1) |
Jul
(1) |
Aug
(36) |
Sep
(12) |
Oct
|
Nov
|
Dec
(10) |
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: Lee W. <lw...@us...> - 2006-06-01 21:29:03
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28393/include Modified Files: sysio.h Log Message: Pave the way for alternate credentials and ready work for strict permission checking. Index: sysio.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/sysio.h,v retrieving revision 1.37 retrieving revision 1.38 diff -u -w -b -B -p -r1.37 -r1.38 --- sysio.h 3 May 2006 15:57:28 -0000 1.37 +++ sysio.h 1 Jun 2006 21:28:57 -0000 1.38 @@ -49,6 +49,7 @@ #include <stdarg.h> #include "sysio-cmn.h" +#include "creds.h" #if defined(_DIRENT_H) && _DIRENT_H /* |
From: Lee W. <lw...@us...> - 2006-06-01 21:29:02
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28393/src Modified Files: access.c inode.c mkdir.c Log Message: Pave the way for alternate credentials and ready work for strict permission checking. Index: access.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/access.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -w -b -B -p -r1.12 -r1.13 --- access.c 3 May 2006 22:31:04 -0000 1.12 +++ access.c 1 Jun 2006 21:28:57 -0000 1.13 @@ -55,21 +55,25 @@ #include "inode.h" #include "sysio-symbols.h" -static gid_t *gids = NULL; /* space for gids */ -static unsigned ngids = 0; /* max # gids */ +/* + * Use a persistent buffer for gids. No, not a cache. We just want to + * avoid calling malloc over, and over, and... + */ +static gid_t *gids = NULL; +static int gidslen = 0; /* * Check given access type on given inode. */ -static int -_sysio_check_permission(struct pnode *pno, - uid_t uid, gid_t gid, - gid_t gids[], size_t ngids, - int amode) +int +_sysio_check_permission(struct pnode *pno, struct creds *crp, int amode) { mode_t mask; struct inode *ino; + int err; struct intnl_stat *stat; + gid_t *gids; + int ngids; /* * Check amode. @@ -88,48 +92,68 @@ _sysio_check_permission(struct pnode *pn if (amode & X_OK) mask |= S_IXUSR; - /* - * Check for RO access to the file due to mount - * options. - */ - if (amode & W_OK && IS_RDONLY(pno)) - return -EROFS; - ino = pno->p_base->pb_ino; assert(ino); + err = 0; /* assume success */ + + /* + * Owner? + */ stat = &ino->i_stbuf; - if (stat->st_uid == uid && (stat->st_mode & mask) == mask) - return 0; + if (stat->st_uid == crp->creds_uid && + (stat->st_mode & mask) == mask) + goto out; + /* + * Group? + */ mask >>= 3; - if (stat->st_gid == gid && (stat->st_mode & mask) == mask) - return 0; - + gids = crp->creds_gids; + ngids = crp->creds_ngids; while (ngids) { ngids--; - if (stat->st_gid == *gids++ && (stat->st_mode & mask) == mask) - return 0; + if (stat->st_gid == *gids++ && + (stat->st_mode & mask) == mask) + goto out; } + /* + * Other? + */ mask >>= 3; if ((stat->st_mode & mask) == mask) - return 0; + goto out; + + err = -EACCES; /* fail */ +out: + if (err) + return err; - return -EACCES; + /* + * Check for RO access to the file due to mount + * options. + */ + if (amode & W_OK && IS_RDONLY(pno)) + return -EROFS; + + return 0; } /* - * Determine if a given access is permitted to a give file. + * Cache groups. */ -int -_sysio_permitted(struct pnode *pno, int amode) +static int +_sysio_ldgroups(gid_t gid0, gid_t **gidsp, int *gidslenp) { - int err; - int n; + int n, i; void *p; - err = 0; + n = *gidslenp; + if (n < 8) { + *gidsp = NULL; + n = 8; + } for (;;) { /* * This is far more expensive than I would like. Each time @@ -138,38 +162,66 @@ _sysio_permitted(struct pnode *pno, int * the result, either. The caller could have altered something * asynchronously. Wish we had easy access to this info. */ - n = getgroups(0, NULL); - if (n < 0) { - err = -errno; - break; + if (n > *gidslenp) { + p = realloc(*gidsp, (size_t )n * sizeof(gid_t)); + if (!p) + return -errno; + *gidsp = p; + *gidslenp = n; + } + (*gidsp)[0] = gid0; + i = getgroups(n - 1, *gidsp + 1); + if (i < 0) { + if (errno != EINVAL) + return -errno; + if (INT_MAX / 2 < n) + return -EINVAL; + n *= 2; + continue; } - if ((unsigned )n > ngids) { - p = realloc(gids, n * sizeof(gid_t)); - if (!p && gids) { - err = -ENOMEM; break; } - ngids = n; - gids = p; - } - if (n) { - err = getgroups(n, gids); - if (err < 0) { - if (errno == EINVAL) - continue; - err = -errno; - break; + return i; } + +/* + * Get current credentials. + */ +static int +_sysio_ldcreds(uid_t uid, gid_t gid, struct creds *crp) +{ + int n; + + n = _sysio_ldgroups(gid, &gids, &gidslen); + if (n < 0) + return n; + crp->creds_uid = uid; + crp->creds_gids = gids; + crp->creds_ngids = n; + + return 0; } - err = - _sysio_check_permission(pno, - geteuid(), getegid(), - gids, (size_t )n, - amode); - break; + +static int +_sysio_getcreds(struct creds *crp) +{ + + return _sysio_ldcreds(getuid(), getgid(), crp); } - if (!gids) + +/* + * Determine if a given access is permitted to a given file. + */ +int +_sysio_permitted(struct pnode *pno, int amode) +{ + struct creds cr; + int err; + + err = _sysio_ldcreds(geteuid(), getegid(), &cr); + if (err < 0) return err; + err = _sysio_check_permission(pno, &cr, amode); return err; } @@ -184,7 +236,7 @@ _sysio_access_shutdown() if (gids) free(gids); gids = NULL; - ngids = 0; + gidslen = 0; } #endif @@ -194,6 +246,7 @@ SYSIO_INTERFACE_NAME(access)(const char struct intent intent; int err; struct pnode *pno; + struct creds cr; SYSIO_INTERFACE_DISPLAY_BLOCK; @@ -203,11 +256,12 @@ SYSIO_INTERFACE_NAME(access)(const char err = _sysio_namei(_sysio_cwd, path, 0, &intent, &pno); if (err) SYSIO_INTERFACE_RETURN(-1, err); + err = _sysio_ldcreds(geteuid(), getegid(), &cr); + if (err < 0) + goto out; err = - _sysio_check_permission(pno, - getuid(), getgid(), - NULL, 0, - amode); + _sysio_check_permission(pno, &cr, amode); +out: P_RELE(pno); SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); } Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- inode.c 3 May 2006 22:34:46 -0000 1.24 +++ inode.c 1 Jun 2006 21:28:57 -0000 1.25 @@ -861,6 +861,35 @@ _sysio_pb_path(struct pnode_base *pb, co } /* + * Common set attributes routine. + */ +int +_sysio_setattr(struct pnode *pno, + struct inode *ino, + unsigned mask, + struct intnl_stat *stbuf) +{ + /* + * It is possible that pno is null (for ftruncate call). + */ + + if (pno) + assert(!ino || pno->p_base->pb_ino == ino); + if (!ino) + ino = pno->p_base->pb_ino; + assert(ino); + + if (pno && IS_RDONLY(pno)) + return -EROFS; + + /* + * Determining permission to change the attributes is + * difficult, at best. Just try it. + */ + return (*ino->i_ops.inop_setattr)(pno, ino, mask, stbuf); +} + +/* * Do nothing. */ void Index: mkdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mkdir.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -b -B -p -r1.18 -r1.19 --- mkdir.c 4 May 2006 02:30:27 -0000 1.18 +++ mkdir.c 1 Jun 2006 21:28:57 -0000 1.19 @@ -57,19 +57,20 @@ int _sysio_mkdir(struct pnode *pno, mode_t mode) { - struct inode *ino; + int err; + struct inode *parenti; if (pno->p_base->pb_ino) return -EEXIST; - ino = pno->p_parent->p_base->pb_ino; - assert(ino); - - if (IS_RDONLY(pno)) - return -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) + return err; mode |= S_IFDIR; - return (*ino->i_ops.inop_mkdir)(pno, mode); + parenti = pno->p_parent->p_base->pb_ino; + assert(parenti); + return (*parenti->i_ops.inop_mkdir)(pno, mode); } int @@ -86,13 +87,8 @@ SYSIO_INTERFACE_NAME(mkdir)(const char * if (err) goto out; - err = _sysio_permitted(pno->p_parent, W_OK); - if (err) - goto error; - mode &= ~(_sysio_umask & 0777); /* apply umask */ - err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_mkdir)(pno, mode); -error: + err = _sysio_mkdir(pno, mode); P_RELE(pno); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); |
From: Lee W. <lw...@us...> - 2006-05-04 02:32:19
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21667 Modified Files: namei.c Log Message: Fixed a comment, only. Index: namei.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/namei.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- namei.c 3 May 2006 22:37:23 -0000 1.22 +++ namei.c 4 May 2006 02:32:08 -0000 1.23 @@ -97,11 +97,11 @@ lookup(struct pnode *parent, if (!parent->p_base->pb_ino) return -ENOTDIR; - if (check_permissions) { /* - * Sometimes we don't want to do this. At initialization + * Sometimes we don't want to check permissions. At initialization * time, for instance. */ + if (check_permissions) { err = _sysio_permitted(parent, X_OK); if (err) return err; |
From: Lee W. <lw...@us...> - 2006-05-04 02:31:10
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21220 Modified Files: init.c Log Message: Oops. Mknod case in do_command fell through to open case. Fixed. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -w -b -B -p -r1.29 -r1.30 --- init.c 3 May 2006 22:34:46 -0000 1.29 +++ init.c 4 May 2006 02:31:05 -0000 1.30 @@ -634,6 +634,7 @@ do_creat(char *args) case CREATE_CHR: case CREATE_BLK: err = _sysio_mknod(pno, mode, dev); + break; case CREATE_FILE: err = _sysio_open(pno, O_CREAT|O_EXCL, mode); if (err) |
From: Lee W. <lw...@us...> - 2006-05-04 02:30:32
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21101 Modified Files: mkdir.c Log Message: Um, it's read-only when IS_RDONLY returns true. Oops. Fixed. Index: mkdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mkdir.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -b -B -p -r1.17 -r1.18 --- mkdir.c 3 May 2006 22:34:46 -0000 1.17 +++ mkdir.c 4 May 2006 02:30:27 -0000 1.18 @@ -65,7 +65,7 @@ _sysio_mkdir(struct pnode *pno, mode_t m ino = pno->p_parent->p_base->pb_ino; assert(ino); - if (!IS_RDONLY(pno)) + if (IS_RDONLY(pno)) return -EROFS; mode |= S_IFDIR; |
From: Lee W. <lw...@us...> - 2006-05-03 22:37:26
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21443 Modified Files: namei.c Log Message: Documented the new ND_NOPERMCHECK flag to the path walk routine. Index: namei.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/namei.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -w -b -B -p -r1.21 -r1.22 --- namei.c 3 May 2006 22:34:46 -0000 1.21 +++ namei.c 3 May 2006 22:37:23 -0000 1.22 @@ -158,6 +158,7 @@ lookup(struct pnode *parent, * ND_NOFOLLOW symbolic links are not followed * ND_NEGOK if terminal/leaf does not exist, return * path node (alias) anyway. + * ND_NOPERMCHECK do not check permissions */ int _sysio_path_walk(struct pnode *parent, struct nameidata *nd) |
From: Lee W. <lw...@us...> - 2006-05-03 22:34:51
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20473/src Modified Files: chdir.c init.c inode.c mkdir.c namei.c open.c rmdir.c symlink.c unlink.c Log Message: Updated copyrights. Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- chdir.c 3 May 2006 22:31:04 -0000 1.24 +++ chdir.c 3 May 2006 22:34:46 -0000 1.25 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -w -b -B -p -r1.28 -r1.29 --- init.c 3 May 2006 22:31:04 -0000 1.28 +++ init.c 3 May 2006 22:34:46 -0000 1.29 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- inode.c 3 May 2006 22:31:04 -0000 1.23 +++ inode.c 3 May 2006 22:34:46 -0000 1.24 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: mkdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mkdir.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- mkdir.c 3 May 2006 22:31:04 -0000 1.16 +++ mkdir.c 3 May 2006 22:34:46 -0000 1.17 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: namei.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/namei.c,v retrieving revision 1.20 retrieving revision 1.21 diff -u -w -b -B -p -r1.20 -r1.21 --- namei.c 3 May 2006 22:31:04 -0000 1.20 +++ namei.c 3 May 2006 22:34:46 -0000 1.21 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: open.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/open.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -w -b -B -p -r1.27 -r1.28 --- open.c 3 May 2006 22:31:04 -0000 1.27 +++ open.c 3 May 2006 22:34:46 -0000 1.28 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: rmdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rmdir.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- rmdir.c 3 May 2006 22:31:04 -0000 1.19 +++ rmdir.c 3 May 2006 22:34:46 -0000 1.20 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: symlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/symlink.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- symlink.c 3 May 2006 22:31:04 -0000 1.15 +++ symlink.c 3 May 2006 22:34:46 -0000 1.16 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/unlink.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -b -B -p -r1.17 -r1.18 --- unlink.c 3 May 2006 22:31:04 -0000 1.17 +++ unlink.c 3 May 2006 22:34:46 -0000 1.18 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States |
From: Lee W. <lw...@us...> - 2006-05-03 22:34:50
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20473/include Modified Files: file.h inode.h sysio-cmn.h Log Message: Updated copyrights. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- file.h 3 May 2006 22:31:04 -0000 1.15 +++ file.h 3 May 2006 22:34:46 -0000 1.16 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: inode.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/inode.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- inode.h 3 May 2006 22:31:04 -0000 1.26 +++ inode.h 3 May 2006 22:34:46 -0000 1.27 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States Index: sysio-cmn.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/sysio-cmn.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -b -B -p -r1.10 -r1.11 --- sysio-cmn.h 27 Feb 2006 17:26:55 -0000 1.10 +++ sysio-cmn.h 3 May 2006 22:34:46 -0000 1.11 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2005 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States |
From: Lee W. <lw...@us...> - 2006-05-03 22:31:10
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18135/src Modified Files: access.c chdir.c init.c inode.c mkdir.c mknod.c module.mk namei.c open.c rmdir.c symlink.c unlink.c Log Message: Some code cleanup. Support permission (and RO mount) checks in some routines. Added two new tests; test_mkdir and test_mknod. Index: access.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/access.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -b -B -p -r1.11 -r1.12 --- access.c 3 May 2006 15:57:28 -0000 1.11 +++ access.c 3 May 2006 22:31:04 -0000 1.12 @@ -62,12 +62,13 @@ static unsigned ngids = 0; /* max # g * Check given access type on given inode. */ static int -_sysio_check_permission(struct inode *ino, +_sysio_check_permission(struct pnode *pno, uid_t uid, gid_t gid, gid_t gids[], size_t ngids, int amode) { mode_t mask; + struct inode *ino; struct intnl_stat *stat; /* @@ -91,9 +92,12 @@ _sysio_check_permission(struct inode *in * Check for RO access to the file due to mount * options. */ - if (amode & W_OK && IS_RDONLY(NULL, ino)) + if (amode & W_OK && IS_RDONLY(pno)) return -EROFS; + ino = pno->p_base->pb_ino; + assert(ino); + stat = &ino->i_stbuf; if (stat->st_uid == uid && (stat->st_mode & mask) == mask) return 0; @@ -119,7 +123,7 @@ _sysio_check_permission(struct inode *in * Determine if a given access is permitted to a give file. */ int -_sysio_permitted(struct inode *ino, int amode) +_sysio_permitted(struct pnode *pno, int amode) { int err; int n; @@ -158,7 +162,7 @@ _sysio_permitted(struct inode *ino, int } } err = - _sysio_check_permission(ino, + _sysio_check_permission(pno, geteuid(), getegid(), gids, (size_t )n, amode); @@ -200,7 +204,7 @@ SYSIO_INTERFACE_NAME(access)(const char if (err) SYSIO_INTERFACE_RETURN(-1, err); err = - _sysio_check_permission(pno->p_base->pb_ino, + _sysio_check_permission(pno, getuid(), getgid(), NULL, 0, amode); Index: chdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/chdir.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -w -b -B -p -r1.23 -r1.24 --- chdir.c 14 Oct 2004 14:59:29 -0000 1.23 +++ chdir.c 3 May 2006 22:31:04 -0000 1.24 @@ -101,11 +101,7 @@ _sysio_p_chdir(struct pnode *pno) return err; if (!(pno->p_base->pb_ino && S_ISDIR(pno->p_base->pb_ino->i_stbuf.st_mode))) - err = -ENOTDIR; - else - err = _sysio_permitted(pno->p_base->pb_ino, X_OK); - if (err) - return err; + return -ENOTDIR; /* * Release old if set. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.27 retrieving revision 1.28 diff -u -w -b -B -p -r1.27 -r1.28 --- init.c 3 May 2006 15:57:28 -0000 1.27 +++ init.c 3 May 2006 22:31:04 -0000 1.28 @@ -540,6 +540,15 @@ do_creat(char *args) struct intent intent; dev_t dev; int err; + enum { + CREATE_DIR = 1, + CREATE_CHR = 2, + CREATE_BLK = 3, + CREATE_FILE = 4 + } op; + int intent_mode; + struct inode *ino; + int i; len = strlen(args); if (_sysio_get_args(args, v) - args != (ssize_t )len || @@ -572,69 +581,65 @@ do_creat(char *args) if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) return -ENOENT; + + /* + * Init, get the operation, setup the intent. + */ err = 0; mode = perms; + op = 0; if (strcmp(v[0].ovi_value, "dir") == 0) { - INTENT_INIT(&intent, INT_CREAT, &mode, 0); - err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); - if (err) - return err; - if (pno->p_base->pb_ino) - err = -EEXIST; - else if (IS_RDONLY(pno->p_parent, - pno->p_parent->p_base->pb_ino)) - err = -EROFS; - else { - struct inode *ino; - - ino = pno->p_parent->p_base->pb_ino; - err = (*ino->i_ops.inop_mkdir)(pno, mode); - } - P_RELE(pno); + op = CREATE_DIR; + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); } else if (strcmp(v[0].ovi_value, "chr") == 0) { - if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) - return -EINVAL; + op = CREATE_CHR; mode |= S_IFCHR; - INTENT_INIT(&intent, INT_CREAT, &mode, 0); - err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); + if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) + err = -EINVAL; + } else if (strcmp(v[0].ovi_value, "blk") == 0) { + op = CREATE_BLK; + mode |= S_IFBLK; + INTENT_INIT(&intent, INT_CREAT, &mode, NULL); + if (!(v[5].ovi_value && parse_mm(v[5].ovi_value, &dev) == 0)) + err = -EINVAL; + } else if (strcmp(v[0].ovi_value, "file") == 0) { + op = CREATE_FILE; + intent_mode = O_CREAT|O_EXCL; + INTENT_INIT(&intent, INT_CREAT, &mode, &intent_mode); + } else + err = -EINVAL; if (err) return err; - if (pno->p_base->pb_ino) - err = -EEXIST; - else if (IS_RDONLY(pno->p_parent, - pno->p_parent->p_base->pb_ino)) - err = -EROFS; - else { - struct inode *ino; - ino = pno->p_parent->p_base->pb_ino; - err = (*ino->i_ops.inop_mknod)(pno, mode, dev); - } - P_RELE(pno); - } else if (strcmp(v[0].ovi_value, "blk") == 0) { /* - * We don't support block special files yet. + * Lookup the given path. */ - return -EINVAL; - } else if (strcmp(v[0].ovi_value, "file") == 0) { - int i; - struct inode *ino; - - i = O_CREAT|O_EXCL; - INTENT_INIT(&intent, INT_CREAT, &mode, &i); err = - _sysio_namei(dir, v[1].ovi_value, ND_NEGOK, &intent, &pno); + _sysio_namei(dir, + v[1].ovi_value, + ND_NEGOK|ND_NOPERMCHECK, + &intent, + &pno); if (err) return err; + + /* + * Perform. + */ + switch (op) { + case CREATE_DIR: + err = _sysio_mkdir(pno, mode); + break; + case CREATE_CHR: + case CREATE_BLK: + err = _sysio_mknod(pno, mode, dev); + case CREATE_FILE: err = _sysio_open(pno, O_CREAT|O_EXCL, mode); - if (err) { - P_RELE(pno); - return err; - } + if (err) + break; ino = pno->p_base->pb_ino; - if (!err && v[6].ovi_value) { + if (v[6].ovi_value) { struct iovec iovec; struct intnl_xtvec xtvec; struct ioctx io_context; @@ -670,10 +675,12 @@ do_creat(char *args) i = (*ino->i_ops.inop_close)(ino); if (!err) err = i; - P_RELE(pno); - } else - err = -EINVAL; + break; + default: + abort(); + } + P_RELE(pno); return err; } @@ -758,8 +765,13 @@ do_cd(char *args) if (_sysio_get_args(args, v) - args != (ssize_t )len || !v[0].ovi_value) return -EINVAL; - if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) + if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) { + /* + * We have no namespace yet. They really need to give us + * something to work with. + */ return -ENOENT; + } err = _sysio_namei(dir, v[0].ovi_value, 0, NULL, &pno); if (err) return err; @@ -805,7 +817,7 @@ do_chmd(char *args) if (!(dir = _sysio_cwd) && !(dir = _sysio_root)) return -ENOENT; - err = _sysio_namei(dir, v[0].ovi_value, 0, NULL, &pno); + err = _sysio_namei(dir, v[0].ovi_value, ND_NOPERMCHECK, NULL, &pno); if (err) return err; err = _sysio_setattr(pno, pno->p_base->pb_ino, SETATTR_MODE, &stbuf); @@ -852,7 +864,7 @@ do_open(char *args) return -ENOENT; INTENT_INIT(&intent, INT_OPEN, &m, NULL); pno = NULL; - err = _sysio_namei(dir, v[0].ovi_value, 0, &intent, &pno); + err = _sysio_namei(dir, v[0].ovi_value, ND_NOPERMCHECK, &intent, &pno); if (err) return err; fil = NULL; Index: inode.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/inode.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- inode.c 14 Oct 2004 14:59:29 -0000 1.22 +++ inode.c 3 May 2006 22:31:04 -0000 1.23 @@ -861,27 +861,6 @@ _sysio_pb_path(struct pnode_base *pb, co } /* - * Common set attributes routine. - */ -int -_sysio_setattr(struct pnode *pno, - struct inode *ino, - unsigned mask, - struct intnl_stat *stbuf) -{ - /* It is possible that pno is null (for ftruncate call). */ - - if (pno) { - assert(!(pno->p_base->pb_ino && ino) || pno->p_base->pb_ino == ino); - if (IS_RDONLY(pno, ino)) - return -EROFS; - } - if (!ino && pno->p_base->pb_ino) - ino = pno->p_base->pb_ino; - return (*ino->i_ops.inop_setattr)(pno, ino, mask, stbuf); -} - -/* * Do nothing. */ void Index: mkdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mkdir.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -w -b -B -p -r1.15 -r1.16 --- mkdir.c 12 May 2005 20:17:48 -0000 1.15 +++ mkdir.c 3 May 2006 22:31:04 -0000 1.16 @@ -55,6 +55,24 @@ #include "sysio-symbols.h" int +_sysio_mkdir(struct pnode *pno, mode_t mode) +{ + struct inode *ino; + + if (pno->p_base->pb_ino) + return -EEXIST; + + ino = pno->p_parent->p_base->pb_ino; + assert(ino); + + if (!IS_RDONLY(pno)) + return -EROFS; + + mode |= S_IFDIR; + return (*ino->i_ops.inop_mkdir)(pno, mode); +} + +int SYSIO_INTERFACE_NAME(mkdir)(const char *path, mode_t mode) { int err; @@ -67,16 +85,11 @@ SYSIO_INTERFACE_NAME(mkdir)(const char * err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); if (err) goto out; - if (pno->p_base->pb_ino) { - err = -EEXIST; - goto error; - } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } - mode |= S_IFDIR; + mode &= ~(_sysio_umask & 0777); /* apply umask */ err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_mkdir)(pno, mode); error: Index: mknod.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/mknod.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -b -B -p -r1.17 -r1.18 --- mknod.c 12 May 2005 20:17:50 -0000 1.17 +++ mknod.c 3 May 2006 22:31:04 -0000 1.18 @@ -62,6 +62,31 @@ #undef mknod #undef __xmknod +/* + * Internal routine to make a device node. + */ +int +_sysio_mknod(struct pnode *pno, mode_t mode, dev_t dev) +{ + + if (pno->p_base->pb_ino) + return -EEXIST; + + /* + * Support only regular, character-special and fifos right now. + * (mode & S_IFMT) == 0 is the same as S_IFREG. + */ + if ((mode & S_IFMT) && + !(S_ISREG(mode) || S_ISCHR(mode) || S_ISFIFO(mode))) + return -EINVAL; + + if (IS_RDONLY(pno)) + return -EROFS; + return (*pno->p_parent->p_base->pb_ino->i_ops.inop_mknod)(pno, + mode, + dev); +} + int PREPEND(__, SYSIO_INTERFACE_NAME(xmknod))(int __ver, const char *path, @@ -79,33 +104,17 @@ PREPEND(__, SYSIO_INTERFACE_NAME(xmknod) goto out; } - /* - * Support only regular, character-special and fifos right now. - * (mode & S_IFMT) == 0 is the same as S_IFREG. - */ - if ((mode & S_IFMT) && - !(S_ISREG(mode) || S_ISCHR(mode) || S_ISFIFO(mode))) { - err = -EINVAL; - goto out; - } - mode &= ~(_sysio_umask & 0777); /* apply umask */ INTENT_INIT(&intent, INT_CREAT, &mode, NULL); err = _sysio_namei(_sysio_cwd, path, ND_NEGOK, &intent, &pno); if (err) goto out; - if (pno->p_base->pb_ino) { - err = -EEXIST; - goto error; - } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } - err = - (*pno->p_parent->p_base->pb_ino->i_ops.inop_mknod)(pno, mode, *dev); + err = _sysio_mknod(pno, mode, *dev); error: P_RELE(pno); out: Index: module.mk =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/module.mk,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -b -B -p -r1.10 -r1.11 --- module.mk 25 Oct 2004 14:29:16 -0000 1.10 +++ module.mk 3 May 2006 22:31:04 -0000 1.11 @@ -23,7 +23,7 @@ SRCDIR_SRCS = src/access.c src/chdir.c s src/link.c src/lseek.c src/mkdir.c \ src/mknod.c src/mount.c src/namei.c \ src/open.c src/rw.c src/reconcile.c src/rename.c \ - src/rmdir.c src/stat64.c src/stat.c \ + src/rmdir.c src/setattr.c src/stat64.c src/stat.c \ src/stddir.c src/readdir.c src/readdir64.c \ src/symlink.c src/readlink.c \ src/truncate.c src/unlink.c src/utime.c \ Index: namei.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/namei.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -w -b -B -p -r1.19 -r1.20 --- namei.c 8 Feb 2006 17:17:43 -0000 1.19 +++ namei.c 3 May 2006 22:31:04 -0000 1.20 @@ -88,7 +88,8 @@ lookup(struct pnode *parent, struct qstr *name, struct pnode **pnop, struct intent *intnt, - const char *path) + const char *path, + int check_permissions) { int err; struct pnode *pno; @@ -96,9 +97,15 @@ lookup(struct pnode *parent, if (!parent->p_base->pb_ino) return -ENOTDIR; - err = _sysio_permitted(parent->p_base->pb_ino, X_OK); + if (check_permissions) { + /* + * Sometimes we don't want to do this. At initialization + * time, for instance. + */ + err = _sysio_permitted(parent, X_OK); if (err) return err; + } /* * Short-circuit `.' and `..'; We don't cache those. @@ -295,7 +302,8 @@ _sysio_path_walk(struct pnode *parent, s &_sysio_mount_file_name, &pno, NULL, - NULL); + NULL, + 1); if (pno) P_RELE(pno); if (!err && _sysio_automount(pno) == 0) { @@ -408,7 +416,8 @@ _sysio_path_walk(struct pnode *parent, s (path || !next.len) ? nd->nd_intent : NULL, - (path && next.len) ? path : NULL); + (path && next.len) ? path : NULL, + !(nd->nd_flags & ND_NOPERMCHECK)); if (err) { if (err == -ENOENT && !next.len && Index: open.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/open.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- open.c 18 Jan 2006 00:42:41 -0000 1.26 +++ open.c 3 May 2006 22:31:04 -0000 1.27 @@ -79,7 +79,7 @@ _sysio_open(struct pnode *pno, int flags int err; struct inode *ino; - ro = IS_RDONLY(pno, pno->p_base->pb_ino); + ro = IS_RDONLY(pno); w = flags & (O_WRONLY|O_RDWR); if (w == (O_WRONLY|O_RDWR)) { /* @@ -103,10 +103,7 @@ _sysio_open(struct pnode *pno, int flags if (!err) { ino = parent->p_base->pb_ino; assert(ino); - err = - !IS_RDONLY(parent, ino) - ? (*ino->i_ops.inop_open)(pno, flags, mode) - : -EROFS; + err = (*ino->i_ops.inop_open)(pno, flags, mode); } } else if ((flags & (O_CREAT|O_EXCL)) == (O_CREAT|O_EXCL)) err = -EEXIST; Index: rmdir.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/rmdir.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -w -b -B -p -r1.18 -r1.19 --- rmdir.c 25 Jan 2005 18:59:34 -0000 1.18 +++ rmdir.c 3 May 2006 22:31:04 -0000 1.19 @@ -72,10 +72,9 @@ SYSIO_INTERFACE_NAME(rmdir)(const char * err = -ENOTDIR; goto error; } - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } if (pno->p_ref > 1) { err = -EBUSY; goto error; @@ -85,7 +84,7 @@ SYSIO_INTERFACE_NAME(rmdir)(const char * * driver is implemented using differentiated inode operations based * on file type, such as incore does. */ - err = pno->p_parent->p_base->pb_ino->i_ops.inop_rmdir(pno); + err = (*pno->p_parent->p_base->pb_ino->i_ops.inop_rmdir)(pno); if (err) goto error; /* Index: symlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/symlink.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -b -B -p -r1.14 -r1.15 --- symlink.c 28 Apr 2006 15:01:48 -0000 1.14 +++ symlink.c 3 May 2006 22:31:04 -0000 1.15 @@ -76,11 +76,10 @@ SYSIO_INTERFACE_NAME(symlink)(const char err = -EEXIST; goto error; } - - if (IS_RDONLY(pno, pno->p_base->pb_ino)) { - err = -EROFS; + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } + /* * Use the parent node operations to request the task in case the * driver is implemented using differentiated inode operations based Index: unlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/unlink.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -w -b -B -p -r1.16 -r1.17 --- unlink.c 25 Jan 2005 18:56:15 -0000 1.16 +++ unlink.c 3 May 2006 22:31:04 -0000 1.17 @@ -68,11 +68,12 @@ SYSIO_INTERFACE_NAME(unlink)(const char err = _sysio_namei(_sysio_cwd, path, ND_NOFOLLOW, &intent, &pno); if (err) goto out; - ino = pno->p_base->pb_ino; - if (IS_RDONLY(pno, ino)) { - err = -EROFS; + + err = _sysio_permitted(pno->p_parent, W_OK); + if (err) goto error; - } + + ino = pno->p_base->pb_ino; /* * Use the parent node operations to request the task in case the * driver is implemented using differentiated inode operations based |
From: Lee W. <lw...@us...> - 2006-05-03 22:31:10
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18135/tests Modified Files: Makefile.am Added Files: test_mkdir.c test_mknod.c Log Message: Some code cleanup. Support permission (and RO mount) checks in some routines. Added two new tests; test_mkdir and test_mknod. --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #if 0 #include <dirent.h> #endif #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" #endif #include "test.h" /* * Make directories. * * Usage: mkdir [path...] * * Without any path arguments, the program creates directories named * by the command line args. */ static int do_mkdir(const char *path); static void usage(void); int main(int argc, char *const argv[]) { int i; int err; int n; extern int _test_sysio_startup(void); /* * Parse command line arguments. */ while ((i = getopt(argc, argv, "")) != -1) switch (i) { default: usage(); } /* * Init sysio lib. */ err = _test_sysio_startup(); if (err) { errno = -err; perror("sysio startup"); exit(1); } n = argc - optind; /* * Try path(s) listed on command-line. */ while (optind < argc) { const char *path; path = argv[optind++]; (void )do_mkdir(path); } /* * If no command-line arguments, read from stdin until EOF. */ if (!n) { int doflush; static char buf[4096]; size_t len; char *cp; char c; doflush = 0; while (fgets(buf, sizeof(buf), stdin) != NULL) { len = strlen(buf); cp = buf + len - 1; c = *cp; *cp = '\0'; if (!doflush) do_mkdir(buf); doflush = c == '\n' ? 0 : 1; } } /* * Clean up. */ _test_sysio_shutdown(); return 0; } static int do_mkdir(const char *path) { if (SYSIO_INTERFACE_NAME(mkdir)(path, 777) != 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: mkdir" " [<path> ...\n]"); exit(1); } --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" #endif #include "test.h" /* * Create a node. * * Usage: mknod path {f|b|c} [dev] * * The dev argument should not be present for regular file and FIFO object * creation. */ static int do_mknod(const char *path, mode_t mode, dev_t dev); static void usage(void); int main(int argc, char *const argv[]) { int i; int err; mode_t mode; dev_t dev; extern int _test_sysio_startup(void); /* * Parse command line arguments. */ while ((i = getopt(argc, argv, "")) != -1) switch (i) { default: usage(); } /* * Init sysio lib. */ err = _test_sysio_startup(); if (err) { errno = -err; perror("sysio startup"); exit(1); } if (argc - optind < 2) usage(); if (strlen(argv[optind + 1]) != 1) usage(); mode = 0666; switch (*argv[optind + 1]) { case 'f': mode |= S_IFREG; break; case 'b': mode |= S_IFBLK; break; case 'c': mode |= S_IFCHR; break; case 'p': mode |= S_IFIFO; break; default: usage(); } dev = 0; if (!(S_ISREG(mode) || S_ISFIFO(mode))) dev = atoi(argv[optind + 2]); else if (argc - optind != 2) { (void )fprintf(stderr, "Too many arguments\n"); usage(); } (void )do_mknod(argv[optind + 0], mode, dev); /* * Clean up. */ _test_sysio_shutdown(); return 0; } static int do_mknod(const char *path, mode_t mode, dev_t dev) { if (SYSIO_INTERFACE_NAME(mknod)(path, mode, dev) != 0) { perror(path); return -1; } return 0; } static void usage() { (void )fprintf(stderr, "Usage: mknod path {f|b|c|p} dev\n"); exit(1); } Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- Makefile.am 28 Apr 2006 14:59:42 -0000 1.26 +++ Makefile.am 3 May 2006 22:31:04 -0000 1.27 @@ -1,6 +1,6 @@ noinst_PROGRAMS = test_copy test_stats test_path test_list \ test_getcwd test_link test_unlink test_symlink test_rename \ - test_regions test_stddir test_fcntl_lock + test_regions test_stddir test_fcntl_lock test_mknod test_mkdir CLEANFILES=drv_data.c @@ -89,6 +89,14 @@ test_fcntl_lock_SOURCES=test_fcntl_lock. test_fcntl_lock_CFLAGS=$(CFL) test_fcntl_lock_DEPENDENCIES=$(LIBS) +test_mknod_SOURCES=test_mknod.c $(CMNSRC) +test_mknod_CFLAGS=$(CFL) +test_mknod_DEPENDENCIES=$(LIBS) + +test_mkdir_SOURCES=test_mkdir.c $(CMNSRC) +test_mkdir_CFLAGS=$(CFL) +test_mkdir_DEPENDENCIES=$(LIBS) + drv_data.c: $(CONFIG_DEPENDENCIES) $(top_srcdir)/tests/gendrvdata.sh test -z "drv_data.c" && rm -f drv_data.c; \ $(SHELL) $(top_srcdir)/tests/gendrvdata.sh $(DRIVERS) > drv_data.c |
From: Lee W. <lw...@us...> - 2006-05-03 22:31:09
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18135/include Modified Files: file.h inode.h Log Message: Some code cleanup. Support permission (and RO mount) checks in some routines. Added two new tests; test_mkdir and test_mknod. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -w -b -B -p -r1.14 -r1.15 --- file.h 10 Apr 2006 23:25:54 -0000 1.14 +++ file.h 3 May 2006 22:31:04 -0000 1.15 @@ -115,18 +115,15 @@ struct file { /* * Determine if a file may be read/written. * - * Give it the open file table ptr and a character indicating read, 'r', or - * write 'w'. It will return 0 if that access is permitted or -EBADF, if not. + * Given a ptr to an open file table entry and a flag indicating read or + * write return 0 if the file record indicates that the access is permitted + * or -EBADF, if not. */ #define F_CHKRW(_fil, _c) \ - ((_c) == O_RDONLY \ - ? (((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR) \ - ? 0 \ - : -EBADF) \ - : (((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR) \ - ? (IS_RDONLY(NULL, (_fil)->f_ino) ? -EROFS : 0) \ - : -EBADF)) + (((_c) == O_RDONLY && \ + ((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR)) || \ + ((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR)) struct ioctx; Index: inode.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/inode.h,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- inode.h 4 Aug 2005 20:17:10 -0000 1.25 +++ inode.h 3 May 2006 22:31:04 -0000 1.26 @@ -325,6 +325,7 @@ struct nameidata { */ #define ND_NOFOLLOW 0x01 /* no follow symlinks */ #define ND_NEGOK 0x02 /* last missing is ok */ +#define ND_NOPERMCHECK 0x04 /* don't check perms */ #ifdef AUTOMOUNT_FILE_NAME #define _ND_INIT_AUTOMOUNT(nd) ((nd)->nd_amcnt = 0) @@ -399,16 +400,10 @@ struct ioctx { } while (0) /* - * Return whether a pnode/inode is on a read-only mount or file system. + * Return whether access to a pnode is read-only. */ -#define IS_RDONLY(pno, ino) \ - ((((struct pnode *)(pno)) && \ - ((((struct pnode *)(pno))->p_mount->mnt_flags & MOUNT_F_RO) || \ - (((struct pnode *)(pno))->p_base->pb_ino && \ - (((struct pnode *)(pno))->p_base->pb_ino->i_fs->fs_flags & \ - FS_F_RO)))) || \ - (((struct inode *)(ino)) && \ - (((struct inode *)(ino))->i_fs->fs_flags & FS_F_RO))) +#define IS_RDONLY(pno) \ + ((pno)->p_mount->mnt_flags & MOUNT_F_RO) extern struct pnode *_sysio_root; @@ -463,7 +458,7 @@ extern int _sysio_path_walk(struct pnode #ifdef AUTOMOUNT_FILE_NAME extern void _sysio_next_component(const char *path, struct qstr *name); #endif -extern int _sysio_permitted(struct inode *ino, int amode); +extern int _sysio_permitted(struct pnode *pno, int amode); extern int _sysio_namei(struct pnode *pno, const char *path, unsigned flags, @@ -487,3 +482,5 @@ extern int _sysio_ioctx_done(struct ioct extern ssize_t _sysio_ioctx_wait(struct ioctx *ioctx); extern void _sysio_ioctx_complete(struct ioctx *ioctx); extern int _sysio_open(struct pnode *pno, int flags, mode_t mode); +extern int _sysio_mkdir(struct pnode *where, mode_t mode); +extern int _sysio_mknod(struct pnode *where, mode_t mode, dev_t dev); |
From: Lee W. <lw...@us...> - 2006-05-03 15:57:35
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24736/include Modified Files: sysio.h Log Message: Speed up group ID checks a little by keeping memory allocated instead of reallocating every time. Index: sysio.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/sysio.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -w -b -B -p -r1.36 -r1.37 --- sysio.h 14 Mar 2006 20:13:05 -0000 1.36 +++ sysio.h 3 May 2006 15:57:28 -0000 1.37 @@ -122,6 +122,9 @@ extern mode_t _sysio_umask; extern int _sysio_init(void); extern void _sysio_shutdown(void); +#ifdef ZERO_SUM_MEMORY +extern void _sysio_access_shutdown(void); +#endif #if 0 struct _sysio_boot_ctl { |
From: Lee W. <lw...@us...> - 2006-05-03 15:57:32
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24736/src Modified Files: access.c init.c Log Message: Speed up group ID checks a little by keeping memory allocated instead of reallocating every time. Index: access.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/access.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -w -b -B -p -r1.10 -r1.11 --- access.c 21 Sep 2004 16:18:30 -0000 1.10 +++ access.c 3 May 2006 15:57:28 -0000 1.11 @@ -9,7 +9,7 @@ * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * - * Cplant(TM) Copyright 1998-2003 Sandia Corporation. + * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States @@ -50,9 +50,14 @@ #include <sys/queue.h> #include "sysio.h" +#include "mount.h" +#include "fs.h" #include "inode.h" #include "sysio-symbols.h" +static gid_t *gids = NULL; /* space for gids */ +static unsigned ngids = 0; /* max # gids */ + /* * Check given access type on given inode. */ @@ -82,6 +87,13 @@ _sysio_check_permission(struct inode *in if (amode & X_OK) mask |= S_IXUSR; + /* + * Check for RO access to the file due to mount + * options. + */ + if (amode & W_OK && IS_RDONLY(NULL, ino)) + return -EROFS; + stat = &ino->i_stbuf; if (stat->st_uid == uid && (stat->st_mode & mask) == mask) return 0; @@ -110,22 +122,33 @@ int _sysio_permitted(struct inode *ino, int amode) { int err; - gid_t *gids; int n; void *p; err = 0; - gids = NULL; for (;;) { + /* + * This is far more expensive than I would like. Each time + * called it has to go to some length to acquire the + * current uid and groups membership. We can't just cache + * the result, either. The caller could have altered something + * asynchronously. Wish we had easy access to this info. + */ n = getgroups(0, NULL); - if (!n) + if (n < 0) { + err = -errno; break; + } + if ((unsigned )n > ngids) { p = realloc(gids, n * sizeof(gid_t)); if (!p && gids) { err = -ENOMEM; break; } + ngids = n; gids = p; + } + if (n) { err = getgroups(n, gids); if (err < 0) { if (errno == EINVAL) @@ -133,6 +156,7 @@ _sysio_permitted(struct inode *ino, int err = -errno; break; } + } err = _sysio_check_permission(ino, geteuid(), getegid(), @@ -142,10 +166,24 @@ _sysio_permitted(struct inode *ino, int } if (!gids) return err; - free(gids); return err; } +#ifdef ZERO_SUM_MEMORY +/* + * Clean up persistent resource on shutdown. + */ +void +_sysio_access_shutdown() +{ + + if (gids) + free(gids); + gids = NULL; + ngids = 0; +} +#endif + int SYSIO_INTERFACE_NAME(access)(const char *path, int amode) { Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.26 retrieving revision 1.27 diff -u -w -b -B -p -r1.26 -r1.27 --- init.c 27 Feb 2006 17:26:55 -0000 1.26 +++ init.c 3 May 2006 15:57:28 -0000 1.27 @@ -210,6 +210,7 @@ _sysio_shutdown() _sysio_fd_shutdown(); _sysio_i_shutdown(); _sysio_fssw_shutdown(); + _sysio_access_shutdown(); #if SYSIO_TRACING { struct trace_callback *tcb; |
From: Lee W. <lw...@us...> - 2006-04-28 15:01:57
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20482 Modified Files: symlink.c Log Message: Fixed a bug in symlink (from Bob Glossman @ cray.com). symlink b a symlink b a Would result in a->a. Itnow throws an error, with EEXIST, as it should. Index: symlink.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/symlink.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- symlink.c 25 Jan 2005 18:56:15 -0000 1.13 +++ symlink.c 28 Apr 2006 15:01:48 -0000 1.14 @@ -64,7 +64,12 @@ SYSIO_INTERFACE_NAME(symlink)(const char SYSIO_INTERFACE_ENTER; INTENT_INIT(&intent, INT_CREAT, NULL, NULL); - err = _sysio_namei(_sysio_cwd, newpath, ND_NEGOK, &intent, &pno); + err = + _sysio_namei(_sysio_cwd, + newpath, + ND_NOFOLLOW|ND_NEGOK, + &intent, + &pno); if (err) goto out; if (pno->p_base->pb_ino) { |
From: Lee W. <lw...@us...> - 2006-04-28 15:00:03
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20144 Modified Files: Makefile.am Added Files: test_symlink.c Log Message: Added symlink test program. --- NEW FILE --- /* * This Cplant(TM) source code is the property of Sandia National * Laboratories. * * This Cplant(TM) source code is copyrighted by Sandia National * Laboratories. * * The redistribution of this Cplant(TM) source code is subject to the * terms of the GNU Lesser General Public License * (see cit/LGPL or http://www.gnu.org/licenses/lgpl.html) * * Cplant(TM) Copyright 1998-2006 Sandia Corporation. * Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive * license for use of this work by or on behalf of the US Government. * Export of this program may require a license from the United States * Government. */ /* * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Questions or comments about this library should be sent to: * * Lee Ward * Sandia National Laboratories, New Mexico * P.O. Box 5800 * Albuquerque, NM 87185-1110 * * le...@sa... */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #if 0 #include <dirent.h> #endif #include <sys/uio.h> #include <sys/queue.h> #if defined(SYSIO_LABEL_NAMES) #include "sysio.h" #endif #include "xtio.h" #include "test.h" /* * Test soft links * * Usage: symlink oldpath newpath * */ static void usage(void); int main(int argc, char *const argv[]) { int i; int err; int n; extern int _test_sysio_startup(void); /* * Parse command line arguments. */ while ((i = getopt(argc, argv, "")) != -1) switch (i) { default: usage(); } /* * Init sysio lib. */ err = _test_sysio_startup(); if (err) { errno = -err; perror("sysio startup"); exit(1); } n = argc - optind; if (n < 2) usage(); /* * Try paths listed on command-line. */ while (optind < argc) { const char *old, *new; struct stat stbuf; old = argv[optind++]; new = argv[optind++]; if ((err = SYSIO_INTERFACE_NAME(symlink)(old, new)) != 0) { perror("link"); break; } if ((err = SYSIO_INTERFACE_NAME(lstat)(new, &stbuf)) != 0) { perror(new); break; } } /* * Clean up. */ _test_sysio_shutdown(); return err ? -1 : 0; } static void usage() { (void )fprintf(stderr, "Usage: symlink" " oldpath newpath\n"); exit(1); } Index: Makefile.am =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/Makefile.am,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- Makefile.am 28 Oct 2005 17:59:31 -0000 1.25 +++ Makefile.am 28 Apr 2006 14:59:42 -0000 1.26 @@ -1,5 +1,5 @@ noinst_PROGRAMS = test_copy test_stats test_path test_list \ - test_getcwd test_link test_unlink test_rename \ + test_getcwd test_link test_unlink test_symlink test_rename \ test_regions test_stddir test_fcntl_lock CLEANFILES=drv_data.c @@ -69,6 +69,10 @@ test_unlink_SOURCES=test_unlink.c $(CMNS test_unlink_CFLAGS=$(CFL) test_unlink_DEPENDENCIES=$(LIBS) +test_symlink_SOURCES=test_symlink.c $(CMNSRC) +test_symlink_CFLAGS=$(CFL) +test_symlink_DEPENDENCIES=$(LIBS) + test_rename_SOURCES=test_rename.c $(CMNSRC) test_rename_CFLAGS=$(CFL) test_rename_DEPENDENCIES=$(LIBS) |
From: Lee W. <lw...@us...> - 2006-04-10 23:25:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6661/src Modified Files: truncate.c Log Message: Add a new macro, F_CHKRW, that given a pointer to an open file table entry and one of 'r' or 'w' will return: 0 if the access is permitted against the open file -EBADF if not opened for the desired access -EROFS if 'w' and the file system was mounted read-only Then, using the new macro, implemented a check for the truncate/ftruncate calls to assure the file and mount will permit the operation before attempting it against the lower-level driver. Index: truncate.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/truncate.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- truncate.c 21 Sep 2004 16:18:31 -0000 1.13 +++ truncate.c 10 Apr 2006 23:25:54 -0000 1.14 @@ -43,6 +43,7 @@ #include <unistd.h> #include <string.h> +#include <fcntl.h> #include <errno.h> #include <assert.h> #include <sys/types.h> @@ -52,6 +53,8 @@ #include "sysio.h" #include "inode.h" #include "file.h" +#include "fs.h" +#include "mount.h" #include "sysio-symbols.h" @@ -133,6 +136,9 @@ PREPEND(_, SYSIO_INTERFACE_NAME(ftruncat err = -EBADF; goto out; } + err = F_CHKRW(fil, 'w'); + if (err) + goto out; err = do_truncate(NULL, fil->f_ino, length); out: SYSIO_INTERFACE_RETURN(err ? -1 : 0, err); |
From: Lee W. <lw...@us...> - 2006-04-10 23:25:58
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6661/include Modified Files: file.h Log Message: Add a new macro, F_CHKRW, that given a pointer to an open file table entry and one of 'r' or 'w' will return: 0 if the access is permitted against the open file -EBADF if not opened for the desired access -EROFS if 'w' and the file system was mounted read-only Then, using the new macro, implemented a check for the truncate/ftruncate calls to assure the file and mount will permit the operation before attempting it against the lower-level driver. Index: file.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/file.h,v retrieving revision 1.13 retrieving revision 1.14 diff -u -w -b -B -p -r1.13 -r1.14 --- file.h 31 Oct 2005 19:47:42 -0000 1.13 +++ file.h 10 Apr 2006 23:25:54 -0000 1.14 @@ -112,6 +112,22 @@ struct file { (fil)->f_flags = (flags); \ } while (0) +/* + * Determine if a file may be read/written. + * + * Give it the open file table ptr and a character indicating read, 'r', or + * write 'w'. It will return 0 if that access is permitted or -EBADF, if not. + */ + +#define F_CHKRW(_fil, _c) \ + ((_c) == O_RDONLY \ + ? (((_fil)->f_flags & O_RDONLY || (_fil)->f_flags & O_RDWR) \ + ? 0 \ + : -EBADF) \ + : (((_fil)->f_flags & O_WRONLY || (_fil)->f_flags & O_RDWR) \ + ? (IS_RDONLY(NULL, (_fil)->f_ino) ? -EROFS : 0) \ + : -EBADF)) + struct ioctx; extern struct file *_sysio_fnew(struct inode *ino, int flags); |
From: Lee W. <lw...@us...> - 2006-04-10 23:21:30
|
Update of /cvsroot/libsysio/libsysio/drivers/native In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5764 Modified Files: fs_native.c Log Message: Fixed a bug in truncate/ftruncate. It was ignoreing the return code; Always returned success. Index: fs_native.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/drivers/native/fs_native.c,v retrieving revision 1.58 retrieving revision 1.59 diff -u -w -b -B -p -r1.58 -r1.59 --- fs_native.c 24 Oct 2005 18:20:37 -0000 1.58 +++ fs_native.c 10 Apr 2006 23:21:24 -0000 1.59 @@ -868,9 +868,11 @@ native_inop_setattr(struct pnode *pno, /* * Do the truncate last. It can't be undone. */ - (void )(fd < 0 + err = fd < 0 ? syscall(SYSIO_SYS_truncate, path, stat->st_size) - : syscall(SYSIO_SYS_ftruncate, fd, stat->st_size)); + : syscall(SYSIO_SYS_ftruncate, fd, stat->st_size); + if (err) + err = -errno; } if (!err) goto out; |
From: Lee W. <lw...@us...> - 2006-04-07 18:32:17
|
Update of /cvsroot/libsysio/libsysio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25696 Modified Files: AUTHORS Log Message: Updated to reflect miscellaneous contributions from other organizations. Index: AUTHORS =================================================================== RCS file: /cvsroot/libsysio/libsysio/AUTHORS,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -w -b -B -p -r1.1.1.1 -r1.2 --- AUTHORS 22 Feb 2003 16:33:05 -0000 1.1.1.1 +++ AUTHORS 7 Apr 2006 18:32:10 -0000 1.2 @@ -1 +1,6 @@ Lee Ward <le...@sa...> + +Various folks at: + +Cluster File Systems Incorporated. (www.clusterfs.com) +Cray Incorporated (www.cray.com) |
From: Ruth K. <rk...@us...> - 2006-03-24 16:34:14
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11070 Modified Files: fcntl.c Log Message: Fix from Cray, SPR 734613, "bad return values from successful fcntl() file locking calls" Index: fcntl.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/fcntl.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -w -b -B -p -r1.24 -r1.25 --- fcntl.c 3 Jan 2006 13:05:29 -0000 1.24 +++ fcntl.c 24 Mar 2006 16:34:07 -0000 1.25 @@ -259,8 +259,7 @@ _sysio_vfcntl(int fd, int cmd, va_list a fl64 = va_arg(ap, struct flock64 *); err = _sysio_fcntl_lock(fil, cmd, fl64); - if (err) - rtn = -1; + rtn = err ? -1 : 0; } break; #endif |
From: Lee W. <lw...@us...> - 2006-03-14 20:13:17
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23600 Modified Files: sysio.h Log Message: From Jim Schutt at Sandia, we are missing the declaration for lstat64. His patch applied with this rev. Index: sysio.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/sysio.h,v retrieving revision 1.35 retrieving revision 1.36 diff -u -w -b -B -p -r1.35 -r1.36 --- sysio.h 28 Oct 2005 17:59:31 -0000 1.35 +++ sysio.h 14 Mar 2006 20:13:05 -0000 1.36 @@ -175,6 +175,7 @@ extern int SYSIO_INTERFACE_NAME(fcntl64) extern int SYSIO_INTERFACE_NAME(fstat)(int fd, struct stat *buf); #if _LARGEFILE64_SOURCE extern int SYSIO_INTERFACE_NAME(fstat64)(int fd, struct stat64 *buf); +extern int SYSIO_INTERFACE_NAME(lstat64)(const char *path, struct stat64 *buf); #endif extern int SYSIO_INTERFACE_NAME(fsync)(int fd); extern char *SYSIO_INTERFACE_NAME(getcwd)(char *buf, size_t size); |
From: Lee W. <lw...@us...> - 2006-02-27 17:26:58
|
Update of /cvsroot/libsysio/libsysio/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21374/src Modified Files: init.c Log Message: Tracing now can reference user-supplied data. The callbacks are supplied the data pointer originally given at registration. A destructor, given at registration, is called with a copy of the user-supplied data pointer when the the trace remove function is invoked if it wasn't NULL. Index: init.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/src/init.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -w -b -B -p -r1.25 -r1.26 --- init.c 18 Jan 2006 00:47:41 -0000 1.25 +++ init.c 27 Feb 2006 17:26:55 -0000 1.26 @@ -85,16 +85,23 @@ * Tracing callback record. */ struct trace_callback { - TAILQ_ENTRY(trace_callback) links; - void (*f)(const char *file, const char *func, int line); + TAILQ_ENTRY(trace_callback) links; /* trace list links */ + void (*f)(const char *file, /* callback function */ + const char *func, + int line, + void *data); + void *data; /* callback data */ + void (*destructor)(void *data); /* data destructor */ }; /* * Initialize a tracing callback record. */ -#define TCB_INIT(__tcb, __f) \ +#define TCB_INIT(__tcb, __f, __d, __destroy) \ do { \ (__tcb)->f = (__f); \ + (__tcb)->data = (__d); \ + (__tcb)->destructor = (__destroy); \ } while (0); /* @@ -210,14 +217,10 @@ _sysio_shutdown() /* * Empty the trace queues and free the entries. */ - while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_entry_trace_head, tcb, links); - free(tcb); - } - while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) { - TAILQ_REMOVE(&_sysio_exit_trace_head, tcb, links); - free(tcb); - } + while ((tcb = _sysio_entry_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_entry_trace_head, tcb); + while ((tcb = _sysio_exit_trace_head.tqh_first) != NULL) + _sysio_remove_trace(&_sysio_exit_trace_head, tcb); } #endif #endif @@ -316,14 +319,17 @@ void * _sysio_register_trace(void *q, void (*f)(const char *file, const char *func, - int line)) + int line, + void *data), + void *data, + void (*destructor)(void *data)) { struct trace_callback *tcb; tcb = malloc(sizeof(struct trace_callback)); if (!tcb) return NULL; - TCB_INIT(tcb, f); + TCB_INIT(tcb, f, data, destructor); TAILQ_INSERT_TAIL((struct trace_q *)q, tcb, links); return tcb; } @@ -334,9 +340,14 @@ _sysio_register_trace(void *q, void _sysio_remove_trace(void *q, void *p) { + struct trace_callback *tcb; - TAILQ_REMOVE((struct trace_q *)q, (struct trace_callback *)p, links); - free(p); + tcb = (struct trace_callback *)p; + + if (tcb->destructor) + (*tcb->destructor)(tcb->data); + TAILQ_REMOVE((struct trace_q *)q, tcb, links); + free(tcb); } void @@ -352,7 +363,7 @@ _sysio_run_trace_q(void *q, tcb = ((struct trace_q *)q)->tqh_first; while (tcb) { - (*tcb->f)(file, func, line); + (*tcb->f)(file, func, line, tcb->data); tcb = tcb->links.tqe_next; } } @@ -360,7 +371,8 @@ _sysio_run_trace_q(void *q, static void _sysio_trace_entry(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+ENTER+ %s\n", func); @@ -369,7 +381,8 @@ _sysio_trace_entry(const char *file __IS static void _sysio_trace_exit(const char *file __IS_UNUSED, const char *func, - int line __IS_UNUSED) + int line __IS_UNUSED, + void *data __IS_UNUSED) { _sysio_cprintf("+EXIT+ %s\n", func); @@ -917,13 +930,17 @@ _sysio_boot_tracing(const char *arg) if (entcb == NULL) entcb = _sysio_register_trace(_sysio_entry_trace_q, - _sysio_trace_entry); + _sysio_trace_entry, + NULL, + NULL); if (entcb == NULL) return -errno; if (exitcb == NULL) exitcb = _sysio_register_trace(_sysio_exit_trace_q, - _sysio_trace_exit); + _sysio_trace_exit, + NULL, + NULL); if (exitcb == NULL) return -errno; } else { |
From: Lee W. <lw...@us...> - 2006-02-27 17:26:58
|
Update of /cvsroot/libsysio/libsysio/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21374/include Modified Files: sysio-cmn.h Log Message: Tracing now can reference user-supplied data. The callbacks are supplied the data pointer originally given at registration. A destructor, given at registration, is called with a copy of the user-supplied data pointer when the the trace remove function is invoked if it wasn't NULL. Index: sysio-cmn.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/include/sysio-cmn.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -w -b -B -p -r1.9 -r1.10 --- sysio-cmn.h 5 Jan 2006 15:27:31 -0000 1.9 +++ sysio-cmn.h 27 Feb 2006 17:26:55 -0000 1.10 @@ -160,7 +160,10 @@ extern void *_sysio_exit_trace_q; extern void *_sysio_register_trace(void *q, void (*)(const char *file, const char *func, - int line)); + int line, + void *data), + void *data, + void (*destructor)(void *data)); extern void _sysio_remove_trace(void *q, void *p); extern void _sysio_run_trace_q(void *q, const char *file, |
From: Lee W. <lw...@us...> - 2006-02-27 16:46:45
|
Update of /cvsroot/libsysio/libsysio In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30279 Modified Files: configure.in Log Message: New version. Tracking release to Cray and ClusterFS. Index: configure.in =================================================================== RCS file: /cvsroot/libsysio/libsysio/configure.in,v retrieving revision 1.22 retrieving revision 1.23 diff -u -w -b -B -p -r1.22 -r1.23 --- configure.in 31 Oct 2005 18:50:58 -0000 1.22 +++ configure.in 27 Feb 2006 16:46:41 -0000 1.23 @@ -1,4 +1,4 @@ -AC_INIT(libsysio, 1.1) +AC_INIT(libsysio, 1.2) AC_CANONICAL_HOST |
From: Lee W. <lw...@us...> - 2006-02-08 17:17:51
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3483/tests Modified Files: startup.c Log Message: The startup code in the tests directory should process the namespace initialization variable before the initial working directory. Fixed. From ClusterFS bugzilla #10114; When compiled to support an initial working directory that is deferred until needed, a chdir to a non-existent directory would cause an abort. This behavior is per design. Not technically a bug. However, it's very unfriendly. Especially so, since the accepted thing to do in this situation is to just leave the current working directory at the root of the namespace. This change, then, alters the behavior to the commonly accepted. Index: startup.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/startup.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -w -b -B -p -r1.11 -r1.12 --- startup.c 3 Feb 2005 20:05:13 -0000 1.11 +++ startup.c 8 Feb 2006 17:17:43 -0000 1.12 @@ -22,22 +22,14 @@ _test_sysio_startup() if (err) return err; #if SYSIO_TRACING + /* + * tracing + */ arg = getenv("SYSIO_TRACING"); err = _sysio_boot("trace", arg); if (err) return err; #endif -#if DEFER_INIT_CWD - arg = getenv("SYSIO_CWD"); - if (!arg) - arg = "/"; - err = _sysio_boot("cwd", arg); - if (err) - return err; -#endif - /* - * tracing - */ /* * namespace */ @@ -51,6 +43,17 @@ _test_sysio_startup() err = _sysio_boot("namespace", arg); if (err) return err; +#if DEFER_INIT_CWD + /* + * Current working directory. + */ + arg = getenv("SYSIO_CWD"); + if (!arg) + arg = "/"; + err = _sysio_boot("cwd", arg); + if (err) + return err; +#endif return 0; } |