Browse Source

- Added the lchown() and lchgrp() functions which change permissions and group

permissions on symbolic links.
#- We'll also add this to PHP 5.1.3? or PHP 5.2, so I didn't add it to NEWS.
migration/RELEASE_1_0_0
Derick Rethans 20 years ago
parent
commit
223aa7294d
  1. 12
      TSRM/tsrm_virtual_cwd.c
  2. 6
      TSRM/tsrm_virtual_cwd.h
  3. 1
      configure.in
  4. 6
      ext/standard/basic_functions.c
  5. 76
      ext/standard/filestat.c
  6. 9
      ext/standard/php_filestat.h

12
TSRM/tsrm_virtual_cwd.c

@ -777,7 +777,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC)
}
#if !defined(TSRM_WIN32) && !defined(NETWARE)
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC)
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int link TSRMLS_DC)
{
cwd_state new_state;
int ret;
@ -785,7 +785,15 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_
CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, filename, NULL, 0);
ret = chown(new_state.cwd, owner, group);
if (link) {
#if HAVE_LCHOWN
ret = lchown(new_state.cwd, owner, group);
#else
ret = -1;
#endif
} else {
ret = chown(new_state.cwd, owner, group);
}
CWD_STATE_FREE(&new_state);
return ret;

6
TSRM/tsrm_virtual_cwd.h

@ -190,7 +190,7 @@ CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC);
#endif
CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC);
#if !defined(TSRM_WIN32) && !defined(NETWARE)
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC);
CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group, int link TSRMLS_DC);
#endif
CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path, int use_realpath);
@ -262,7 +262,8 @@ extern virtual_cwd_globals cwd_globals;
#endif
#define VCWD_CHMOD(path, mode) virtual_chmod(path, mode TSRMLS_CC)
#if !defined(TSRM_WIN32) && !defined(NETWARE)
#define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group TSRMLS_CC)
#define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group, 0 TSRMLS_CC)
#define VCWD_LCHOWN(path, owner, group) virtual_chown(path, owner, group, 1 TSRMLS_CC)
#endif
#else
@ -305,6 +306,7 @@ extern virtual_cwd_globals cwd_globals;
#define VCWD_CHMOD(path, mode) chmod(path, mode)
#if !defined(TSRM_WIN32) && !defined(NETWARE)
#define VCWD_CHOWN(path, owner, group) chown(path, owner, group)
#define VCWD_LCHOWN(path, owner, group) lchown(path, owner, group)
#endif
#endif

1
configure.in

@ -482,6 +482,7 @@ isascii \
link \
localtime_r \
lockf \
lchown \
lrand48 \
memcpy \
memmove \

6
ext/standard/basic_functions.c

@ -695,6 +695,12 @@ zend_function_entry basic_functions[] = {
#ifndef NETWARE
PHP_FE(chown, NULL)
PHP_FE(chgrp, NULL)
#endif
#if HAVE_LCHOWN
PHP_FE(lchown, NULL)
#endif
#if HAVE_LCHOWN
PHP_FE(lchgrp, NULL)
#endif
PHP_FE(chmod, NULL)
#if HAVE_UTIME

76
ext/standard/filestat.c

@ -323,12 +323,9 @@ PHP_FUNCTION(disk_free_space)
}
/* }}} */
/* {{{ proto bool chgrp(string filename, mixed group)
Change file group */
#ifndef NETWARE
PHP_FUNCTION(chgrp)
static void php_do_chgrp(INTERNAL_FUNCTION_PARAMETERS, int do_lchgrp)
{
#if !defined(WINDOWS)
zval **filename, **group;
gid_t gid;
struct group *gr=NULL;
@ -360,25 +357,48 @@ PHP_FUNCTION(chgrp)
RETURN_FALSE;
}
ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid);
if (do_lchgrp) {
ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), -1, gid);
} else {
ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid);
}
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
RETURN_TRUE;
}
#ifndef NETWARE
/* {{{ proto bool chgrp(string filename, mixed group)
Change file group */
PHP_FUNCTION(chgrp)
{
#if !defined(WINDOWS)
php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
#else
RETURN_FALSE;
#endif
}
/* }}} */
/* {{{ proto bool lchgrp(string filename, mixed group)
Change symlink group */
#if HAVE_LCHOWN
PHP_FUNCTION(lchgrp)
{
# if !defined(WINDOWS)
php_do_chgrp(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
# else
RETURN_FALSE;
# endif
}
#endif
/* }}} */
#endif
/* {{{ proto bool chown (string filename, mixed user)
Change file owner */
#ifndef NETWARE
PHP_FUNCTION(chown)
static void php_do_chown(INTERNAL_FUNCTION_PARAMETERS, int do_lchown)
{
#if !defined(WINDOWS)
zval **filename, **user;
int ret;
uid_t uid;
@ -410,16 +430,46 @@ PHP_FUNCTION(chown)
RETURN_FALSE;
}
ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1);
if (do_lchown) {
ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), uid, -1);
} else {
ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1);
}
if (ret == -1) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
RETURN_FALSE;
}
}
#ifndef NETWARE
/* {{{ proto bool chown (string filename, mixed user)
Change file owner */
PHP_FUNCTION(chown)
{
#if !defined(WINDOWS)
RETVAL_TRUE;
php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
#else
RETURN_FALSE;
#endif
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool chown (string filename, mixed user)
Change file owner */
#if HAVE_LCHOWN
PHP_FUNCTION(lchown)
{
# if !defined(WINDOWS)
RETVAL_TRUE;
php_do_chown(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
# else
RETURN_FALSE;
# endif
}
#endif
/* }}} */
#endif
/* {{{ proto bool chmod(string filename, int mode)
Change file mode */

9
ext/standard/php_filestat.h

@ -47,9 +47,18 @@ PHP_FUNCTION(disk_total_space);
PHP_FUNCTION(disk_free_space);
PHP_FUNCTION(chown);
PHP_FUNCTION(chgrp);
#if HAVE_LCHOWN
PHP_FUNCTION(lchown);
#endif
#if HAVE_LCHOWN
PHP_FUNCTION(lchgrp);
#endif
PHP_FUNCTION(chmod);
#if HAVE_UTIME
PHP_FUNCTION(touch);
# if HAVE_LTOUCH
PHP_FUNCTION(ltouch);
# endif
#endif
PHP_FUNCTION(clearstatcache);

Loading…
Cancel
Save