From 79e1686a12e7ed0a3a2ae7372e4a3320ebd5f901 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Mon, 13 Dec 1999 12:35:16 +0000 Subject: zsh-workers/9013 --- Doc/Zsh/mod_files.yo | 7 ++++++- Src/Modules/files.c | 11 +++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Doc/Zsh/mod_files.yo b/Doc/Zsh/mod_files.yo index 356696faa..d5c87b6d1 100644 --- a/Doc/Zsh/mod_files.yo +++ b/Doc/Zsh/mod_files.yo @@ -17,12 +17,17 @@ The var(user-spec) can be in four forms: startsitem() sitem(var(user))(change owner to var(user); do not change group) +sitem(var(user)tt(::))(change owner to var(user); do not change group) sitem(var(user)tt(:))(change owner to var(user); change group to var(user)'s primary group) sitem(var(user)tt(:)var(group))(change owner to var(user); change group to var(group)) sitem(tt(:)var(group))(do not change owner; change group to var(group)) endsitem() -In each case, the `tt(:)' may instead be a `tt(.)'. +In each case, the `tt(:)' may instead be a `tt(.)'. The rule is that +if there is a `tt(:)' then the separator is `tt(:)', otherwise +if there is a `tt(.)' then the separator is `tt(.)', otherwise +there is no separator. + Each of var(user) and var(group) may be either a username (or group name, as appropriate) or a decimal user ID (group ID). Interpretation as a name takes precedence, if there is an all-numeric username (or group name). diff --git a/Src/Modules/files.c b/Src/Modules/files.c index 844ca7d25..ac3bedd04 100644 --- a/Src/Modules/files.c +++ b/Src/Modules/files.c @@ -628,21 +628,22 @@ bin_chown(char *nam, char **args, char *ops, int func) { struct chownmagic chm; char *uspec = ztrdup(*args), *p = uspec; + char *end; chm.nam = nam; if(func == BIN_CHGRP) { chm.uid = -1; goto dogroup; } - if(*p == ':' || *p == '.') { + end = strchr(uspec, ':'); + if(!end) + end = strchr(uspec, '.'); + if(end == uspec) { chm.uid = -1; p++; goto dogroup; } else { struct passwd *pwd; - char *end = strchr(p, ':'); - if(!end) - end = strchr(p, '.'); if(end) *end = 0; pwd = getpwnam(p); @@ -666,6 +667,8 @@ bin_chown(char *nam, char **args, char *ops, int func) return 1; } chm.gid = pwd->pw_gid; + } else if(p[0] == ':' && !p[1]) { + chm.gid = -1; } else { struct group *grp; dogroup: -- cgit 1.4.1