version 1.38, 2018/09/09 13:53:11 |
version 1.39, 2018/09/21 19:00:45 |
|
|
char host[HOST_NAME_MAX+1]; /* Name of this host */ |
char host[HOST_NAME_MAX+1]; /* Name of this host */ |
uid_t userid = (uid_t)-1; /* User's UID */ |
uid_t userid = (uid_t)-1; /* User's UID */ |
gid_t groupid = (gid_t)-1; /* User's GID */ |
gid_t groupid = (gid_t)-1; /* User's GID */ |
|
gid_t gidset[NGROUPS_MAX]; /* User's GID list */ |
|
int gidsetlen = 0; /* Number of GIDS in list */ |
char *homedir = NULL; /* User's $HOME */ |
char *homedir = NULL; /* User's $HOME */ |
char *locuser = NULL; /* Local User's name */ |
char *locuser = NULL; /* Local User's name */ |
int isserver = FALSE; /* We're the server */ |
int isserver = FALSE; /* We're the server */ |
|
|
homedir = xstrdup(pw->pw_dir); |
homedir = xstrdup(pw->pw_dir); |
locuser = xstrdup(pw->pw_name); |
locuser = xstrdup(pw->pw_name); |
groupid = pw->pw_gid; |
groupid = pw->pw_gid; |
|
gidsetlen = getgroups(NGROUPS_MAX, gidset); |
gethostname(host, sizeof(host)); |
gethostname(host, sizeof(host)); |
#if 0 |
#if 0 |
if ((cp = strchr(host, '.')) != NULL) |
if ((cp = strchr(host, '.')) != NULL) |
|
|
{ |
{ |
static char buf[100]; |
static char buf[100]; |
static uid_t lastuid = (uid_t)-1; |
static uid_t lastuid = (uid_t)-1; |
struct passwd *pwd = NULL; |
const char *name; |
|
|
/* |
/* |
* The value of opts may have changed so we always |
* The value of opts may have changed so we always |
|
|
} |
} |
|
|
/* |
/* |
* Try to avoid getpwuid() call. |
* Try to avoid passwd lookup. |
*/ |
*/ |
if (lastuid == uid && buf[0] != '\0' && buf[0] != ':') |
if (lastuid == uid && buf[0] != '\0' && buf[0] != ':') |
return(buf); |
return(buf); |
|
|
lastuid = uid; |
lastuid = uid; |
|
|
if ((pwd = getpwuid(uid)) == NULL) { |
if ((name = user_from_uid(uid, 1)) == NULL) { |
if (IS_ON(opts, DO_DEFOWNER) && !isserver) |
if (IS_ON(opts, DO_DEFOWNER) && !isserver) |
(void) strlcpy(buf, defowner, sizeof(buf)); |
(void) strlcpy(buf, defowner, sizeof(buf)); |
else { |
else { |
|
|
(void) snprintf(buf, sizeof(buf), ":%u", uid); |
(void) snprintf(buf, sizeof(buf), ":%u", uid); |
} |
} |
} else { |
} else { |
(void) strlcpy(buf, pwd->pw_name, sizeof(buf)); |
(void) strlcpy(buf, name, sizeof(buf)); |
} |
} |
|
|
return(buf); |
return(buf); |
|
|
{ |
{ |
static char buf[100]; |
static char buf[100]; |
static gid_t lastgid = (gid_t)-1; |
static gid_t lastgid = (gid_t)-1; |
struct group *grp = NULL; |
const char *name; |
|
|
/* |
/* |
* The value of opts may have changed so we always |
* The value of opts may have changed so we always |
|
|
} |
} |
|
|
/* |
/* |
* Try to avoid getgrgid() call. |
* Try to avoid group lookup. |
*/ |
*/ |
if (lastgid == gid && buf[0] != '\0' && buf[0] != ':') |
if (lastgid == gid && buf[0] != '\0' && buf[0] != ':') |
return(buf); |
return(buf); |
|
|
lastgid = gid; |
lastgid = gid; |
|
|
if ((grp = (struct group *)getgrgid(gid)) == NULL) { |
if ((name = group_from_gid(gid, 1)) == NULL) { |
if (IS_ON(opts, DO_DEFGROUP) && !isserver) |
if (IS_ON(opts, DO_DEFGROUP) && !isserver) |
(void) strlcpy(buf, defgroup, sizeof(buf)); |
(void) strlcpy(buf, defgroup, sizeof(buf)); |
else { |
else { |
|
|
(void) snprintf(buf, sizeof(buf), ":%u", gid); |
(void) snprintf(buf, sizeof(buf), ":%u", gid); |
} |
} |
} else |
} else |
(void) strlcpy(buf, grp->gr_name, sizeof(buf)); |
(void) strlcpy(buf, name, sizeof(buf)); |
|
|
return(buf); |
return(buf); |
} |
} |
|
|
{ |
{ |
struct passwd *pw; |
struct passwd *pw; |
char *pw_dir, *rest; |
char *pw_dir, *rest; |
|
static char lastuser[_PW_NAME_LEN + 1]; |
|
static char lastdir[PATH_MAX]; |
size_t len; |
size_t len; |
|
|
if (*file != '~') { |
if (*file != '~') { |
|
|
else |
else |
rest = NULL; |
rest = NULL; |
if (strcmp(locuser, file) != 0) { |
if (strcmp(locuser, file) != 0) { |
if ((pw = getpwnam(file)) == NULL) { |
if (strcmp(lastuser, file) != 0) { |
error("%s: unknown user name", file); |
if ((pw = getpwnam(file)) == NULL) { |
if (rest != NULL) |
error("%s: unknown user name", file); |
*rest = '/'; |
if (rest != NULL) |
return(NULL); |
*rest = '/'; |
|
return(NULL); |
|
} |
|
strlcpy(lastuser, pw->pw_name, sizeof(lastuser)); |
|
strlcpy(lastdir, pw->pw_dir, sizeof(lastdir)); |
} |
} |
pw_dir = pw->pw_dir; |
pw_dir = lastdir; |
} |
} |
if (rest != NULL) |
if (rest != NULL) |
*rest = '/'; |
*rest = '/'; |