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.
This commit is contained in:
Jesse Smith 2019-09-03 11:42:27 -03:00
parent 79c6c61a73
commit 2f83222829
2 changed files with 22 additions and 9 deletions

View file

@ -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)

28
doas.c
View file

@ -85,7 +85,11 @@ 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;
@ -93,11 +97,13 @@ parseuid(const char *s, uid_t *uid)
}
#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;
}
@ -117,7 +123,11 @@ 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;
@ -125,11 +135,13 @@ parsegid(const char *s, gid_t *gid)
}
#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;
}