No reaction the first time so this is a repost.

Diffed against the stable 4.2.0 source tree. Adds an optional third bool to
chown and chgrp that makes use of the lchown system call to change the owner
and group of the symlink itself, and not the final target. The default
behavior is unchanged.

D
--- TSRM/tsrm_virtual_cwd.h.orig        Tue Dec 11 16:16:20 2001
+++ TSRM/tsrm_virtual_cwd.h     Wed May  8 01:32:47 2002
@@ -132,6 +132,7 @@
 CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC);
 #ifndef TSRM_WIN32
 CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC);
+CWD_API int virtual_lchown(const char *filename, uid_t owner, gid_t group TSRMLS_DC);
 #endif
 
 CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func 
verify_path);
@@ -181,6 +182,7 @@
 #define VCWD_CHMOD(path, mode) virtual_chmod(path, mode TSRMLS_CC)
 #ifndef TSRM_WIN32
 #define VCWD_CHOWN(path, owner, group) virtual_chown(path, owner, group TSRMLS_CC)
+#define VCWD_LCHOWN(path, owner, group) virtual_lchown(path, owner, group TSRMLS_CC)
 #endif
 
 #else
@@ -214,6 +216,7 @@
 #define VCWD_CHMOD(path, mode) chmod(path, mode)
 #ifndef TSRM_WIN32
 #define VCWD_CHOWN(path, owner, group) chown(path, owner, group)
+#define VCWD_LCHOWN(path, owner, group) lchown(path, owner, group)
 #endif
 
 #endif
--- TSRM/tsrm_virtual_cwd.c.orig        Tue Dec 11 16:16:20 2001
+++ TSRM/tsrm_virtual_cwd.c     Tue May  7 19:09:04 2002
@@ -538,6 +538,20 @@
        CWD_STATE_FREE(&new_state);
        return ret;
 }
+
+CWD_API int virtual_lchown(const char *filename, uid_t owner, gid_t group TSRMLS_DC)
+{
+       cwd_state new_state;
+       int ret;
+
+       CWD_STATE_COPY(&new_state, &CWDG(cwd));
+       virtual_file_ex(&new_state, filename, NULL);
+
+       ret = lchown(new_state.cwd, owner, group);
+
+       CWD_STATE_FREE(&new_state);
+       return ret;
+}
 #endif
 
 CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...)
--- ext/standard/filestat.c.orig        Thu Feb 28 09:26:45 2002
+++ ext/standard/filestat.c     Wed May  8 03:42:11 2002
@@ -331,7 +331,7 @@
 }
 /* }}} */
 
-/* {{{ proto bool chgrp(string filename, mixed group)
+/* {{{ proto bool chgrp(string filename, mixed group [, bool no_dereference])
    Change file group */
 PHP_FUNCTION(chgrp)
 {
@@ -340,10 +340,23 @@
        gid_t gid;
        struct group *gr=NULL;
        int ret;
+       zval **no_dereference = NULL;
 
-       if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, 
&group)==FAILURE) {
+       switch (ZEND_NUM_ARGS()) {
+           case 2:
+               if (zend_get_parameters_ex(2, &filename, &group) == FAILURE)
+                   WRONG_PARAM_COUNT;
+               break;
+
+           case 3:
+               if (zend_get_parameters_ex(3, &filename, &group, &no_dereference) == 
+FAILURE)
+                   WRONG_PARAM_COUNT;
+               break;
+
+           default:
                WRONG_PARAM_COUNT;
        }
+
        convert_to_string_ex(filename);
        if (Z_TYPE_PP(group) == IS_STRING) {
                gr = getgrnam(Z_STRVAL_PP(group));
@@ -367,7 +380,12 @@
                RETURN_FALSE;
        }
 
-       ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid);
+       if (no_dereference && Z_BVAL_PP(no_dereference)) {
+           ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), -1, gid);
+       } else {
+           ret = VCWD_CHOWN(Z_STRVAL_PP(filename), -1, gid);
+       }
+
        if (ret == -1) {
                php_error(E_WARNING, "chgrp failed: %s", strerror(errno));
                RETURN_FALSE;
@@ -379,7 +397,7 @@
 }
 /* }}} */
 
-/* {{{ proto bool chown (string filename, mixed user)
+/* {{{ proto bool chown (string filename, mixed user [, bool no_dereference])
    Change file owner */
 PHP_FUNCTION(chown)
 {
@@ -388,10 +406,23 @@
        int ret;
        uid_t uid;
        struct passwd *pw = NULL;
+       zval **no_dereference = NULL;
 
-       if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &filename, 
&user)==FAILURE) {
+       switch (ZEND_NUM_ARGS()) {
+           case 2:
+               if (zend_get_parameters_ex(2, &filename, &user) == FAILURE)
+                   WRONG_PARAM_COUNT;
+               break;
+
+           case 3:
+               if (zend_get_parameters_ex(3, &filename, &user, &no_dereference) == 
+FAILURE)
+                   WRONG_PARAM_COUNT;
+               break;
+
+           default:
                WRONG_PARAM_COUNT;
        }
+       
        convert_to_string_ex(filename);
        if (Z_TYPE_PP(user) == IS_STRING) {
                pw = getpwnam(Z_STRVAL_PP(user));
@@ -415,7 +446,12 @@
                RETURN_FALSE;
        }
 
-       ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1);
+       if (no_dereference && Z_BVAL_PP(no_dereference)) {
+           ret = VCWD_LCHOWN(Z_STRVAL_PP(filename), uid, -1);
+       } else {
+           ret = VCWD_CHOWN(Z_STRVAL_PP(filename), uid, -1);
+       }
+
        if (ret == -1) {
                php_error(E_WARNING, "chown failed: %s", strerror(errno));
                RETURN_FALSE;

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to