version 1.28, 2014/07/05 06:45:00 |
version 1.29, 2014/07/05 06:53:36 |
|
|
int oumask; /* Old umask */ |
int oumask; /* Old umask */ |
|
|
static int cattarget(char *); |
static int cattarget(char *); |
static int setownership(char *, int, UID_T, GID_T, int); |
static int setownership(char *, int, uid_t, gid_t, int); |
static int setfilemode(char *, int, int, int); |
static int setfilemode(char *, int, int, int); |
static int fchog(int, char *, char *, char *, int); |
static int fchog(int, char *, char *, char *, int); |
static int removefile(struct stat *, int); |
static int removefile(struct stat *, int); |
|
|
* Set uid and gid ownership of a file. |
* Set uid and gid ownership of a file. |
*/ |
*/ |
static int |
static int |
setownership(char *file, int fd, UID_T uid, GID_T gid, int link) |
setownership(char *file, int fd, uid_t uid, gid_t gid, int link) |
{ |
{ |
int status = -1; |
int status = -1; |
|
|
|
|
*/ |
*/ |
#if defined(HAVE_LCHOWN) |
#if defined(HAVE_LCHOWN) |
if (link) |
if (link) |
status = lchown(file, (CHOWN_UID_T) uid, |
status = lchown(file, uid, gid); |
(CHOWN_GID_T) gid); |
|
#else |
#else |
if (link) |
if (link) |
return 0; |
return 0; |
|
|
|
|
#if defined(HAVE_FCHOWN) |
#if defined(HAVE_FCHOWN) |
if (fd != -1 && !link) |
if (fd != -1 && !link) |
status = fchown(fd, (CHOWN_UID_T) uid, |
status = fchown(fd, uid, gid); |
(CHOWN_GID_T) gid); |
|
#endif |
#endif |
if (status < 0 && !link) |
if (status < 0 && !link) |
status = chown(file, (CHOWN_UID_T) uid, |
status = chown(file, uid, gid); |
(CHOWN_GID_T) gid); |
|
|
|
if (status < 0) { |
if (status < 0) { |
if (uid == (UID_T) -1) |
if (uid == (uid_t)-1) |
message(MT_NOTICE, "%s: chgrp %d failed: %s", |
message(MT_NOTICE, "%s: chgrp %d failed: %s", |
target, gid, SYSERR); |
target, gid, SYSERR); |
else |
else |
|
|
extern char *locuser; |
extern char *locuser; |
int i; |
int i; |
struct stat st; |
struct stat st; |
UID_T uid; |
uid_t uid; |
GID_T gid; |
gid_t gid; |
GID_T primegid = (GID_T)-2; |
gid_t primegid = (gid_t)-2; |
|
|
uid = userid; |
uid = userid; |
if (userid == 0) { /* running as root; take anything */ |
if (userid == 0) { /* running as root; take anything */ |
if (*owner == ':') { |
if (*owner == ':') { |
uid = (UID_T) atoi(owner + 1); |
uid = (uid_t) atoi(owner + 1); |
} else if (pw == NULL || strcmp(owner, pw->pw_name) != 0) { |
} else if (pw == NULL || strcmp(owner, pw->pw_name) != 0) { |
if ((pw = getpwnam(owner)) == NULL) { |
if ((pw = getpwnam(owner)) == NULL) { |
if (mode != -1 && IS_ON(mode, S_ISUID)) { |
if (mode != -1 && IS_ON(mode, S_ISUID)) { |
|
|
primegid = pw->pw_gid; |
primegid = pw->pw_gid; |
} |
} |
if (*group == ':') { |
if (*group == ':') { |
gid = (GID_T) atoi(group + 1); |
gid = (gid_t)atoi(group + 1); |
goto ok; |
goto ok; |
} |
} |
} else { /* not root, setuid only if user==owner */ |
} else { /* not root, setuid only if user==owner */ |
|
|
primegid = lupw->pw_gid; |
primegid = lupw->pw_gid; |
} |
} |
|
|
gid = (GID_T) -1; |
gid = (gid_t)-1; |
if (gr == NULL || strcmp(group, gr->gr_name) != 0) { |
if (gr == NULL || strcmp(group, gr->gr_name) != 0) { |
if ((*group == ':' && |
if ((*group == ':' && |
(getgrgid(gid = atoi(group + 1)) == NULL)) |
(getgrgid(gid = atoi(group + 1)) == NULL)) |
|
|
target, locuser, group); |
target, locuser, group); |
mode &= ~S_ISGID; |
mode &= ~S_ISGID; |
} |
} |
gid = (GID_T) -1; |
gid = (gid_t)-1; |
} |
} |
ok: |
ok: |
if (stat(file, &st) == -1) { |
if (stat(file, &st) == -1) { |
|
|
len = ptarget - target; |
len = ptarget - target; |
while ((dp = readdir(d)) != NULL) { |
while ((dp = readdir(d)) != NULL) { |
if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || |
if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || |
dp->d_name[1] == '.' && dp->d_name[2] == '\0')) |
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) |
continue; |
continue; |
|
|
if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) { |
if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) { |
|
|
len = ptarget - target; |
len = ptarget - target; |
while ((dp = readdir(d)) != NULL) { |
while ((dp = readdir(d)) != NULL) { |
if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || |
if (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || |
dp->d_name[1] == '.' && dp->d_name[2] == '\0')) |
(dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) |
continue; |
continue; |
|
|
if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) { |
if (len + 1 + (int)strlen(dp->d_name) >= MAXPATHLEN - 1) { |