Skip to content
Permalink
Browse files Browse the repository at this point in the history
Added optimization to Makefile (can be set/overruled using OPT).
Added flag to display all warnings during compiling.
Added status checks when parsing user/group IDs for Linux.
Make sure Linux drops original user's groups when running as another user.
  • Loading branch information
Jesse Smith committed Sep 3, 2019
1 parent 79c6c61 commit 2f83222
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -5,9 +5,10 @@ PREFIX?=/usr/local
MANDIR?=$(DESTDIR)$(PREFIX)/man
SYSCONFDIR?=$(DESTDIR)$(PREFIX)/etc
OBJECTS=doas.o env.o execvpe.o reallocarray.o y.tab.o
OPT?=-O2
# Can set GLOBAL_PATH here to set PATH for target user.
# TARGETPATH=-DGLOBAL_PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:\"
CFLAGS+=-DUSE_PAM -DDOAS_CONF=\"${SYSCONFDIR}/doas.conf\" $(TARGETPATH)
CFLAGS+=-Wall $(OPT) -DUSE_PAM -DDOAS_CONF=\"${SYSCONFDIR}/doas.conf\" $(TARGETPATH)
LDFLAGS+=-lpam
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
Expand Down
28 changes: 20 additions & 8 deletions doas.c
Expand Up @@ -85,19 +85,25 @@ static int
parseuid(const char *s, uid_t *uid)
{
struct passwd *pw;
const char *errstr;
#if !defined(__linux__) && !defined(__NetBSD__)
const char *errstr = NULL;
#else
int status;
#endif

if ((pw = getpwnam(s)) != NULL) {
*uid = pw->pw_uid;
return 0;
}
#if !defined(__linux__) && !defined(__NetBSD__)
*uid = strtonum(s, 0, UID_MAX, &errstr);
#else
sscanf(s, "%d", uid);
#endif
if (errstr)
return -1;
#else
status = sscanf(s, "%d", uid);
if (status != 1)
return -1;
#endif
return 0;
}

Expand All @@ -117,19 +123,25 @@ static int
parsegid(const char *s, gid_t *gid)
{
struct group *gr;
const char *errstr;
#if !defined(__linux__) && !defined(__NetBSD__)
const char *errstr = NULL;
#else
int status;
#endif

if ((gr = getgrnam(s)) != NULL) {
*gid = gr->gr_gid;
return 0;
}
#if !defined(__linux__) && !defined(__NetBSD__)
*gid = strtonum(s, 0, GID_MAX, &errstr);
#else
sscanf(s, "%d", gid);
#endif
if (errstr)
return -1;
#else
status = sscanf(s, "%d", gid);
if (status != 1)
return -1;
#endif
return 0;
}

Expand Down

0 comments on commit 2f83222

Please sign in to comment.