-/* $OpenBSD: common.c,v 1.38 2018/09/09 13:53:11 millert Exp $ */
+/* $OpenBSD: common.c,v 1.39 2018/09/21 19:00:45 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
char host[HOST_NAME_MAX+1]; /* Name of this host */
uid_t userid = (uid_t)-1; /* User's UID */
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 *locuser = NULL; /* Local User's name */
int isserver = FALSE; /* We're the server */
homedir = xstrdup(pw->pw_dir);
locuser = xstrdup(pw->pw_name);
groupid = pw->pw_gid;
+ gidsetlen = getgroups(NGROUPS_MAX, gidset);
gethostname(host, sizeof(host));
#if 0
if ((cp = strchr(host, '.')) != NULL)
{
static char buf[100];
static uid_t lastuid = (uid_t)-1;
- struct passwd *pwd = NULL;
+ const char *name;
/*
* 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] != ':')
return(buf);
lastuid = uid;
- if ((pwd = getpwuid(uid)) == NULL) {
+ if ((name = user_from_uid(uid, 1)) == NULL) {
if (IS_ON(opts, DO_DEFOWNER) && !isserver)
(void) strlcpy(buf, defowner, sizeof(buf));
else {
(void) snprintf(buf, sizeof(buf), ":%u", uid);
}
} else {
- (void) strlcpy(buf, pwd->pw_name, sizeof(buf));
+ (void) strlcpy(buf, name, sizeof(buf));
}
return(buf);
{
static char buf[100];
static gid_t lastgid = (gid_t)-1;
- struct group *grp = NULL;
+ const char *name;
/*
* 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] != ':')
return(buf);
lastgid = gid;
- if ((grp = (struct group *)getgrgid(gid)) == NULL) {
+ if ((name = group_from_gid(gid, 1)) == NULL) {
if (IS_ON(opts, DO_DEFGROUP) && !isserver)
(void) strlcpy(buf, defgroup, sizeof(buf));
else {
(void) snprintf(buf, sizeof(buf), ":%u", gid);
}
} else
- (void) strlcpy(buf, grp->gr_name, sizeof(buf));
+ (void) strlcpy(buf, name, sizeof(buf));
return(buf);
}
{
struct passwd *pw;
char *pw_dir, *rest;
+ static char lastuser[_PW_NAME_LEN + 1];
+ static char lastdir[PATH_MAX];
size_t len;
if (*file != '~') {
else
rest = NULL;
if (strcmp(locuser, file) != 0) {
- if ((pw = getpwnam(file)) == NULL) {
- error("%s: unknown user name", file);
- if (rest != NULL)
- *rest = '/';
- return(NULL);
+ if (strcmp(lastuser, file) != 0) {
+ if ((pw = getpwnam(file)) == NULL) {
+ error("%s: unknown user name", file);
+ if (rest != 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)
*rest = '/';
-/* $OpenBSD: expand.c,v 1.16 2018/09/09 13:53:11 millert Exp $ */
+/* $OpenBSD: expand.c,v 1.17 2018/09/21 19:00:45 millert Exp $ */
/*
* Copyright (c) 1983 Regents of the University of California.
char *lastpathp;
char *tilde; /* "~user" if not expanding tilde, else "" */
char *tpathp;
+char pathbuf[BUFSIZ];
int expany; /* any expansions done? */
char *entp;
{
struct namelist *nl, *prev;
int n;
- char pathbuf[BUFSIZ];
if (debug)
debugmsg(DM_CALL, "expand(%p, %d) start, list = %s",
return;
}
if (*s == '~') {
- struct passwd *pw;
-
- cp = ++s;
- if (*cp == CNULL || *cp == '/') {
+ if ((cp = strchr(s, '/')) == NULL) {
tilde = "~";
- cp1 = (u_char *)homedir;
+ s++;
} else {
- tilde = (char *)(cp1 = ebuf);
- *cp1++ = '~';
- do
- *cp1++ = *cp++;
- while (*cp && *cp != '/');
- *cp1 = CNULL;
- if (strcmp(locuser, (char *)ebuf+1) != 0) {
- if ((pw = getpwnam((char *)ebuf+1)) == NULL) {
- strlcat((char *)ebuf,
- ": unknown user name",
- sizeof(ebuf));
- yyerror((char *)ebuf+1);
- return;
- }
- cp1 = (u_char *)pw->pw_dir;
- } else {
- cp1 = (u_char *)homedir;
- }
+ tilde = memcpy(ebuf, s, (cp - s));
+ ebuf[cp - s] = '\0';
s = cp;
}
- for (cp = (u_char *)path; (*cp++ = *cp1++) != '\0'; )
- continue;
- tpathp = pathp = (char *)cp - 1;
+ cp = exptilde(path, tilde, sizeof(pathbuf));
+ tpathp = pathp = (char *)cp;
} else {
tpathp = pathp = path;
tilde = "";