This patch from Lars Kellogg-Stedman, fixes the behavior of
chown to be consistant with GNU chown, so that it follows symlinks (who cares about the perms on a link anyways?) unless the -h option is supplied. -Erik
This commit is contained in:
parent
eb5f433736
commit
2b02ab9606
14
chown.c
14
chown.c
@ -36,9 +36,11 @@
|
|||||||
static long uid;
|
static long uid;
|
||||||
static long gid;
|
static long gid;
|
||||||
|
|
||||||
|
static int (*chown_func)() = chown;
|
||||||
|
|
||||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||||
{
|
{
|
||||||
if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
perror(fileName);
|
perror(fileName);
|
||||||
@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
|||||||
int chown_main(int argc, char **argv)
|
int chown_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
int recursiveFlag = FALSE;
|
int recursiveFlag = FALSE,
|
||||||
|
noderefFlag = FALSE;
|
||||||
char *groupName=NULL;
|
char *groupName=NULL;
|
||||||
char *p=NULL;
|
char *p=NULL;
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "R")) > 0) {
|
while ((opt = getopt(argc, argv, "Rh")) > 0) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'R':
|
case 'R':
|
||||||
recursiveFlag = TRUE;
|
recursiveFlag = TRUE;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
noderefFlag = TRUE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (noderefFlag) chown_func = lchown;
|
||||||
|
|
||||||
if (argc > optind && argc > 2 && argv[optind]) {
|
if (argc > optind && argc > 2 && argv[optind]) {
|
||||||
/* First, check if there is a group name here */
|
/* First, check if there is a group name here */
|
||||||
groupName = strchr(argv[optind], '.');
|
groupName = strchr(argv[optind], '.');
|
||||||
|
@ -36,9 +36,11 @@
|
|||||||
static long uid;
|
static long uid;
|
||||||
static long gid;
|
static long gid;
|
||||||
|
|
||||||
|
static int (*chown_func)() = chown;
|
||||||
|
|
||||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||||
{
|
{
|
||||||
if (lchown(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
}
|
}
|
||||||
perror(fileName);
|
perror(fileName);
|
||||||
@ -48,21 +50,27 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
|||||||
int chown_main(int argc, char **argv)
|
int chown_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
int recursiveFlag = FALSE;
|
int recursiveFlag = FALSE,
|
||||||
|
noderefFlag = FALSE;
|
||||||
char *groupName=NULL;
|
char *groupName=NULL;
|
||||||
char *p=NULL;
|
char *p=NULL;
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "R")) > 0) {
|
while ((opt = getopt(argc, argv, "Rh")) > 0) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'R':
|
case 'R':
|
||||||
recursiveFlag = TRUE;
|
recursiveFlag = TRUE;
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
noderefFlag = TRUE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (noderefFlag) chown_func = lchown;
|
||||||
|
|
||||||
if (argc > optind && argc > 2 && argv[optind]) {
|
if (argc > optind && argc > 2 && argv[optind]) {
|
||||||
/* First, check if there is a group name here */
|
/* First, check if there is a group name here */
|
||||||
groupName = strchr(argv[optind], '.');
|
groupName = strchr(argv[optind], '.');
|
||||||
|
Loading…
Reference in New Issue
Block a user